summary refs log tree commit diff
path: root/nixos/modules/misc/nixpkgs.nix
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2018-02-09 18:47:48 +0000
committerGitHub <noreply@github.com>2018-02-09 18:47:48 +0000
commit1fcbc7055cb599cec45eb4d8dad61d12357947d9 (patch)
tree046370acf1be551197d2466bbbe009f680c84102 /nixos/modules/misc/nixpkgs.nix
parent3748f3aac839e3431691420e0b04bb7c82c3accb (diff)
parentf2a45a47d4b4b1293083a2e5882380c7e15a7e2c (diff)
downloadnixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.tar
nixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.tar.gz
nixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.tar.bz2
nixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.tar.lz
nixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.tar.xz
nixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.tar.zst
nixpkgs-1fcbc7055cb599cec45eb4d8dad61d12357947d9.zip
Merge pull request #33700 from roberth/nixos-externalpkgs
nixos: Add nixpkgs.pkgs option
Diffstat (limited to 'nixos/modules/misc/nixpkgs.nix')
-rw-r--r--nixos/modules/misc/nixpkgs.nix53
1 files changed, 50 insertions, 3 deletions
diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix
index c3e7ab9a666..e747fbc6755 100644
--- a/nixos/modules/misc/nixpkgs.nix
+++ b/nixos/modules/misc/nixpkgs.nix
@@ -3,6 +3,8 @@
 with lib;
 
 let
+  cfg = config.nixpkgs;
+
   isConfig = x:
     builtins.isAttrs x || lib.isFunction x;
 
@@ -42,12 +44,51 @@ let
     merge = lib.mergeOneOption;
   };
 
-  _pkgs = import ../../.. config.nixpkgs;
+  pkgsType = mkOptionType {
+    name = "nixpkgs";
+    description = "An evaluation of Nixpkgs; the top level attribute set of packages";
+    check = builtins.isAttrs;
+  };
 
 in
 
 {
   options.nixpkgs = {
+
+    pkgs = mkOption {
+      defaultText = literalExample
+        ''import "''${nixos}/.." {
+            inherit (config.nixpkgs) config overlays system;
+          }
+        '';
+      default = import ../../.. { inherit (cfg) config overlays system; };
+      type = pkgsType;
+      example = literalExample ''import <nixpkgs> {}'';
+      description = ''
+        This is the evaluation of Nixpkgs that will be provided to
+        all NixOS modules. Defining this option has the effect of
+        ignoring the other options that would otherwise be used to
+        evaluate Nixpkgs, because those are arguments to the default
+        value. The default value imports the Nixpkgs source files
+        relative to the location of this NixOS module, because
+        NixOS and Nixpkgs are distributed together for consistency,
+        so the <code>nixos</code> in the default value is in fact a
+        relative path. The <code>config</code>, <code>overlays</code>
+        and <code>system</code> come from this option's siblings.
+
+        This option can be used by applications like NixOps to increase
+        the performance of evaluation, or to create packages that depend
+        on a container that should be built with the exact same evaluation
+        of Nixpkgs, for example. Applications like this should set
+        their default value using <code>lib.mkDefault</code>, so
+        user-provided configuration can override it without using
+        <code>lib</code>.
+
+        Note that using a distinct version of Nixpkgs with NixOS may
+        be an unexpected source of problems. Use this option with care.
+      '';
+    };
+
     config = mkOption {
       default = {};
       example = literalExample
@@ -59,6 +100,8 @@ in
         The configuration of the Nix Packages collection.  (For
         details, see the Nixpkgs documentation.)  It allows you to set
         package configuration options.
+
+        Ignored when <code>nixpkgs.pkgs</code> is set.
       '';
     };
 
@@ -82,6 +125,8 @@ in
         takes as an argument the <emphasis>original</emphasis> Nixpkgs.
         The first argument should be used for finding dependencies, and
         the second should be used for overriding recipes.
+
+        Ignored when <code>nixpkgs.pkgs</code> is set.
       '';
     };
 
@@ -93,14 +138,16 @@ in
         If unset, it defaults to the platform type of your host system.
         Specifying this option is useful when doing distributed
         multi-platform deployment, or when building virtual machines.
+
+        Ignored when <code>nixpkgs.pkgs</code> is set.
       '';
     };
   };
 
   config = {
     _module.args = {
-      pkgs = _pkgs;
-      pkgs_i686 = _pkgs.pkgsi686Linux;
+      pkgs = cfg.pkgs;
+      pkgs_i686 = cfg.pkgs.pkgsi686Linux;
     };
   };
 }