about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2017-03-23 20:49:28 -0400
committerJohn Ericson <Ericson2314@Yahoo.com>2017-04-17 17:13:01 -0400
commit3efc661a1de6a2ce9b98aa39283e68914297b8d7 (patch)
treecc7467715da0a521a692c13b825cf8cc67fa2d98 /lib
parentd86caa3216dce17f54c1505a751cf5b403fd8bcf (diff)
downloadnixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.tar
nixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.tar.gz
nixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.tar.bz2
nixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.tar.lz
nixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.tar.xz
nixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.tar.zst
nixlib-3efc661a1de6a2ce9b98aa39283e68914297b8d7.zip
Elaborate `localSystem` and `crossSystem` in a consistent manner
Diffstat (limited to 'lib')
-rw-r--r--lib/systems/default.nix18
-rw-r--r--lib/systems/platforms.nix2
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/systems/default.nix b/lib/systems/default.nix
index 70d431837daa..d956969a18f9 100644
--- a/lib/systems/default.nix
+++ b/lib/systems/default.nix
@@ -2,4 +2,22 @@ rec {
   doubles = import ./doubles.nix;
   parse = import ./parse.nix;
   platforms = import ./platforms.nix;
+
+  # Elaborate a `localSystem` or `crossSystem` so that it contains everything
+  # necessary.
+  #
+  # `parsed` is inferred from args, both because there are two options with one
+  # clearly prefered, and to prevent cycles. A simpler fixed point where the RHS
+  # always just used `final.*` would fail on both counts.
+  elaborate = args: let
+    final = {
+      # Prefer to parse `config` as it is strictly more informative.
+      parsed = parse.mkSystemFromString (if args ? config then args.config else args.system);
+      # Either of these can be losslessly-extracted from `parsed` iff parsing succeeds.
+      system = parse.doubleFromSystem final.parsed;
+      config = parse.tripleFromSystem final.parsed;
+      # Just a guess, based on `system`
+      platform = platforms.selectBySystem final.system;
+    } // args;
+  in final;
 }
diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix
index 665950766f7e..4322c8e2ff68 100644
--- a/lib/systems/platforms.nix
+++ b/lib/systems/platforms.nix
@@ -474,7 +474,7 @@ rec {
     };
   };
 
-  selectPlatformBySystem = system: {
+  selectBySystem = system: {
       "i686-linux" = pc32;
       "x86_64-linux" = pc64;
       "armv5tel-linux" = sheevaplug;