Merge pull request #177012 from hercules-ci/nixos-modular-system
`flake.lib.nixosSystem`: Allow `nixpkgs.system` to be set modularly; improve error message
This commit is contained in:
commit
fe2c9ae814
5 changed files with 54 additions and 11 deletions
21
flake.nix
21
flake.nix
|
@ -20,13 +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;
|
||||
} ];
|
||||
});
|
||||
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;
|
||||
|
|
|
@ -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_);
|
||||
};
|
||||
|
|
|
@ -244,6 +244,14 @@ in
|
|||
defaultText = literalExpression
|
||||
''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
|
||||
description = ''
|
||||
Systems with a recently generated <literal>hardware-configuration.nix</literal>
|
||||
do not need to specify this option, unless cross-compiling, in which case
|
||||
you should set <emphasis>only</emphasis> <option>nixpkgs.buildPlatform</option>.
|
||||
|
||||
If this is somehow not feasible, you may fall back to removing the
|
||||
<option>nixpkgs.hostPlatform</option> line from the generated config and
|
||||
use the old options.
|
||||
|
||||
Specifies the platform on which NixOS should be built. When
|
||||
<code>nixpkgs.crossSystem</code> is unset, it also specifies
|
||||
the platform <emphasis>for</emphasis> 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 <literal>hardware-configuration.nix</literal>
|
||||
may instead specify <emphasis>only</emphasis> <option>nixpkgs.buildPlatform</option>,
|
||||
or fall back to removing the <option>nixpkgs.hostPlatform</option> line from the generated config.
|
||||
|
||||
Specifies the platform for which NixOS should be
|
||||
built. Specify this only if it is different from
|
||||
<code>nixpkgs.localSystem</code>, 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 <literal>hardware-configuration.nix</literal>.
|
||||
|
||||
Specifies the Nix platform type on which NixOS should be built.
|
||||
It is better to specify <code>nixpkgs.localSystem</code> instead.
|
||||
<programlisting>
|
||||
|
|
|
@ -186,7 +186,7 @@ in
|
|||
|
||||
dysnomia.properties = {
|
||||
hostname = config.networking.hostName;
|
||||
inherit (config.nixpkgs.localSystem) system;
|
||||
inherit (pkgs.stdenv.hostPlatform) system;
|
||||
|
||||
supportedTypes = [
|
||||
"echo"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue