diff --git a/nixos/doc/manual/release-notes/rl-1903.xml b/nixos/doc/manual/release-notes/rl-1903.xml
index c1649edcf23..dafd62e8779 100644
--- a/nixos/doc/manual/release-notes/rl-1903.xml
+++ b/nixos/doc/manual/release-notes/rl-1903.xml
@@ -147,6 +147,14 @@
make sure to update your configuration if you want to keep proglodyte-wasm
+
+
+ When the nixpkgs.pkgs option is set, NixOS will no
+ longer ignore the nixpkgs.overlays option. The old
+ behavior can be recovered by setting nixpkgs.overlays =
+ lib.mkForce [];.
+
+
OpenSMTPD has been upgraded to version 6.4.0p1. This release makes
diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix
index 1dfd2c3c6cf..93fbf16841e 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 {}'';
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 nixpkgs.overlays
, if
+ that is also set. Either nixpkgs.crossSystem
or
+ nixpkgs.localSystem
will be used in an assertion
+ to check that the NixOS and Nixpkgs architectures match. Any
+ other options in nixpkgs.*
, notably config
,
+ 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 nixos
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 original Nixpkgs.
The first argument should be used for finding dependencies, and
the second should be used for overriding recipes.
- Ignored when nixpkgs.pkgs
is set.
+ If nixpkgs.pkgs
is set, overlays specified here
+ will be applied after the overlays that were already present
+ in nixpkgs.pkgs
.
'';
};
@@ -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 7459c1c69ff..ad68a42f3f2 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 4e6531286ee..1d412a6582c 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