git.iko.soy/typeable/nixpkgs
on master help sign in
nixpkgs module: Fix defaulting of `localSystem` and `system`

Take two of #40708 (4fe289860888668956b7e79e24efeb101c2f51d1). That PR attempted to bidirectionally default `config.nixpkgs.system` and `config.nixpkgs.localSystem.system` to each be updated by the other. But this is not possible with the way the module system works. Divergence in certain cases in inevitable. This PR is more conservative and just has `system` default `localSystem` and `localSystem` make the final call as-is. This solves a number of issues. - `localSystem` completely overrides `system`, just like with nixpkgs proper. There is no need to specify `localSystem.system` to clobber the old system. - `config.nixpkgs.localSystem` is exactly what is passed to nixpkgs. No spooky steps. - `config.nixpkgs.localSystem` is elaborated just as nixpkgs would so that all attributes are available, not just the ones the user specified. The remaining issue is just that `config.nixpkgs.system` doesn't update based on `config.nixpkgs.localSystem.system`. It should never be referred to lest it is a bogus stale value because `config.nixpkgs.localSystem` overwrites it. Fixes #46320

commit9f9723b179961e7235d8e808c4ee8eaf52e05086 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateThu 17 May 2018, 18:53 (9 years ago) parent8ae2703
2 files changed+13−5
nixos/lib/eval-config.nix+5−1 nixos/modules/misc/nixpkgs.nix+8−4
nixos/lib/eval-config.nix+5−1
@@ -36,7 +36,11 @@ let
3636 _file = ./eval-config.nix;
3737 key = _file;
3838 config = {
39− nixpkgs.localSystem = lib.mkDefault { inherit system; };
39+ # Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
40+ # this. Since the latter defaults to the former, the former should
41+ # default to the argument. That way this new default could propagate all
42+ # they way through, but has the last priority behind everything else.
43+ nixpkgs.system = lib.mkDefault system;
4044 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
4145 };
4246 };
nixos/modules/misc/nixpkgs.nix+8−4
@@ -62,12 +62,11 @@ in
6262 pkgs = mkOption {
6363 defaultText = literalExample
6464 ''import "''${nixos}/.." {
65− inherit (config.nixpkgs) config overlays localSystem crossSystem;
65+ inherit (cfg) config overlays localSystem crossSystem;
6666 }
6767 '';
6868 default = import ../../.. {
69− localSystem = { inherit (cfg) system; } // cfg.localSystem;
70− inherit (cfg) config overlays crossSystem;
69+ inherit (cfg) config overlays localSystem crossSystem;
7170 };
7271 type = pkgsType;
7372 example = literalExample ''import <nixpkgs> {}'';
@@ -140,8 +139,11 @@ in
140139
141140 localSystem = mkOption {
142141 type = types.attrs; # TODO utilize lib.systems.parsedPlatform
143− default = { system = builtins.currentSystem; };
142+ default = { inherit (cfg) system; };
144143 example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; };
144+ # Make sure that the final value has all fields for sake of other modules
145+ # referring to this. TODO make `lib.systems` itself use the module system.
146+ apply = lib.systems.elaborate;
145147 defaultText = literalExample
146148 ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
147149 description = ''
@@ -180,6 +182,7 @@ in
180182 system = mkOption {
181183 type = types.str;
182184 example = "i686-linux";
185+ default = { system = builtins.currentSystem; };
183186 description = ''
184187 Specifies the Nix platform type on which NixOS should be built.
185188 It is better to specify <code>nixpkgs.localSystem</code> instead.
@@ -196,6 +199,7 @@ in
196199 </programlisting>
197200 See <code>nixpkgs.localSystem</code> for more information.
198201
202+ Ignored when <code>nixpkgs.localSystem</code> is set.
199203 Ignored when <code>nixpkgs.pkgs</code> is set.
200204 '';
201205 };