From 8c0901eb45e1e118fec0d6e3326b8a9249306da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Tue, 28 Apr 2020 18:09:33 +0200 Subject: [PATCH 1/6] lib: add makeOverridableWithName --- lib/customisation.nix | 25 ++++++++++++++++++++++--- lib/default.nix | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index dc5dd76919765..bee7b2de0aff3 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -55,16 +55,33 @@ rec { nix-repl> y = lib.makeOverridable x { a = 1; b = 2; } nix-repl> y - { override = «lambda»; overrideDerivation = «lambda»; result = 3; } + { override = { ... }; overrideDerivation = «lambda»; result = 3; } nix-repl> y.override { a = 10; } - { override = «lambda»; overrideDerivation = «lambda»; result = 12; } + { override = { ... }; overrideDerivation = «lambda»; result = 12; } Please refer to "Nixpkgs Contributors Guide" section ".overrideDerivation" to learn about `overrideDerivation` and caveats related to its use. */ - makeOverridable = f: origArgs: + makeOverridable = makeOverridableWithName null; + + + /* `makeOverridableWithName` takes a function from attribute set to attribute + set and injects a `override` attribute and a optional `name` attribute + which can be used to override arguments of the function. + + nix-repl> x = {a, b}: { result = a + b; } + + nix-repl> y = lib.makeOverridableWithName "update" x { a = 1; b = 2; } + + nix-repl> y + { override = { ... }; overrideDerivation = «lambda»; result = 3; update = «repeated»; } + + nix-repl> y.update { a = 10; } + { override = { ... }; overrideDerivation = «lambda»; result = 12; } + */ + makeOverridableWithName = name: f: origArgs: let result = f origArgs; @@ -81,6 +98,7 @@ rec { if builtins.isAttrs result then result // { override = overrideArgs; + ${name} = overrideArgs; overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv); ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv: overrideResult (x: x.overrideAttrs fdrv); @@ -89,6 +107,7 @@ rec { # Transform the result into a functor while propagating its arguments lib.setFunctionArgs result (lib.functionArgs result) // { override = overrideArgs; + ${name} = overrideArgs; } else result; diff --git a/lib/default.nix b/lib/default.nix index d00c4abec0a96..908dcbba29a39 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -101,7 +101,7 @@ let noDepEntry fullDepEntry packEntry stringAfter; inherit (customisation) overrideDerivation makeOverridable callPackageWith callPackagesWith extendDerivation hydraJob - makeScope; + makeScope makeOverridableWithName; inherit (meta) addMetaAttrs dontDistribute setName updateName appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio hiPrioSet; From 4409499baddb5fb444a034179cb8f9ac52fce082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Tue, 28 Apr 2020 18:12:43 +0200 Subject: [PATCH 2/6] buildPythonPackage: use makeOverridableWithName --- pkgs/top-level/python-packages.nix | 34 +++++++++--------------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index e54a4e9fe4564..785c7f445f132 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -26,31 +26,17 @@ let bootstrapped-pip = callPackage ../development/python-modules/bootstrapped-pip { }; - # Derivations built with `buildPythonPackage` can already be overriden with `override`, `overrideAttrs`, and `overrideDerivation`. - # This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`. - makeOverridablePythonPackage = f: origArgs: - let - ff = f origArgs; - overrideWith = newArgs: origArgs // (if pkgs.lib.isFunction newArgs then newArgs origArgs else newArgs); - in - if builtins.isAttrs ff then (ff // { - overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs); - }) - else if builtins.isFunction ff then { - overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs); - __functor = self: ff; - } - else ff; - - buildPythonPackage = makeOverridablePythonPackage ( makeOverridable (callPackage ../development/interpreters/python/mk-python-derivation.nix { - inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}" - inherit toPythonModule; # Libraries provide modules - })); + buildPythonPackage = makeOverridableWithName "overridePythonAttrs" + (callPackage ../development/interpreters/python/mk-python-derivation.nix { + inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}" + inherit toPythonModule; # Libraries provide modules + }); - buildPythonApplication = makeOverridablePythonPackage ( makeOverridable (callPackage ../development/interpreters/python/mk-python-derivation.nix { - namePrefix = ""; # Python applications should not have any prefix - toPythonModule = x: x; # Application does not provide modules. - })); + buildPythonApplication = makeOverridableWithName "overridePythonAttrs" + (callPackage ../development/interpreters/python/mk-python-derivation.nix { + namePrefix = ""; # Python applications should not have any prefix + toPythonModule = x: x; # Application does not provide modules. + }); # See build-setupcfg/default.nix for documentation. buildSetupcfg = import ../build-support/build-setupcfg self; From 5657d4d190250678cf95de4a18c9048a6158675d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Tue, 28 Apr 2020 18:10:37 +0200 Subject: [PATCH 3/6] buildRustPackage: allow overrides via overrideRustAttrs --- pkgs/development/compilers/rust/default.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index d08b63dd643f9..feafeeea05d0f 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -31,9 +31,10 @@ inherit cargo; }; - buildRustPackage = callPackage ../../../build-support/rust { - inherit rustc cargo fetchCargoTarball; - }; + buildRustPackage = lib.makeOverridableWithName "overrideRustAttrs" + (callPackage ../../../build-support/rust { + inherit rustc cargo fetchCargoTarball; + }); rustcSrc = callPackage ./rust-src.nix { inherit rustc; From 326d976a00c356e8e53cee258d3e10129cd2a472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Tue, 28 Apr 2020 18:11:28 +0200 Subject: [PATCH 4/6] buildRubyGem: allow overrides via overrideRubyGemAttrs --- pkgs/development/ruby-modules/gem/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/ruby-modules/gem/default.nix b/pkgs/development/ruby-modules/gem/default.nix index 158d5891ec3ac..952e421f3b13a 100644 --- a/pkgs/development/ruby-modules/gem/default.nix +++ b/pkgs/development/ruby-modules/gem/default.nix @@ -22,7 +22,7 @@ , ruby, bundler } @ defs: -lib.makeOverridable ( +lib.makeOverridableWithName "overrideRubyGemAttrs" ( { name ? null , gemName From e13bd49675871943e171dd64bff8faad04092bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Sat, 9 May 2020 14:26:19 +0200 Subject: [PATCH 5/6] buildLuarocksPackage: allow overrides via overrideLuarocksAttrs --- pkgs/top-level/lua-packages.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index 7cf47c26c6fc4..b71157362454e 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -56,10 +56,11 @@ let buildLuaApplication = args: buildLuarocksPackage ({namePrefix="";} // args ); - buildLuarocksPackage = with pkgs.lib; makeOverridable(callPackage ../development/interpreters/lua-5/build-lua-package.nix { - inherit toLuaModule; - inherit lua; - }); + buildLuarocksPackage = lib.makeOverridableWithName "overrideLuarocksAttrs" + (callPackage ../development/interpreters/lua-5/build-lua-package.nix { + inherit toLuaModule; + inherit lua; + }); in with self; { From 829a9c1375ec21e7d9fe1ba4ee7010248167ab77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Sat, 9 May 2020 15:53:32 +0200 Subject: [PATCH 6/6] buildPerlPackage: allow overrides via overridePerlAttrs --- pkgs/top-level/perl-packages.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix index 17d605742154a..e5248dc6a35f6 100644 --- a/pkgs/top-level/perl-packages.nix +++ b/pkgs/top-level/perl-packages.nix @@ -36,9 +36,10 @@ let }; }); - buildPerlPackage = callPackage ../development/perl-modules/generic { - inherit buildPerl; - }; + buildPerlPackage = stdenv.lib.makeOverridableWithName "overridePerlAttrs" + (callPackage ../development/perl-modules/generic { + inherit buildPerl; + }); # Helper functions for packages that use Module::Build to build. buildPerlModule = args: