top-level: Simplify impure and pure fallback

This is now possible, since the `platform` attribute has been removed in
PR #107214. I've been waiting to do a cleanup like this for a long time!

+24 -34
+10 -14
pkgs/top-level/default.nix
··· 1 1 /* This function composes the Nix Packages collection. It: 2 2 3 - 1. Applies the final stage to the given `config` if it is a function 3 + 1. Elaborates `localSystem` and `crossSystem` with defaults as needed. 4 4 5 - 2. Infers an appropriate `platform` based on the `system` if none is 6 - provided 5 + 2. Applies the final stage to the given `config` if it is a function 7 6 8 7 3. Defaults to no non-standard config and no cross-compilation target 9 8 ··· 50 49 in let 51 50 lib = import ../../lib; 52 51 52 + localSystem = lib.systems.elaborate args.localSystem; 53 + 54 + # Condition preserves sharing which in turn affects equality. 55 + crossSystem = 56 + if crossSystem0 == null || crossSystem0 == args.localSystem 57 + then localSystem 58 + else lib.systems.elaborate crossSystem0; 59 + 53 60 # Allow both: 54 61 # { /* the config */ } and 55 62 # { pkgs, ... } : { /* the config */ } ··· 57 64 if lib.isFunction config0 58 65 then config0 { inherit pkgs; } 59 66 else config0; 60 - 61 - # From a minimum of `system` or `config` (actually a target triple, *not* 62 - # nixpkgs configuration), infer the other one and platform as needed. 63 - localSystem = lib.systems.elaborate (if builtins.isAttrs args.localSystem then ( 64 - # Allow setting the platform in the config file. This take precedence over 65 - # the inferred platform, but not over an explicitly passed-in one. 66 - builtins.intersectAttrs { platform = null; } config1 67 - // args.localSystem) else args.localSystem); 68 - 69 - crossSystem = if crossSystem0 == null then localSystem 70 - else lib.systems.elaborate crossSystem0; 71 67 72 68 configEval = lib.evalModules { 73 69 modules = [
+14 -20
pkgs/top-level/impure.nix
··· 12 12 13 13 in 14 14 15 - { # We combine legacy `system` and `platform` into `localSystem`, if 16 - # `localSystem` was not passed. Strictly speaking, this is pure desugar, but 17 - # it is most convient to do so before the impure `localSystem.system` default, 18 - # so we do it now. 19 - localSystem ? builtins.intersectAttrs { system = null; platform = null; } args 15 + { # We put legacy `system` into `localSystem`, if `localSystem` was not passed. 16 + # If neither is passed, assume we are building packages on the current 17 + # (build, in GNU Autotools parlance) platform. 18 + localSystem ? { system = args.system or builtins.currentSystem; } 20 19 21 - , # These are needed only because nix's `--arg` command-line logic doesn't work 22 - # with unnamed parameters allowed by ... 23 - system ? localSystem.system 24 - , platform ? localSystem.platform 25 - , crossSystem ? null 20 + # These are needed only because nix's `--arg` command-line logic doesn't work 21 + # with unnamed parameters allowed by ... 22 + , system ? localSystem.system 23 + , crossSystem ? localSystem 26 24 27 25 , # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or 28 26 # $HOME/.config/nixpkgs/config.nix. ··· 77 75 , ... 78 76 } @ args: 79 77 80 - # If `localSystem` was explicitly passed, legacy `system` and `platform` should 81 - # not be passed. 82 - assert args ? localSystem -> !(args ? system || args ? platform); 78 + # If `localSystem` was explicitly passed, legacy `system` should 79 + # not be passed, and vice-versa. 80 + assert args ? localSystem -> !(args ? system); 81 + assert args ? system -> !(args ? localSystem); 83 82 84 - import ./. (builtins.removeAttrs args [ "system" "platform" ] // { 85 - inherit config overlays crossSystem crossOverlays; 86 - # Fallback: Assume we are building packages on the current (build, in GNU 87 - # Autotools parlance) system. 88 - localSystem = if builtins.isString localSystem then localSystem 89 - else (if args ? localSystem then {} 90 - else { system = builtins.currentSystem; }) // localSystem; 83 + import ./. (builtins.removeAttrs args [ "system" ] // { 84 + inherit config overlays localSystem; 91 85 })