···221221 isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
222222223223224224+ /* Convert a store path to a fake derivation. */
225225+ toDerivation = path:
226226+ let path' = builtins.storePath path; in
227227+ { type = "derivation";
228228+ name = builtins.unsafeDiscardStringContext (builtins.substring 33 (-1) (baseNameOf path'));
229229+ outPath = path';
230230+ outputs = [ "out" ];
231231+ };
232232+233233+224234 /* If the Boolean `cond' is true, return the attribute set `as',
225235 otherwise an empty attribute set. */
226236 optionalAttrs = cond: as: if cond then as else {};
+5
lib/strings.nix
···218218219219 # Format a number adding leading zeroes up to fixed width.
220220 fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
221221+222222+223223+ # Check whether a value is a store path.
224224+ isStorePath = x: builtins.substring 0 1 (toString x) == "/" && dirOf (builtins.toPath x) == builtins.storeDir;
225225+221226}
+5-3
lib/types.nix
···9494 # derivation is a reserved keyword.
9595 package = mkOptionType {
9696 name = "derivation";
9797- check = isDerivation;
9898- merge = mergeOneOption;
9797+ check = x: isDerivation x || isStorePath x;
9898+ merge = loc: defs:
9999+ let res = mergeOneOption loc defs;
100100+ in if isDerivation res then res else toDerivation res;
99101 };
100102101103 path = mkOptionType {
102104 name = "path";
103105 # Hacky: there is no ‘isPath’ primop.
104104- check = x: builtins.unsafeDiscardStringContext (builtins.substring 0 1 (toString x)) == "/";
106106+ check = x: builtins.substring 0 1 (toString x) == "/";
105107 merge = mergeOneOption;
106108 };
107109
···107107 </varlistentry>
108108109109 <varlistentry>
110110+ <term><varname>types.package</varname></term>
111111+ <listitem>
112112+ <para>A derivation (such as <literal>pkgs.hello</literal>) or a
113113+ store path (such as
114114+ <filename>/nix/store/1ifi1cfbfs5iajmvwgrbmrnrw3a147h9-hello-2.10</filename>).</para>
115115+ </listitem>
116116+ </varlistentry>
117117+118118+ <varlistentry>
110119 <term><varname>types.listOf</varname> <replaceable>t</replaceable></term>
111120 <listitem>
112121 <para>A list of elements of type <replaceable>t</replaceable>
···138147<varname>mkOptionType</varname>. See
139148<filename>lib/types.nix</filename> in Nixpkgs for details.</para>
140149141141-</section>150150+</section>