git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #163443 from ncfavier/fix-types-package

lib.types.package: only call toDerivation when necessary

commita15fbdb88f38800c8e554772a12de8031815802a authorRobert Hensing <roberth@users.noreply.github.com> dateFri 11 Mar 2022, 11:56 (5 years ago) parentaff5c579c2266c
3 files changed+15−4
lib/types.nix+10−2 nixos/doc/manual/development/option-types.section.md+2−1 nixos/doc/manual/from_md/development/option-types.section.xml+3−1
lib/types.nix+10−2
@@ -368,13 +368,21 @@ rec {
368368 emptyValue = { value = {}; };
369369 };
370370
371− # derivation is a reserved keyword.
371+ # A package is a top-level store path (/nix/store/hash-name). This includes:
372+ # - derivations
373+ # - more generally, attribute sets with an `outPath` or `__toString` attribute
374+ # pointing to a store path, e.g. flake inputs
375+ # - strings with context, e.g. "${pkgs.foo}" or (toString pkgs.foo)
376+ # - hardcoded store path literals (/nix/store/hash-foo) or strings without context
377+ # ("/nix/store/hash-foo"). These get a context added to them using builtins.storePath.
372378 package = mkOptionType {
373379 name = "package";
374380 check = x: isDerivation x || isStorePath x;
375381 merge = loc: defs:
376382 let res = mergeOneOption loc defs;
377− in if isDerivation res then res else toDerivation res;
383+ in if builtins.isPath res || (builtins.isString res && ! builtins.hasContext res)
384+ then toDerivation res
385+ else res;
378386 };
379387
380388 shellPackage = package // {
nixos/doc/manual/development/option-types.section.md+2−1
@@ -22,7 +22,8 @@ merging is handled.
2222
2323`types.package`
2424
25−: A derivation or a store path.
25+: A top-level store path. This can be an attribute set pointing
26+ to a store path, like a derivation or a flake input.
2627
2728`types.anything`
2829
nixos/doc/manual/from_md/development/option-types.section.xml+3−1
@@ -43,7 +43,9 @@
4343 </term>
4444 <listitem>
4545 <para>
46− A derivation or a store path.
46+ A top-level store path. This can be an attribute set
47+ pointing to a store path, like a derivation or a flake
48+ input.
4749 </para>
4850 </listitem>
4951 </varlistentry>