Allow options with type "package" to be store paths
For example, this allows writing nix.package = /nix/store/786mlvhd17xvcp2r4jmmay6jj4wj6b7f-nix-1.10pre4206_896428c; Also, document types.package in the manual.
This commit is contained in:
parent
fa7a0f24a4
commit
214d4fb73c
@ -221,6 +221,16 @@ rec {
|
|||||||
isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
|
isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a store path to a fake derivation. */
|
||||||
|
toDerivation = path:
|
||||||
|
let path' = builtins.storePath path; in
|
||||||
|
{ type = "derivation";
|
||||||
|
name = builtins.unsafeDiscardStringContext (builtins.substring 33 (-1) (baseNameOf path'));
|
||||||
|
outPath = path';
|
||||||
|
outputs = [ "out" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* If the Boolean `cond' is true, return the attribute set `as',
|
/* If the Boolean `cond' is true, return the attribute set `as',
|
||||||
otherwise an empty attribute set. */
|
otherwise an empty attribute set. */
|
||||||
optionalAttrs = cond: as: if cond then as else {};
|
optionalAttrs = cond: as: if cond then as else {};
|
||||||
|
@ -218,4 +218,9 @@ rec {
|
|||||||
|
|
||||||
# Format a number adding leading zeroes up to fixed width.
|
# Format a number adding leading zeroes up to fixed width.
|
||||||
fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
|
fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
|
||||||
|
|
||||||
|
|
||||||
|
# Check whether a value is a store path.
|
||||||
|
isStorePath = x: builtins.substring 0 1 (toString x) == "/" && dirOf (builtins.toPath x) == builtins.storeDir;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,14 +94,16 @@ rec {
|
|||||||
# derivation is a reserved keyword.
|
# derivation is a reserved keyword.
|
||||||
package = mkOptionType {
|
package = mkOptionType {
|
||||||
name = "derivation";
|
name = "derivation";
|
||||||
check = isDerivation;
|
check = x: isDerivation x || isStorePath x;
|
||||||
merge = mergeOneOption;
|
merge = loc: defs:
|
||||||
|
let res = mergeOneOption loc defs;
|
||||||
|
in if isDerivation res then res else toDerivation res;
|
||||||
};
|
};
|
||||||
|
|
||||||
path = mkOptionType {
|
path = mkOptionType {
|
||||||
name = "path";
|
name = "path";
|
||||||
# Hacky: there is no ‘isPath’ primop.
|
# Hacky: there is no ‘isPath’ primop.
|
||||||
check = x: builtins.unsafeDiscardStringContext (builtins.substring 0 1 (toString x)) == "/";
|
check = x: builtins.substring 0 1 (toString x) == "/";
|
||||||
merge = mergeOneOption;
|
merge = mergeOneOption;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,6 +106,15 @@ options = {
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><varname>types.package</varname></term>
|
||||||
|
<listitem>
|
||||||
|
<para>A derivation (such as <literal>pkgs.hello</literal>) or a
|
||||||
|
store path (such as
|
||||||
|
<filename>/nix/store/1ifi1cfbfs5iajmvwgrbmrnrw3a147h9-hello-2.10</filename>).</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><varname>types.listOf</varname> <replaceable>t</replaceable></term>
|
<term><varname>types.listOf</varname> <replaceable>t</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
@ -138,4 +147,4 @@ You can also create new types using the function
|
|||||||
<varname>mkOptionType</varname>. See
|
<varname>mkOptionType</varname>. See
|
||||||
<filename>lib/types.nix</filename> in Nixpkgs for details.</para>
|
<filename>lib/types.nix</filename> in Nixpkgs for details.</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
Loading…
Reference in New Issue
Block a user