From a41af6a27b0b56b22b8200bb43e26714aa9e3ab7 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sat, 31 Aug 2019 06:50:22 +0200 Subject: gimp: Fix derivation detection --- pkgs/applications/graphics/gimp/wrapper.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/graphics/gimp/wrapper.nix b/pkgs/applications/graphics/gimp/wrapper.nix index 11c1e9ada93..d58dc375cb9 100644 --- a/pkgs/applications/graphics/gimp/wrapper.nix +++ b/pkgs/applications/graphics/gimp/wrapper.nix @@ -1,7 +1,7 @@ { stdenv, lib, symlinkJoin, gimp, makeWrapper, gimpPlugins, gnome3, plugins ? null}: let -allPlugins = lib.filter (pkg: builtins.isAttrs pkg && pkg.type == "derivation" && !pkg.meta.broken or false) (lib.attrValues gimpPlugins); +allPlugins = lib.filter (pkg: lib.isDerivation pkg && !pkg.meta.broken or false) (lib.attrValues gimpPlugins); selectedPlugins = if plugins == null then allPlugins else plugins; extraArgs = map (x: x.wrapArgs or "") selectedPlugins; versionBranch = stdenv.lib.versions.majorMinor gimp.version; -- cgit 1.4.1 From a75080f58ccdf7f702a1a0259e816be74143df52 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:06:22 +0200 Subject: lib/makeOverridable: Deduplicate override definition And call it overrideArgs in the let binding because that's what it does --- lib/customisation.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index 1f5eb0d11e8..cb02496b81d 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -68,16 +68,19 @@ rec { let ff = f origArgs; overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs); + + # Re-call the function but with different arguments + overrideArgs = newArgs: makeOverridable f (overrideWith newArgs); in if builtins.isAttrs ff then (ff // { - override = newArgs: makeOverridable f (overrideWith newArgs); + override = overrideArgs; overrideDerivation = fdrv: makeOverridable (args: overrideDerivation (f args) fdrv) origArgs; ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv: makeOverridable (args: (f args).overrideAttrs fdrv) origArgs; }) else if lib.isFunction ff then { - override = newArgs: makeOverridable f (overrideWith newArgs); + override = overrideArgs; __functor = self: ff; overrideDerivation = throw "overrideDerivation not yet supported for functors"; } -- cgit 1.4.1 From e140d709c43ab25d993c5c78b4e01aee754b49af Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:12:05 +0200 Subject: lib/makeOverridable: Abstract result overriding --- lib/customisation.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index cb02496b81d..21bab1ab4bc 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -71,13 +71,14 @@ rec { # Re-call the function but with different arguments overrideArgs = newArgs: makeOverridable f (overrideWith newArgs); + # Change the result of the function call by applying g to it + overrideResult = g: makeOverridable (args: g (f args)) origArgs; in if builtins.isAttrs ff then (ff // { override = overrideArgs; - overrideDerivation = fdrv: - makeOverridable (args: overrideDerivation (f args) fdrv) origArgs; + overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv); ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv: - makeOverridable (args: (f args).overrideAttrs fdrv) origArgs; + overrideResult (x: x.overrideAttrs fdrv); }) else if lib.isFunction ff then { override = overrideArgs; -- cgit 1.4.1 From d54bdf5504cfe43937e4cfc1f3e03ad621f74b87 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:13:24 +0200 Subject: lib/makeOverridable: Propagate function arguments to override functions This allows querying the arguments you can .override: nix-repl> lib.functionArgs pkgs.hello.override { fetchurl = false; stdenv = false; } --- lib/customisation.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index 21bab1ab4bc..09d7fbf74b0 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -67,12 +67,14 @@ rec { makeOverridable = f: origArgs: let ff = f origArgs; + # Creates a functor with the same arguments as f + copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f); overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs); # Re-call the function but with different arguments - overrideArgs = newArgs: makeOverridable f (overrideWith newArgs); + overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs)); # Change the result of the function call by applying g to it - overrideResult = g: makeOverridable (args: g (f args)) origArgs; + overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs; in if builtins.isAttrs ff then (ff // { override = overrideArgs; -- cgit 1.4.1 From c638dac226e1b3f86fee155d9a27839e3fb4b7e5 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:14:22 +0200 Subject: lib/makeOverridable: Propagate function args of the callPackage'd function This allows querying function arguments of things like fetchFromGitHub: nix-repl> lib.functionArgs pkgs.fetchFromGitHub { fetchSubmodules = true; githubBase = true; ... } --- lib/customisation.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index 09d7fbf74b0..c4eeee9a045 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -82,11 +82,12 @@ rec { ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv: overrideResult (x: x.overrideAttrs fdrv); }) - else if lib.isFunction ff then { - override = overrideArgs; - __functor = self: ff; - overrideDerivation = throw "overrideDerivation not yet supported for functors"; - } + else if lib.isFunction ff then + # Transform ff into a functor while propagating its arguments + lib.setFunctionArgs ff (lib.functionArgs ff) // { + override = overrideArgs; + overrideDerivation = throw "overrideDerivation not yet supported for functors"; + } else ff; -- cgit 1.4.1 From 23e72eff4197394e9dce69b20f55cff165e4409f Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:15:01 +0200 Subject: lib/makeOverridable: Remove unimplemented overrideDerivation for functions - Apparently nobody ever needed this - We already have enough ways to override things - Using overrideDerivation is discouraged --- lib/customisation.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index c4eeee9a045..cbc0604c2b4 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -86,7 +86,6 @@ rec { # Transform ff into a functor while propagating its arguments lib.setFunctionArgs ff (lib.functionArgs ff) // { override = overrideArgs; - overrideDerivation = throw "overrideDerivation not yet supported for functors"; } else ff; -- cgit 1.4.1 From a4896cb4aab132c0bcc32c5df4440f6d3b7ec5de Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:16:01 +0200 Subject: lib/makeOverridable: Refactor - Rename ff to result because that's what it is - Better indentation - Less parens - Comment what overrideWith does --- lib/customisation.nix | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index cbc0604c2b4..b898e832cf5 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -66,9 +66,11 @@ rec { */ makeOverridable = f: origArgs: let - ff = f origArgs; + result = f origArgs; + # Creates a functor with the same arguments as f copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f); + # Changes the original arguments with (potentially a function that returns) a set of new attributes overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs); # Re-call the function but with different arguments @@ -76,18 +78,19 @@ rec { # Change the result of the function call by applying g to it overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs; in - if builtins.isAttrs ff then (ff // { - override = overrideArgs; - overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv); - ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv: - overrideResult (x: x.overrideAttrs fdrv); - }) - else if lib.isFunction ff then - # Transform ff into a functor while propagating its arguments - lib.setFunctionArgs ff (lib.functionArgs ff) // { + if builtins.isAttrs result then + result // { + override = overrideArgs; + overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv); + ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv: + overrideResult (x: x.overrideAttrs fdrv); + } + else if lib.isFunction result then + # Transform the result into a functor while propagating its arguments + lib.setFunctionArgs result (lib.functionArgs result) // { override = overrideArgs; } - else ff; + else result; /* Call the package function in the file `fn' with the required -- cgit 1.4.1