Merge pull request #46341 from obsidiansystems/fix-46320

nixpkgs module: Fix defaulting of `localSystem` and `system`

authored by Graham Christensen and committed by GitHub ca7391da bcedf59d

+13 -5
+5 -1
nixos/lib/eval-config.nix
··· 36 _file = ./eval-config.nix; 37 key = _file; 38 config = { 39 - nixpkgs.localSystem = lib.mkDefault { inherit system; }; 40 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_); 41 }; 42 };
··· 36 _file = ./eval-config.nix; 37 key = _file; 38 config = { 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; 44 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_); 45 }; 46 };
+8 -4
nixos/modules/misc/nixpkgs.nix
··· 62 pkgs = mkOption { 63 defaultText = literalExample 64 ''import "''${nixos}/.." { 65 - inherit (config.nixpkgs) config overlays localSystem crossSystem; 66 } 67 ''; 68 default = import ../../.. { 69 - localSystem = { inherit (cfg) system; } // cfg.localSystem; 70 - inherit (cfg) config overlays crossSystem; 71 }; 72 type = pkgsType; 73 example = literalExample ''import <nixpkgs> {}''; ··· 140 141 localSystem = mkOption { 142 type = types.attrs; # TODO utilize lib.systems.parsedPlatform 143 - default = { system = builtins.currentSystem; }; 144 example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; }; 145 defaultText = literalExample 146 ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; 147 description = '' ··· 180 system = mkOption { 181 type = types.str; 182 example = "i686-linux"; 183 description = '' 184 Specifies the Nix platform type on which NixOS should be built. 185 It is better to specify <code>nixpkgs.localSystem</code> instead. ··· 196 </programlisting> 197 See <code>nixpkgs.localSystem</code> for more information. 198 199 Ignored when <code>nixpkgs.pkgs</code> is set. 200 ''; 201 };
··· 62 pkgs = mkOption { 63 defaultText = literalExample 64 ''import "''${nixos}/.." { 65 + inherit (cfg) config overlays localSystem crossSystem; 66 } 67 ''; 68 default = import ../../.. { 69 + inherit (cfg) config overlays localSystem crossSystem; 70 }; 71 type = pkgsType; 72 example = literalExample ''import <nixpkgs> {}''; ··· 139 140 localSystem = mkOption { 141 type = types.attrs; # TODO utilize lib.systems.parsedPlatform 142 + default = { inherit (cfg) system; }; 143 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; 147 defaultText = literalExample 148 ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; 149 description = '' ··· 182 system = mkOption { 183 type = types.str; 184 example = "i686-linux"; 185 + default = { system = builtins.currentSystem; }; 186 description = '' 187 Specifies the Nix platform type on which NixOS should be built. 188 It is better to specify <code>nixpkgs.localSystem</code> instead. ··· 199 </programlisting> 200 See <code>nixpkgs.localSystem</code> for more information. 201 202 + Ignored when <code>nixpkgs.localSystem</code> is set. 203 Ignored when <code>nixpkgs.pkgs</code> is set. 204 ''; 205 };