summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2009-11-19 17:19:39 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2009-11-19 17:19:39 +0000
commit56ed820f84101fc7b7cc47cbb1f57e616f35ac73 (patch)
tree03815ba25182ffc336e965ba28b147eb3389f877
parent6ba27ab5521e4439c082c868dcf692fea0e6f876 (diff)
downloadnixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.tar
nixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.tar.gz
nixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.tar.bz2
nixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.tar.lz
nixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.tar.xz
nixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.tar.zst
nixpkgs-56ed820f84101fc7b7cc47cbb1f57e616f35ac73.zip
Add systems.nix give more control over the increasing list of supported
systems.  This is not yet used because it has to be integrated with the
current system.

svn path=/nixpkgs/branches/stdenv-updates/; revision=18468
-rw-r--r--pkgs/lib/attrsets.nix10
-rw-r--r--pkgs/lib/default.nix4
-rw-r--r--pkgs/lib/systems.nix125
-rw-r--r--pkgs/lib/types.nix4
4 files changed, 142 insertions, 1 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix
index 63abf789944..4b2496c1987 100644
--- a/pkgs/lib/attrsets.nix
+++ b/pkgs/lib/attrsets.nix
@@ -2,9 +2,11 @@
 
 with {
   inherit (builtins) head tail isString;
+  inherit (import ./trivial.nix) or;
   inherit (import ./default.nix) fold;
   inherit (import ./strings.nix) concatStringsSep;
   inherit (import ./lists.nix) concatMap;
+  inherit (import ./misc.nix) eqStrict;
 };
 
 rec {
@@ -259,4 +261,12 @@ rec {
       !(isAttrs lhs && isAttrs rhs)
     ) lhs rhs;
 
+  matchAttrs = pattern: attrs:
+    fold or false (attrValues (zipAttrsWithNames (attrNames pattern) (n: values:
+      let pat = head values; val = head (tail values); in
+      if tail values == [] then false
+      else if isAttrs pat then isAttrs val && matchAttrs head values
+      else eqStrict pat val
+    ) [pattern attrs]));
+
 }
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix
index 2f916d3ddd7..86c45fe8334 100644
--- a/pkgs/lib/default.nix
+++ b/pkgs/lib/default.nix
@@ -15,12 +15,14 @@ let
   misc = import ./misc.nix;
   maintainers = import ./maintainers.nix;
   platforms = import ./platforms.nix;
+  systems = import ./systems.nix;
 
 in
   { inherit trivial lists strings stringsWithDeps attrsets sources options
-      properties modules types meta debug maintainers platforms;
+      properties modules types meta debug maintainers platforms systems;
   }
   # !!! don't include everything at top-level; perhaps only the most
   # commonly used functions.
   // trivial // lists // strings // stringsWithDeps // attrsets // sources
   // properties // options // types // meta // debug // misc // modules
+  // systems
diff --git a/pkgs/lib/systems.nix b/pkgs/lib/systems.nix
new file mode 100644
index 00000000000..41fdaacde44
--- /dev/null
+++ b/pkgs/lib/systems.nix
@@ -0,0 +1,125 @@
+# Define the list of system with their properties.  Only systems tested for
+# Nixpkgs are listed below
+
+with import ./lists.nix;
+with import ./types.nix;
+with import ./attrsets.nix;
+
+let
+  lib = import ./default.nix;
+  setTypes = type:
+    mapAttrs (name: value:
+      setType type ({inherit name;} // value)
+    );
+in
+
+rec {
+
+  isSignificantByte = x: typeOf x == "significant-byte";
+  significantBytes = setTypes "significant-byte" {
+    bigEndian = {};
+    littleEndian = {};
+  };
+
+
+  isCpuType = x: typeOf x == "cpu-type"
+    && elem x.bits [8 16 32 64 128]
+    && (builtins.lessThan 8 x.bits -> isSignificantByte x.significantByte);
+
+  cpuTypes = with significantBytes;
+    setTypes "cpu-type" {
+      arm =      { bits = 32; significantByte = littleEndian; };
+      armv5tel = { bits = 32; significantByte = littleEndian; };
+      i686 =     { bits = 32; significantByte = littleEndian; };
+      powerpc =  { bits = 32; significantByte = bigEndian; };
+      x86_64 =   { bits = 64; significantByte = littleEndian; };
+    };
+
+
+  isExecFormat = x: typeOf x == "exec-format";
+  execFormats = setTypes "exec-format" {
+    aout = {}; # a.out
+    elf = {};
+    macho = {};
+    pe = {};
+    unknow = {};
+  };
+
+
+  isKernel = x: typeOf x == "kernel";
+  kernels = with execFormats;
+    setTypes "kernel" {
+      cygwin =  { execFormat = pe; };
+      darwin =  { execFormat = macho; };
+      freebsd = { execFormat = elf; };
+      linux =   { execFormat = elf; };
+      netbsd =  { execFormat = elf; };
+      none =    { execFormat = unknow; };
+      openbsd = { execFormat = elf; };
+      win32 =   { execFormat = pe; };
+    };
+
+
+  isArchitecture = x: typeOf x == "architecture";
+  architectures = setTypes "architecture" {
+    apple = {};
+    pc = {};
+    unknow = {};
+  };
+
+
+  isSystem = x: typeOf x == "system"
+    && isCpuType x.cpu
+    && isArchitecture x.arch
+    && isKernel x.kernel;
+
+  mkSystem = {
+    cpu ? cpuTypes.i686,
+    arch ? architectures.pc,
+    kernel ? kernels.linux,
+    name ? "${cpu.name}-${arch.name}-${kernel.name}"
+  }: setType "system" {
+    inherit name cpu arch kernel;
+  };
+
+
+  isDarwin = matchAttrs { kernel = kernels.darwin; };
+  isLinux = matchAttrs { kernel = kernels.linux; };
+  isi686 = matchAttrs { cpu = cpuTypes.i686; };
+  is64Bit = matchAttrs { cpu = { bits = 64; }; };
+
+
+  # This should revert the job done by config.guess from the gcc compiler.
+  mkSystemFromString = s: let
+    l = lib.splitString "-" s;
+
+    getCpu = name:
+      attrByPath [name] (throw "Unknow cpuType `${name}'.")
+        cpuTypes;
+    getArch = name:
+      attrByPath [name] (throw "Unknow architecture `${name}'.")
+        architectures;
+    getKernel = name:
+      attrByPath [name] (throw "Unknow kernel `${name}'.")
+        kernels;
+
+    system =
+      if builtins.length l == 2 then
+        mkSystem rec {
+          name = s;
+          cpu = getCpu (head l);
+          arch =
+            if isDarwin system
+            then architectures.apple
+            else architectures.pc;
+          kernel = getKernel (head (tail l));
+        }
+      else
+        mkSystem {
+          name = s;
+          cpu = getCpu (head l);
+          arch = getArch (head (tail l));
+          kernel = getKernel (head (tail (tail l)));
+        };
+  in assert isSystem system; system;
+}
diff --git a/pkgs/lib/types.nix b/pkgs/lib/types.nix
index d71cb9df097..fd3c071c0be 100644
--- a/pkgs/lib/types.nix
+++ b/pkgs/lib/types.nix
@@ -12,6 +12,10 @@ rec {
   hasType = x: isAttrs x && x ? _type;
   typeOf = x: if hasType x then x._type else "";
 
+  setType = typeName: value: value // {
+    _type = typeName;
+  };
+
   
   # name (name of the type)
   # check (boolean function)