summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2022-03-11 11:56:44 +0100
committerGitHub <noreply@github.com>2022-03-11 11:56:44 +0100
commita15fbdb88f38800c8e554772a12de8031815802a (patch)
tree3d3ed8c3f71ac476f31fedc6b1aa100c2a9b9149 /lib
parentaff5c571a02d3815d456006c692e76aa2a1c5c24 (diff)
parent9c2266c03171dcf492b6accdb0cde0cb28e156b5 (diff)
downloadnixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.tar
nixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.tar.gz
nixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.tar.bz2
nixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.tar.lz
nixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.tar.xz
nixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.tar.zst
nixpkgs-a15fbdb88f38800c8e554772a12de8031815802a.zip
Merge pull request #163443 from ncfavier/fix-types-package
lib.types.package: only call toDerivation when necessary
Diffstat (limited to 'lib')
-rw-r--r--lib/types.nix12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 2e7261f7553..3078615f5dd 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -368,13 +368,21 @@ rec {
       emptyValue = { value = {}; };
     };
 
-    # derivation is a reserved keyword.
+    # A package is a top-level store path (/nix/store/hash-name). This includes:
+    # - derivations
+    # - more generally, attribute sets with an `outPath` or `__toString` attribute
+    #   pointing to a store path, e.g. flake inputs
+    # - strings with context, e.g. "${pkgs.foo}" or (toString pkgs.foo)
+    # - hardcoded store path literals (/nix/store/hash-foo) or strings without context
+    #   ("/nix/store/hash-foo"). These get a context added to them using builtins.storePath.
     package = mkOptionType {
       name = "package";
       check = x: isDerivation x || isStorePath x;
       merge = loc: defs:
         let res = mergeOneOption loc defs;
-        in if isDerivation res then res else toDerivation res;
+        in if builtins.isPath res || (builtins.isString res && ! builtins.hasContext res)
+          then toDerivation res
+          else res;
     };
 
     shellPackage = package // {