From c6f7d4367894047592cc412740f0c1f5b2ca2b59 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 5 Apr 2018 15:22:45 -0400 Subject: [PATCH] nixpkgs module: Clean up platform options - `localSystem` is added, it strictly supercedes system - `crossSystem`'s description mentions `localSystem` (and vice versa). - No more weird special casing I don't even understand TEMP --- lib/systems/parse.nix | 4 +- nixos/doc/manual/man-nixos-build-vms.xml | 6 +- nixos/lib/eval-config.nix | 4 +- nixos/modules/misc/nixpkgs.nix | 69 ++++++++++++++++---- nixos/modules/services/misc/dysnomia.nix | 2 +- nixos/modules/services/misc/nixos-manual.nix | 2 +- nixos/modules/virtualisation/containers.nix | 4 +- pkgs/stdenv/generic/check-meta.nix | 2 +- 8 files changed, 67 insertions(+), 26 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 641a7f5d758..0dd8999f5f9 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -201,7 +201,7 @@ rec { ################################################################################ - types.system = mkOptionType { + types.parsedPlatform = mkOptionType { name = "system"; description = "fully parsed representation of llvm- or nix-style platform tuple"; merge = mergeOneOption; @@ -215,7 +215,7 @@ rec { isSystem = isType "system"; mkSystem = components: - assert types.system.check components; + assert types.parsedPlatform.check components; setType "system" components; mkSkeletonFromList = l: { diff --git a/nixos/doc/manual/man-nixos-build-vms.xml b/nixos/doc/manual/man-nixos-build-vms.xml index 878ebee0527..f4b59a7c6d4 100644 --- a/nixos/doc/manual/man-nixos-build-vms.xml +++ b/nixos/doc/manual/man-nixos-build-vms.xml @@ -40,7 +40,7 @@ points to the generated virtual network. test1 = {pkgs, config, ...}: { services.openssh.enable = true; - nixpkgs.system = "i686-linux"; + nixpkgs.localSystem.system = "i686-linux"; deployment.targetHost = "test1.example.net"; # Other NixOS options @@ -51,7 +51,7 @@ points to the generated virtual network. services.openssh.enable = true; services.httpd.enable = true; environment.systemPackages = [ pkgs.lynx ]; - nixpkgs.system = "x86_64-linux"; + nixpkgs.localSystem.system = "x86_64-linux"; deployment.targetHost = "test2.example.net"; # Other NixOS options @@ -66,7 +66,7 @@ In each NixOS configuration, two attributes have a special meaning. The deployment.targetHost specifies the address (domain name or IP address) of the system which is used by ssh to perform -remote deployment operations. The nixpkgs.system +remote deployment operations. The nixpkgs.localSystem.system attribute can be used to specify an architecture for the target machine, such as i686-linux which builds a 32-bit NixOS configuration. Omitting this property will build the configuration diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 2e7971cca81..97c79487df4 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -26,7 +26,7 @@ , lib ? import ../../lib }: -let extraArgs_ = extraArgs; pkgs_ = pkgs; system_ = system; +let extraArgs_ = extraArgs; pkgs_ = pkgs; extraModules = let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; in if e == "" then [] else [(import (builtins.toPath e))]; in @@ -36,7 +36,7 @@ let _file = ./eval-config.nix; key = _file; config = { - nixpkgs.system = lib.mkDefault system_; + nixpkgs.localSystem = lib.mkDefault { inherit system; }; _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_); }; }; diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 9217250eec2..b8a55a24394 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -58,10 +58,13 @@ in pkgs = mkOption { defaultText = literalExample ''import "''${nixos}/.." { - inherit (config.nixpkgs) config overlays system; + inherit (config.nixpkgs) config overlays localSystem crossSystem; } ''; - default = import ../../.. { inherit (cfg) config overlays system crossSystem; }; + default = import ../../.. { + localSystem = { inherit (cfg) system; } // cfg.localSystem; + inherit (cfg) config overlays crossSystem; + }; type = pkgsType; example = literalExample ''import {}''; description = '' @@ -73,8 +76,9 @@ in 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 - relative path. The config, overlays - and system come from this option's siblings. + relative path. The config, overlays, + localSystem, and crossSystem come + from this option's siblings. This option can be used by applications like NixOps to increase the performance of evaluation, or to create packages that depend @@ -130,13 +134,40 @@ in ''; }; - crossSystem = mkOption { - type = types.nullOr types.attrs; - default = null; + localSystem = mkOption { + type = types.attrs; # TODO utilize lib.systems.parsedPlatform + default = { system = builtins.currentSystem; }; + example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; }; + defaultText = literalExample + ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; description = '' - The description of the system we're cross-compiling to, or null - if this isn't a cross-compile. See the description of the - crossSystem argument in the nixpkgs manual. + Specifies the platform on which NixOS should be built. When + nixpkgs.crossSystem is unset, it also specifies + the platform for which NixOS should be + built. If this option is unset, it defaults to the platform + type of the machine where evaluation happens. Specifying this + option is useful when doing distributed multi-platform + deployment, or when building virtual machines. See its + description in the Nixpkgs manual for more details. + + Ignored when nixpkgs.pkgs is set. + ''; + }; + + crossSystem = mkOption { + type = types.nullOr types.attrs; # TODO utilize lib.systems.parsedPlatform + default = null; + example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; }; + defaultText = literalExample + ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; + description = '' + Specifies the platform for which NixOS should be + built. Specify this only if it is different from + nixpkgs.localSystem, the platform + on which NixOS should be built. In other + words, specify this to cross-compile NixOS. Otherwise it + should be set as null, the default. See its description in the + Nixpkgs manual for more details. Ignored when nixpkgs.pkgs is set. ''; @@ -146,10 +177,20 @@ in type = types.str; example = "i686-linux"; description = '' - Specifies the Nix platform type for which NixOS should be built. - If unset, it defaults to the platform type of your host system. - Specifying this option is useful when doing distributed - multi-platform deployment, or when building virtual machines. + Specifies the Nix platform type on which NixOS should be built. + It is better to specify nixpkgs.localSystem instead. + + { + nixpkgs.system = ..; + } + + is the same as + + { + nixpkgs.localSystem.system = ..; + } + + See nixpkgs.localSystem for more information. Ignored when nixpkgs.pkgs is set. ''; diff --git a/nixos/modules/services/misc/dysnomia.nix b/nixos/modules/services/misc/dysnomia.nix index 25cd0038e36..9e66e0811ab 100644 --- a/nixos/modules/services/misc/dysnomia.nix +++ b/nixos/modules/services/misc/dysnomia.nix @@ -158,7 +158,7 @@ in services.dysnomia.properties = { hostname = config.networking.hostName; - system = if config.nixpkgs.system == "" then builtins.currentSystem else config.nixpkgs.system; + inherit (config.nixpkgs.localSystem) system; supportedTypes = (import "${pkgs.stdenv.mkDerivation { name = "supportedtypes"; diff --git a/nixos/modules/services/misc/nixos-manual.nix b/nixos/modules/services/misc/nixos-manual.nix index abf506ea7c6..4bd1c20edf7 100644 --- a/nixos/modules/services/misc/nixos-manual.nix +++ b/nixos/modules/services/misc/nixos-manual.nix @@ -23,7 +23,7 @@ let options = let scrubbedEval = evalModules { - modules = [ { nixpkgs.system = config.nixpkgs.system; } ] ++ baseModules; + modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ baseModules; args = (config._module.args) // { modules = [ ]; }; specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; }; }; diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index e54a5fe7d40..7ec443248de 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -112,7 +112,7 @@ let # If the host is 64-bit and the container is 32-bit, add a # --personality flag. - ${optionalString (config.nixpkgs.system == "x86_64-linux") '' + ${optionalString (config.nixpkgs.localSystem.system == "x86_64-linux") '' if [ "$(< ''${SYSTEM_PATH:-/nix/var/nix/profiles/per-container/$INSTANCE/system}/system)" = i686-linux ]; then extraFlags+=" --personality=x86" fi @@ -255,7 +255,7 @@ let }; - system = config.nixpkgs.system; + system = config.nixpkgs.localSystem.system; bindMountOpts = { name, config, ... }: { diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 26522ad6045..c86f1c8bd44 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -144,7 +144,7 @@ let license = either (listOf lib.types.attrs) (either lib.types.attrs str); maintainers = listOf (attrsOf str); priority = int; - platforms = listOf (either str lib.systems.parsed.types.system); + platforms = listOf (either str lib.systems.parsedPlatform.types.system); hydraPlatforms = listOf str; broken = bool;