about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2018-11-13 09:55:24 +0100
committerGitHub <noreply@github.com>2018-11-13 09:55:24 +0100
commitdd3aca2d0b9dcb4888779bfb08805d79596607c9 (patch)
tree43b1f614f2520d5ff13dcac6fa0632796b42b4f0
parent5189877d348a98c092828211f535dc8365c4dc6e (diff)
parentb60dccbf4f021596913ad595dc43a3dff9f44ad4 (diff)
downloadnixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.tar
nixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.tar.gz
nixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.tar.bz2
nixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.tar.lz
nixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.tar.xz
nixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.tar.zst
nixlib-dd3aca2d0b9dcb4888779bfb08805d79596607c9.zip
Merge pull request #49256 from roberth/nixos-nixpkgs-pkgs-use-overlays
NixOS: use overlays when nixpkgs.pkgs is set
-rw-r--r--nixos/doc/manual/release-notes/rl-1903.xml8
-rw-r--r--nixos/modules/misc/nixpkgs.nix58
-rw-r--r--pkgs/top-level/all-packages.nix2
-rw-r--r--pkgs/top-level/stage.nix4
4 files changed, 57 insertions, 15 deletions
diff --git a/nixos/doc/manual/release-notes/rl-1903.xml b/nixos/doc/manual/release-notes/rl-1903.xml
index c1649edcf236..dafd62e8779b 100644
--- a/nixos/doc/manual/release-notes/rl-1903.xml
+++ b/nixos/doc/manual/release-notes/rl-1903.xml
@@ -149,6 +149,14 @@
    </listitem>
    <listitem>
     <para>
+     When the <literal>nixpkgs.pkgs</literal> option is set, NixOS will no
+     longer ignore the <literal>nixpkgs.overlays</literal> option. The old
+     behavior can be recovered by setting <literal>nixpkgs.overlays =
+     lib.mkForce [];</literal>.
+    </para>
+   </listitem>
+   <listitem>
+    <para>
      OpenSMTPD has been upgraded to version 6.4.0p1. This release makes
      backwards-incompatible changes to the configuration file format. See
      <command>man smtpd.conf</command> for more information on the new file
diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix
index 1dfd2c3c6cf3..93fbf16841e5 100644
--- a/nixos/modules/misc/nixpkgs.nix
+++ b/nixos/modules/misc/nixpkgs.nix
@@ -1,9 +1,10 @@
-{ config, lib, pkgs, ... }:
+{ config, options, lib, pkgs, ... }:
 
 with lib;
 
 let
   cfg = config.nixpkgs;
+  opt = options.nixpkgs;
 
   isConfig = x:
     builtins.isAttrs x || lib.isFunction x;
@@ -54,6 +55,12 @@ let
     check = builtins.isAttrs;
   };
 
+  defaultPkgs = import ../../../pkgs/top-level/default.nix {
+    inherit (cfg) config overlays localSystem crossSystem;
+  };
+
+  finalPkgs = if opt.pkgs.isDefined then cfg.pkgs.appendOverlays cfg.overlays else defaultPkgs;
+
 in
 
 {
@@ -61,21 +68,25 @@ in
 
     pkgs = mkOption {
       defaultText = literalExample
-        ''import "''${nixos}/.." {
+        ''import "''${nixos}/../pkgs/top-level" {
             inherit (cfg) config overlays localSystem crossSystem;
           }
         '';
-      default = import ../../.. {
-        inherit (cfg) config overlays localSystem crossSystem;
-      };
       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
+        If set, the pkgs argument to all NixOS modules is the value of
+        this option, extended with <code>nixpkgs.overlays</code>, if
+        that is also set. Either <code>nixpkgs.crossSystem</code> or
+        <code>nixpkgs.localSystem</code> will be used in an assertion
+        to check that the NixOS and Nixpkgs architectures match. Any
+        other options in <code>nixpkgs.*</code>, notably <code>config</code>,
+        will be ignored.
+
+        If unset, the pkgs argument to all NixOS modules is determined
+        as shown in the default value for this option.
+
+        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
@@ -128,12 +139,14 @@ in
       description = ''
         List of overlays to use with the Nix Packages collection.
         (For details, see the Nixpkgs documentation.)  It allows
-        you to override packages globally. This is a function that
+        you to override packages globally. Each function in the list
         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.
+        If <code>nixpkgs.pkgs</code> is set, overlays specified here
+        will be applied after the overlays that were already present
+        in <code>nixpkgs.pkgs</code>.
       '';
     };
 
@@ -207,7 +220,26 @@ in
 
   config = {
     _module.args = {
-      pkgs = cfg.pkgs;
+      pkgs = finalPkgs;
     };
+
+    assertions = [
+      (
+        let
+          nixosExpectedSystem =
+            if config.nixpkgs.crossSystem != null
+            then config.nixpkgs.crossSystem.system
+            else config.nixpkgs.localSystem.system;
+          nixosOption =
+            if config.nixpkgs.crossSystem != null
+            then "nixpkgs.crossSystem"
+            else "nixpkgs.localSystem";
+          pkgsSystem = finalPkgs.stdenv.targetPlatform.system;
+        in {
+          assertion = nixosExpectedSystem == pkgsSystem;
+          message = "The NixOS nixpkgs.pkgs option was set to a Nixpkgs invocation that compiles to target system ${pkgsSystem} but NixOS was configured for system ${nixosExpectedSystem} via NixOS option ${nixosOption}. The NixOS system settings must match the Nixpkgs target system.";
+        }
+      )
+    ];
   };
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 7459c1c69ffe..ad68a42f3f29 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -22212,7 +22212,7 @@ with pkgs;
          in
            myOS.run-nginx
 
-     Unlike in plain NixOS, the nixpkgs.config, nixpkgs.overlays and
+     Unlike in plain NixOS, the nixpkgs.config and
      nixpkgs.system options will be ignored by default. Instead,
      nixpkgs.pkgs will have the default value of pkgs as it was
      constructed right after invoking the nixpkgs function (e.g. the
diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix
index 4e6531286ee5..1d412a6582cd 100644
--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -164,7 +164,9 @@ let
     # preexisting overlays. Prefer to initialize with the right overlays
     # in one go when calling Nixpkgs, for performance and simplicity.
     appendOverlays = extraOverlays:
-      import ./stage.nix (args // { overlays = args.overlays ++ extraOverlays; });
+      if extraOverlays == []
+      then self
+      else import ./stage.nix (args // { overlays = args.overlays ++ extraOverlays; });
 
     # Extend the package set with a single overlay. This preserves
     # preexisting overlays. Prefer to initialize with the right overlays