summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-08-06 19:55:42 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-08-07 03:09:57 +0200
commit214d4fb73cd5c2aab6718a38b35c8b5217f0f200 (patch)
treef78ea308807277211b91f5d692eedce3a842501d
parentfa7a0f24a4c8e02789be6b5c9c83c4c3ee6948a5 (diff)
downloadnixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.tar
nixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.tar.gz
nixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.tar.bz2
nixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.tar.lz
nixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.tar.xz
nixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.tar.zst
nixpkgs-214d4fb73cd5c2aab6718a38b35c8b5217f0f200.zip
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.
-rw-r--r--lib/attrsets.nix10
-rw-r--r--lib/strings.nix5
-rw-r--r--lib/types.nix8
-rw-r--r--nixos/doc/manual/development/option-declarations.xml11
4 files changed, 30 insertions, 4 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index 20be2002402..2300ee9c000 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -221,6 +221,16 @@ rec {
   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',
      otherwise an empty attribute set. */
   optionalAttrs = cond: as: if cond then as else {};
diff --git a/lib/strings.nix b/lib/strings.nix
index bac03c9d7ad..e72bdc6d968 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -218,4 +218,9 @@ rec {
 
   # Format a number adding leading zeroes up to fixed width.
   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;
+
 }
diff --git a/lib/types.nix b/lib/types.nix
index 49f24b022de..a7f9bf1946e 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -94,14 +94,16 @@ rec {
     # derivation is a reserved keyword.
     package = mkOptionType {
       name = "derivation";
-      check = isDerivation;
-      merge = mergeOneOption;
+      check = x: isDerivation x || isStorePath x;
+      merge = loc: defs:
+        let res = mergeOneOption loc defs;
+        in if isDerivation res then res else toDerivation res;
     };
 
     path = mkOptionType {
       name = "path";
       # 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;
     };
 
diff --git a/nixos/doc/manual/development/option-declarations.xml b/nixos/doc/manual/development/option-declarations.xml
index 6d93dc5c009..ea5d1241876 100644
--- a/nixos/doc/manual/development/option-declarations.xml
+++ b/nixos/doc/manual/development/option-declarations.xml
@@ -107,6 +107,15 @@ options = {
   </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>
     <term><varname>types.listOf</varname> <replaceable>t</replaceable></term>
     <listitem>
       <para>A list of elements of type <replaceable>t</replaceable>
@@ -138,4 +147,4 @@ You can also create new types using the function
 <varname>mkOptionType</varname>.  See
 <filename>lib/types.nix</filename> in Nixpkgs for details.</para>
 
-</section>
\ No newline at end of file
+</section>