summary refs log tree commit diff
path: root/lib/systems/parse.nix
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-10-31 08:35:51 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-11-04 16:49:28 -0400
commit66aa02f190d17b4e7c4bf0f7f891984647a38234 (patch)
treec18caf98baa04b8cb57a6287847eae1789a872a5 /lib/systems/parse.nix
parentf172d86a4e1bd84e6d2f4de3bceba36f58095484 (diff)
downloadnixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.tar
nixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.tar.gz
nixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.tar.bz2
nixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.tar.lz
nixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.tar.xz
nixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.tar.zst
nixpkgs-66aa02f190d17b4e7c4bf0f7f891984647a38234.zip
lib/systems: Support FreeBSD
A tricky thing about FreeBSD is that there is no stable ABI across
versions. That means that putting in the version as part of the config
string is paramount.

We have a parsed represenation that separates name versus version to
accomplish this. We include FreeBSD versions 12 and 13 to demonstrate
how it works.
Diffstat (limited to 'lib/systems/parse.nix')
-rw-r--r--lib/systems/parse.nix15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix
index ac450534fe1..d8ba251503a 100644
--- a/lib/systems/parse.nix
+++ b/lib/systems/parse.nix
@@ -290,7 +290,11 @@ rec {
     # the normalized name for macOS.
     macos    = { execFormat = macho;   families = { inherit darwin; }; name = "darwin"; };
     ios      = { execFormat = macho;   families = { inherit darwin; }; };
-    freebsd  = { execFormat = elf;     families = { inherit bsd; }; };
+    # A tricky thing about FreeBSD is that there is no stable ABI across
+    # versions. That means that putting in the version as part of the
+    # config string is paramount.
+    freebsd12 = { execFormat = elf;     families = { inherit bsd; }; name = "freebsd"; version = 12; };
+    freebsd13 = { execFormat = elf;     families = { inherit bsd; }; name = "freebsd"; version = 13; };
     linux    = { execFormat = elf;     families = { }; };
     netbsd   = { execFormat = elf;     families = { inherit bsd; }; };
     none     = { execFormat = unknown; families = { }; };
@@ -431,6 +435,8 @@ rec {
         then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = "redox";                      }
       else if (elemAt l 2 == "mmixware")
         then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = "mmixware";                   }
+      else if hasPrefix "freebsd" (elemAt l 2)
+        then { cpu = elemAt l 0; vendor = elemAt l 1;    kernel = elemAt l 2;                }
       else if hasPrefix "netbsd" (elemAt l 2)
         then { cpu = elemAt l 0; vendor = elemAt l 1;    kernel = elemAt l 2;                }
       else if (elem (elemAt l 2) ["eabi" "eabihf" "elf"])
@@ -485,10 +491,13 @@ rec {
 
   mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (lib.splitString "-" s));
 
+  kernelName = kernel:
+    kernel.name + toString (kernel.version or "");
+
   doubleFromSystem = { cpu, kernel, abi, ... }:
     /**/ if abi == abis.cygnus       then "${cpu.name}-cygwin"
     else if kernel.families ? darwin then "${cpu.name}-darwin"
-    else "${cpu.name}-${kernel.name}";
+    else "${cpu.name}-${kernelName kernel}";
 
   tripleFromSystem = { cpu, vendor, kernel, abi, ... } @ sys: assert isSystem sys; let
     optExecFormat =
@@ -496,7 +505,7 @@ rec {
                           gnuNetBSDDefaultExecFormat cpu != kernel.execFormat)
         kernel.execFormat.name;
     optAbi = lib.optionalString (abi != abis.unknown) "-${abi.name}";
-  in "${cpu.name}-${vendor.name}-${kernel.name}${optExecFormat}${optAbi}";
+  in "${cpu.name}-${vendor.name}-${kernelName kernel}${optExecFormat}${optAbi}";
 
   ################################################################################