From 40e7be11c8098d11217786d106462e958e1d8718 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Nov 2020 20:55:55 +0000 Subject: [PATCH] lib.systems.platforms: Make selection more flexible We dont have to match on exact strings if we get accessed to `parsed`. Co-authored-by: Matthew Bauer --- lib/systems/default.nix | 2 +- lib/systems/platforms.nix | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 9939743157e78..f6832945a23dc 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -25,7 +25,7 @@ rec { system = parse.doubleFromSystem final.parsed; config = parse.tripleFromSystem final.parsed; # Just a guess, based on `system` - platform = platforms.selectBySystem final.system; + platform = platforms.select final; # Determine whether we are compatible with the provided CPU isCompatible = platform: parse.isCompatible final.parsed.cpu platform.parsed.cpu; # Derived meta-data diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index 42d9809fd7d0c..a01f167a02b6a 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -469,17 +469,22 @@ rec { ''; }; - selectBySystem = system: { - i486-linux = pc32; - i586-linux = pc32; - i686-linux = pc32; - x86_64-linux = pc64; - armv5tel-linux = sheevaplug; - armv6l-linux = raspberrypi; - armv7a-linux = armv7l-hf-multiplatform; - armv7l-linux = armv7l-hf-multiplatform; - aarch64-linux = aarch64-multiplatform; - mipsel-linux = fuloong2f_n32; - powerpc64le-linux = powernv; - }.${system} or pcBase; + select = platform: + # x86 + /**/ if platform.isx86_32 then pc32 + else if platform.isx86_64 then pc64 + + # ARM + else if platform.isAarch32 then let + version = platform.parsed.cpu.version or ""; + in if lib.versionOlder version "6" then sheevaplug + else if lib.versionOlder version "7" then raspberrypi + else armv7l-hf-multiplatform + else if platform.isAarch64 then aarch64-multiplatform + + else if platform.parsed.cpu == lib.systems.parse.cpuTypes.mipsel then fuloong2f_n32 + + else if platform.parsed.cpu == lib.systems.parse.cpuTypes.powerpc64le then powernv + + else pcBase; }