From 2dde58903e0f2f490088c3b0cedadc9b479da085 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 22 Jan 2021 16:36:06 -0500 Subject: [PATCH] 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! --- pkgs/top-level/default.nix | 24 ++++++++++-------------- pkgs/top-level/impure.nix | 34 ++++++++++++++-------------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index dfa68ba31b8..10cf36d4d13 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -1,9 +1,8 @@ /* This function composes the Nix Packages collection. It: - 1. Applies the final stage to the given `config` if it is a function + 1. Elaborates `localSystem` and `crossSystem` with defaults as needed. - 2. Infers an appropriate `platform` based on the `system` if none is - provided + 2. Applies the final stage to the given `config` if it is a function 3. Defaults to no non-standard config and no cross-compilation target @@ -50,6 +49,14 @@ let # Rename the function arguments in let lib = import ../../lib; + localSystem = lib.systems.elaborate args.localSystem; + + # Condition preserves sharing which in turn affects equality. + crossSystem = + if crossSystem0 == null || crossSystem0 == args.localSystem + then localSystem + else lib.systems.elaborate crossSystem0; + # Allow both: # { /* the config */ } and # { pkgs, ... } : { /* the config */ } @@ -58,17 +65,6 @@ in let then config0 { inherit pkgs; } else config0; - # From a minimum of `system` or `config` (actually a target triple, *not* - # nixpkgs configuration), infer the other one and platform as needed. - localSystem = lib.systems.elaborate (if builtins.isAttrs args.localSystem then ( - # Allow setting the platform in the config file. This take precedence over - # the inferred platform, but not over an explicitly passed-in one. - builtins.intersectAttrs { platform = null; } config1 - // args.localSystem) else args.localSystem); - - crossSystem = if crossSystem0 == null then localSystem - else lib.systems.elaborate crossSystem0; - configEval = lib.evalModules { modules = [ ./config.nix diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix index 3ba6c08a140..6f7383c8e7a 100644 --- a/pkgs/top-level/impure.nix +++ b/pkgs/top-level/impure.nix @@ -12,17 +12,15 @@ let in -{ # We combine legacy `system` and `platform` into `localSystem`, if - # `localSystem` was not passed. Strictly speaking, this is pure desugar, but - # it is most convient to do so before the impure `localSystem.system` default, - # so we do it now. - localSystem ? builtins.intersectAttrs { system = null; platform = null; } args +{ # We put legacy `system` into `localSystem`, if `localSystem` was not passed. + # If neither is passed, assume we are building packages on the current + # (build, in GNU Autotools parlance) platform. + localSystem ? { system = args.system or builtins.currentSystem; } -, # These are needed only because nix's `--arg` command-line logic doesn't work - # with unnamed parameters allowed by ... - system ? localSystem.system -, platform ? localSystem.platform -, crossSystem ? null +# These are needed only because nix's `--arg` command-line logic doesn't work +# with unnamed parameters allowed by ... +, system ? localSystem.system +, crossSystem ? localSystem , # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or # $HOME/.config/nixpkgs/config.nix. @@ -77,15 +75,11 @@ in , ... } @ args: -# If `localSystem` was explicitly passed, legacy `system` and `platform` should -# not be passed. -assert args ? localSystem -> !(args ? system || args ? platform); +# If `localSystem` was explicitly passed, legacy `system` should +# not be passed, and vice-versa. +assert args ? localSystem -> !(args ? system); +assert args ? system -> !(args ? localSystem); -import ./. (builtins.removeAttrs args [ "system" "platform" ] // { - inherit config overlays crossSystem crossOverlays; - # Fallback: Assume we are building packages on the current (build, in GNU - # Autotools parlance) system. - localSystem = if builtins.isString localSystem then localSystem - else (if args ? localSystem then {} - else { system = builtins.currentSystem; }) // localSystem; +import ./. (builtins.removeAttrs args [ "system" ] // { + inherit config overlays localSystem; })