From 889a5c35127e4e6b2c722611dcaa9c802337446b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 27 Oct 2018 14:00:19 +0200 Subject: [PATCH 1/7] pkgs.appendOverlays: Avoid unnecessary nixpkgs evaluation --- pkgs/top-level/stage.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index 37724a870a3..d270a6608a1 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 From a54a799d59f2a4fba2e119e0c42dbe96c2c74a68 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 27 Oct 2018 14:51:54 +0200 Subject: [PATCH 2/7] NixOS: nixpkgs.pkgs: Append overlays when specified --- nixos/modules/misc/nixpkgs.nix | 22 ++++++++++++++-------- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 7f9833e184a..3e9f93b95e6 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 ../../.. { + inherit (cfg) config overlays localSystem crossSystem; + }; + + finalPkgs = if opt.pkgs.isDefined then cfg.pkgs.appendOverlays cfg.overlays else defaultPkgs; + in { @@ -65,9 +72,6 @@ in inherit (cfg) config overlays localSystem crossSystem; } ''; - default = import ../../.. { - inherit (cfg) config overlays localSystem crossSystem; - }; type = pkgsType; example = literalExample ''import {}''; description = '' @@ -128,12 +132,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,8 +213,8 @@ in config = { _module.args = { - pkgs = cfg.pkgs; - pkgs_i686 = cfg.pkgs.pkgsi686Linux; + pkgs = finalPkgs; + pkgs_i686 = finalPkgs.pkgsi686Linux; }; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 782fb6d8dd8..d0038d8c256 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22091,7 +22091,7 @@ with pkgs; * The result can be extended in the modules by defining * extra options in system.build. * - * 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 From 5f894a67f565129ac683434c3040ba85c2df3750 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 28 Oct 2018 02:09:43 +0200 Subject: [PATCH 3/7] nixos/modules/misc/nixpkgs.nix: Use pure Nixpkgs function --- nixos/modules/misc/nixpkgs.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 3e9f93b95e6..ee85f8c7ab9 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -55,7 +55,7 @@ let check = builtins.isAttrs; }; - defaultPkgs = import ../../.. { + defaultPkgs = import ../../../pkgs/top-level/default.nix { inherit (cfg) config overlays localSystem crossSystem; }; @@ -68,7 +68,7 @@ in pkgs = mkOption { defaultText = literalExample - ''import "''${nixos}/.." { + ''import "''${nixos}/../pkgs/top-level" { inherit (cfg) config overlays localSystem crossSystem; } ''; From 696a8bd2b5750d5a0c67887cce0628f59dc26f9e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 28 Oct 2018 02:11:00 +0200 Subject: [PATCH 4/7] nixpkgs.overlays: Add note about nixpkgs.pkgs' treatment of other options --- nixos/modules/misc/nixpkgs.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index ee85f8c7ab9..81556c419bd 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -140,6 +140,9 @@ in If nixpkgs.pkgs is set, overlays specified here will be applied after the overlays that were already present in nixpkgs.pkgs. + + Note that other options such as nixpkgs.config will + be ignored when nixpkgs.pkgs is set. ''; }; From 5341e145c3b685500e9881c118d583dffaa65012 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 3 Nov 2018 19:48:42 +0100 Subject: [PATCH 5/7] release-notes/19.03: nixpkgs.pkgs and nixpkgs.overlays now combine --- nixos/doc/manual/release-notes/rl-1903.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-1903.xml b/nixos/doc/manual/release-notes/rl-1903.xml index 839d75b53bd..9a24fb94062 100644 --- a/nixos/doc/manual/release-notes/rl-1903.xml +++ b/nixos/doc/manual/release-notes/rl-1903.xml @@ -137,6 +137,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 [];. + + From b682778366f91bd3a2b5746cfc951ad429904f16 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 4 Nov 2018 23:09:43 +0100 Subject: [PATCH 6/7] nixos/../nixpkgs.nix: Add assertions to check pkgs' system --- nixos/modules/misc/nixpkgs.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 461a3b68ed6..2bebbdcad94 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -218,5 +218,24 @@ in _module.args = { 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."; + } + ) + ]; }; } From b60dccbf4f021596913ad595dc43a3dff9f44ad4 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 10 Nov 2018 23:21:21 +0100 Subject: [PATCH 7/7] NixOS: update config.nixpkgs.pkgs documentation --- nixos/modules/misc/nixpkgs.nix | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 2bebbdcad94..93fbf16841e 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -75,11 +75,18 @@ in 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 @@ -140,9 +147,6 @@ in If nixpkgs.pkgs is set, overlays specified here will be applied after the overlays that were already present in nixpkgs.pkgs. - - Note that other options such as nixpkgs.config will - be ignored when nixpkgs.pkgs is set. ''; };