summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2017-05-21 13:39:23 -0400
committerJohn Ericson <Ericson2314@Yahoo.com>2017-05-22 00:25:02 -0400
commit2e7ec6fb702be66389405d48693b322565b27c69 (patch)
tree8fe252b2e58b2c7640f6c76d67707e5dc0bd9926 /lib
parentda8b2f1412c77ef50c90587d4b0f3a66e11892d6 (diff)
downloadnixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.tar
nixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.tar.gz
nixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.tar.bz2
nixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.tar.lz
nixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.tar.xz
nixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.tar.zst
nixpkgs-2e7ec6fb702be66389405d48693b322565b27c69.zip
lib: Make platform predicates more ergonomic to use
`hostPlatform.isDarwin` instead of `lib.system.parse.isDarwin
hostPlatform.parsed`
Diffstat (limited to 'lib')
-rw-r--r--lib/systems/default.nix6
-rw-r--r--lib/systems/doubles.nix38
-rw-r--r--lib/systems/inspect.nix36
-rw-r--r--lib/systems/parse.nix26
4 files changed, 68 insertions, 38 deletions
diff --git a/lib/systems/default.nix b/lib/systems/default.nix
index d956969a18f..a61e4efc4ef 100644
--- a/lib/systems/default.nix
+++ b/lib/systems/default.nix
@@ -1,6 +1,9 @@
+let inherit (import ../attrsets.nix) mapAttrs; in
+
 rec {
   doubles = import ./doubles.nix;
   parse = import ./parse.nix;
+  inspect = import ./inspect.nix;
   platforms = import ./platforms.nix;
 
   # Elaborate a `localSystem` or `crossSystem` so that it contains everything
@@ -18,6 +21,7 @@ rec {
       config = parse.tripleFromSystem final.parsed;
       # Just a guess, based on `system`
       platform = platforms.selectBySystem final.system;
-    } // args;
+    } // mapAttrs (n: v: v final.parsed) inspect.predicates
+      // args;
   in final;
 }
diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix
index 9b17a51531a..0168eb42f2f 100644
--- a/lib/systems/doubles.nix
+++ b/lib/systems/doubles.nix
@@ -1,8 +1,9 @@
-let lists = import ../lists.nix; in
-let parse = import ./parse.nix; in
-let inherit (import ../attrsets.nix) matchAttrs; in
-
 let
+  lists = import ../lists.nix;
+  parse = import ./parse.nix;
+  inherit (import ./inspect.nix) predicates;
+  inherit (import ../attrsets.nix) matchAttrs;
+
   all = [
     "aarch64-linux"
     "armv5tel-linux" "armv6l-linux" "armv7l-linux"
@@ -25,20 +26,21 @@ in rec {
   allBut = platforms: lists.filter (x: !(builtins.elem x platforms)) all;
   none = [];
 
-  arm = filterDoubles (matchAttrs { cpu = { family = "arm"; bits = 32; }; });
-  i686 = filterDoubles parse.isi686;
-  mips = filterDoubles (matchAttrs { cpu = { family = "mips"; }; });
-  x86_64 = filterDoubles parse.isx86_64;
-
-  cygwin = filterDoubles parse.isCygwin;
-  darwin = filterDoubles parse.isDarwin;
-  freebsd = filterDoubles (matchAttrs { kernel = parse.kernels.freebsd; });
-  gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; }); # Should be better
-  illumos = filterDoubles (matchAttrs { kernel = parse.kernels.solaris; });
-  linux = filterDoubles parse.isLinux;
-  netbsd = filterDoubles (matchAttrs { kernel = parse.kernels.netbsd; });
-  openbsd = filterDoubles (matchAttrs { kernel = parse.kernels.openbsd; });
-  unix = filterDoubles parse.isUnix;
+  arm     = filterDoubles predicates.isArm32;
+  i686    = filterDoubles predicates.isi686;
+  mips    = filterDoubles predicates.isMips;
+  x86_64  = filterDoubles predicates.isx86_64;
+
+  cygwin  = filterDoubles predicates.isCygwin;
+  darwin  = filterDoubles predicates.isDarwin;
+  freebsd = filterDoubles predicates.isFreeBSD;
+  # Should be better, but MinGW is unclear, and HURD is bit-rotted.
+  gnu     = filterDoubles (matchAttrs { kernel = parse.kernels.linux;  abi = parse.abis.gnu; });
+  illumos = filterDoubles predicates.isSunOS;
+  linux   = filterDoubles predicates.isLinux;
+  netbsd  = filterDoubles predicates.isNetBSD;
+  openbsd = filterDoubles predicates.isOpenBSD;
+  unix    = filterDoubles predicates.isUnix;
 
   mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux"];
 }
diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix
new file mode 100644
index 00000000000..1dcb4af35e6
--- /dev/null
+++ b/lib/systems/inspect.nix
@@ -0,0 +1,36 @@
+with import ./parse.nix;
+with import ../attrsets.nix;
+
+rec {
+  patterns = {
+    "32bit"      = { cpu = { bits = 32; }; };
+    "64bit"      = { cpu = { bits = 64; }; };
+    i686         = { cpu = cpuTypes.i686; };
+    x86_64       = { cpu = cpuTypes.x86_64; };
+    Arm          = { cpu = { family = "arm"; }; };
+    Mips         = { cpu = { family = "mips"; }; };
+    BigEndian    = { cpu = { significantByte = significantBytes.bigEndian; }; };
+    LittleEndian = { cpu = { significantByte = significantBytes.littleEndian; }; };
+
+    Unix         = { kernel = { families = { inherit (kernelFamilies) unix; }; }; };
+    BSD          = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; };
+
+    Darwin       = { kernel = kernels.darwin; };
+    Linux        = { kernel = kernels.linux; };
+    SunOS        = { kernel = kernels.solaris; };
+    FreeBSD      = { kernel = kernels.freebsd; };
+    NetBSD       = { kernel = kernels.netbsd; };
+    OpenBSD      = { kernel = kernels.openbsd; };
+    Windows      = { kernel = kernels.windows; };
+    Cygwin       = { kernel = kernels.windows; abi = abis.cygnus; };
+    MinGW        = { kernel = kernels.windows; abi = abis.gnu; };
+
+    Arm32        = recursiveUpdate patterns.Arm patterns."32bit";
+    Arm64        = recursiveUpdate patterns.Arm patterns."64bit";
+
+  };
+
+  predicates = mapAttrs'
+    (name: value: nameValuePair ("is" + name) (matchAttrs value))
+    patterns;
+}
diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix
index b9758f44fc1..b94caeb5758 100644
--- a/lib/systems/parse.nix
+++ b/lib/systems/parse.nix
@@ -8,6 +8,7 @@
 with import ../lists.nix;
 with import ../types.nix;
 with import ../attrsets.nix;
+with (import ./inspect.nix).predicates;
 
 let
   lib = import ../default.nix;
@@ -109,19 +110,6 @@ rec {
       inherit cpu vendor kernel abi;
     };
 
-  is64Bit = matchAttrs { cpu = { bits = 64; }; };
-  is32Bit = matchAttrs { cpu = { bits = 32; }; };
-  isi686 = matchAttrs { cpu = cpuTypes.i686; };
-  isx86_64 = matchAttrs { cpu = cpuTypes.x86_64; };
-
-  isDarwin = matchAttrs { kernel = kernels.darwin; };
-  isLinux = matchAttrs { kernel = kernels.linux; };
-  isUnix = matchAttrs { kernel = { families = { inherit (kernelFamilies) unix; }; }; };
-  isWindows = matchAttrs { kernel = kernels.windows; };
-  isCygwin = matchAttrs { kernel = kernels.windows; abi = abis.cygnus; };
-  isMinGW = matchAttrs { kernel = kernels.windows; abi = abis.gnu; };
-
-
   mkSkeletonFromList = l: {
     "2" = # We only do 2-part hacks for things Nix already supports
       if elemAt l 1 == "cygwin"
@@ -153,22 +141,22 @@ rec {
     getKernel = name:  kernels.${name} or (throw "Unknown kernel: ${name}");
     getAbi    = name:     abis.${name} or (throw "Unknown ABI: ${name}");
 
-    system = rec {
+    parsed = rec {
       cpu = getCpu args.cpu;
       vendor =
         /**/ if args ? vendor    then getVendor args.vendor
-        else if isDarwin  system then vendors.apple
-        else if isWindows system then vendors.pc
+        else if isDarwin  parsed then vendors.apple
+        else if isWindows parsed then vendors.pc
         else                     vendors.unknown;
       kernel = getKernel args.kernel;
       abi =
         /**/ if args ? abi       then getAbi args.abi
-        else if isLinux   system then abis.gnu
-        else if isWindows system then abis.gnu
+        else if isLinux   parsed then abis.gnu
+        else if isWindows parsed then abis.gnu
         else                     abis.unknown;
     };
 
-  in mkSystem system;
+  in mkSystem parsed;
 
   mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (lib.splitString "-" s));