From e15308727693143d45904eeba3cd0b72fd643be5 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 10 Jul 2022 13:18:31 +0200 Subject: [PATCH 1/5] nixos: Fix use of nixpkgs.localSystem localSystem is ill-defined because unlike hostPlatform, its meaning is different in a cross or non-cross context. --- nixos/modules/services/misc/dysnomia.nix | 2 +- nixos/modules/virtualisation/nixos-containers.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/misc/dysnomia.nix b/nixos/modules/services/misc/dysnomia.nix index 7d9c39a6973..1964fa93f93 100644 --- a/nixos/modules/services/misc/dysnomia.nix +++ b/nixos/modules/services/misc/dysnomia.nix @@ -186,7 +186,7 @@ in dysnomia.properties = { hostname = config.networking.hostName; - inherit (config.nixpkgs.localSystem) system; + inherit (pkgs.stdenv.hostPlatform) system; supportedTypes = [ "echo" diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index b9301515712..deb9742a2c1 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -132,7 +132,7 @@ let # If the host is 64-bit and the container is 32-bit, add a # --personality flag. - ${optionalString (config.nixpkgs.localSystem.system == "x86_64-linux") '' + ${optionalString (pkgs.stdenv.hostPlatform.system == "x86_64-linux") '' if [ "$(< ''${SYSTEM_PATH:-/nix/var/nix/profiles/per-container/$INSTANCE/system}/system)" = i686-linux ]; then extraFlags+=" --personality=x86" fi From 711e653a65300652f680aa9aa7e26b609f7d232e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 9 Jun 2022 11:27:29 +0200 Subject: [PATCH 2/5] nixos/eval-config: Allow system to be set modularly when arg is null --- nixos/lib/eval-config.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 3b58ef29797..791a03a3ba3 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -9,7 +9,9 @@ # expressions are ever made modular at the top level) can just use # types.submodule instead of using eval-config.nix evalConfigArgs@ -{ # !!! system can be set modularly, would be nice to remove +{ # !!! system can be set modularly, would be nice to remove, + # however, removing or changing this default is too much + # of a breaking change. To set it modularly, pass `null`. system ? builtins.currentSystem , # !!! is this argument needed any more? The pkgs argument can # be set modularly anyway. @@ -48,7 +50,7 @@ let # this. Since the latter defaults to the former, the former should # default to the argument. That way this new default could propagate all # they way through, but has the last priority behind everything else. - nixpkgs.system = lib.mkDefault system; + nixpkgs.system = lib.mkIf (system != null) (lib.mkDefault system); _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_); }; From 62314ccc17684bcc9310f3b380cffe15bae177d6 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 9 Jun 2022 11:37:08 +0200 Subject: [PATCH 3/5] flake.lib.nixosSystem: Allow nixpkgs.system to be set instead --- flake.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flake.nix b/flake.nix index 8c0403adc4a..f78c7512873 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,11 @@ ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}"; system.nixos.revision = final.mkIf (self ? rev) self.rev; } ]; + } // lib.optionalAttrs (! args?system) { + # Allow system to be set modularly in nixpkgs.system. + # We set it to null, to remove the "legacy" entrypoint's + # non-hermetic default. + system = null; }); }); From 82378f9c0ca67445e915fab1af5f14b0327019e6 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 9 Jun 2022 11:38:30 +0200 Subject: [PATCH 4/5] flake.nix: Format --- flake.nix | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index f78c7512873..67ecfc6eb08 100644 --- a/flake.nix +++ b/flake.nix @@ -20,18 +20,20 @@ nixos = import ./nixos/lib { lib = final; }; nixosSystem = args: - import ./nixos/lib/eval-config.nix (args // { - modules = args.modules ++ [ { - system.nixos.versionSuffix = - ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}"; - system.nixos.revision = final.mkIf (self ? rev) self.rev; - } ]; - } // lib.optionalAttrs (! args?system) { - # Allow system to be set modularly in nixpkgs.system. - # We set it to null, to remove the "legacy" entrypoint's - # non-hermetic default. - system = null; - }); + import ./nixos/lib/eval-config.nix ( + args // { + modules = args.modules ++ [{ + system.nixos.versionSuffix = + ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}"; + system.nixos.revision = final.mkIf (self ? rev) self.rev; + }]; + } // lib.optionalAttrs (! args?system) { + # Allow system to be set modularly in nixpkgs.system. + # We set it to null, to remove the "legacy" entrypoint's + # non-hermetic default. + system = null; + } + ); }); checks.x86_64-linux.tarball = jobs.tarball; From acd969a4ddfdc45eca90ac4d920857ec50c5c1cd Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 25 Jun 2022 11:02:54 +0200 Subject: [PATCH 5/5] nixos/nixpkgs.nix: Recommend hostPlatform instead of system The ${opt.*} syntax will print the full path when NixOS is used as a submodule. nixpkgs.system / nixpkgs.localSystem must not be read by any other module because its meaning is ambiguous in cross vs non-cross contexts. hostPlatform is generally what you need. *Where* you build something generally doesn't matter in a system _configuration_ context like NixOS. --- nixos/modules/misc/nixpkgs.nix | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index ad017aff816..e991ff42028 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -244,6 +244,14 @@ in defaultText = literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; description = '' + Systems with a recently generated hardware-configuration.nix + do not need to specify this option, unless cross-compiling, in which case + you should set only . + + If this is somehow not feasible, you may fall back to removing the + line from the generated config and + use the old options. + Specifies the platform on which NixOS should be built. When nixpkgs.crossSystem is unset, it also specifies the platform for which NixOS should be @@ -265,6 +273,10 @@ in default = null; example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; }; description = '' + Systems with a recently generated hardware-configuration.nix + may instead specify only , + or fall back to removing the line from the generated config. + Specifies the platform for which NixOS should be built. Specify this only if it is different from nixpkgs.localSystem, the platform @@ -280,7 +292,29 @@ in system = mkOption { type = types.str; example = "i686-linux"; + default = + if opt.hostPlatform.isDefined + then + throw '' + Neither ${opt.system} nor any other option in nixpkgs.* is meant + to be read by modules and configurations. + Use pkgs.stdenv.hostPlatform instead. + '' + else + throw '' + Neither ${opt.hostPlatform} nor or the legacy option ${opt.system} has been set. + You can set ${opt.hostPlatform} in hardware-configuration.nix by re-running + a recent version of nixos-generate-config. + The option ${opt.system} is still fully supported for NixOS 22.05 interoperability, + but will be deprecated in the future, so we recommend to set ${opt.hostPlatform}. + ''; + defaultText = lib.literalMD '' + Traditionally `builtins.currentSystem`, but unset when invoking NixOS through `lib.nixosSystem`. + ''; description = '' + This option does not need to be specified for NixOS configurations + with a recently generated hardware-configuration.nix. + Specifies the Nix platform type on which NixOS should be built. It is better to specify nixpkgs.localSystem instead.