From a8f0a992121d70d669f8134fca52f45aeae869c0 Mon Sep 17 00:00:00 2001 From: eveeifyeve <88671402+Eveeifyeve@users.noreply.github.com> Date: Wed, 6 May 2026 07:50:13 +1000 Subject: [PATCH] nim: deprecate and move os and cpu to stdenv.targetPlatform.nim This change makes it more accesssable to using nim cpu and os without referencing nim. --- lib/systems/default.nix | 58 ++++++++++++++ pkgs/by-name/ni/nim-2_2/package.nix | 8 +- pkgs/by-name/ni/nim-unwrapped-2_2/package.nix | 78 +------------------ 3 files changed, 66 insertions(+), 78 deletions(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index fd4ed9777b52..e481b8a8fc28 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -621,6 +621,64 @@ let else null; }; + + nim = { + # See these locations for a known list of cpu/os idntifeiers: + # - https://nim-lang.org/docs/system.html#hostCPU + # - https://nim-lang.org/docs/system.html#hostOS + cpu = + if final.isAarch32 then + "arm" + else if final.isAarch64 then + "arm64" + else if final.isAlpha then + "alpha" + else if final.isAvr then + "avr" + else if final.isMips && final.is32Bit then + "mips" + else if final.isMips && final.is64Bit then + "mips64" + else if final.isMsp430 then + "msp430" + else if final.isPower && final.is32bit then + "powerpc" + else if final.isPower && final.is64bit then + "powerpc64" + else if final.isRiscV && final.is64bit then + "riscv64" + else if final.isSparc then + "sparc" + else if final.isx86_32 then + "i386" + else if final.isx86_64 then + "amd64" + else + null; + os = + if final.isAndroid then + "Android" + else if final.isDarwin then + "MacOSX" + else if final.isFreeBSD then + "FreeBSD" + else if final.isGenode then + "Genode" + else if final.isLinux then + "Linux" + else if final.isNetBSD then + "NetBSD" + else if final.isNone then + "Standalone" + else if final.isOpenBSD then + "OpenBSD" + else if final.isWindows then + "Windows" + else if final.isiOS then + "iOS" + else + null; + }; }; in assert final.useAndroidPrebuilt -> final.isAndroid; diff --git a/pkgs/by-name/ni/nim-2_2/package.nix b/pkgs/by-name/ni/nim-2_2/package.nix index 322d3711f903..350d235887b9 100644 --- a/pkgs/by-name/ni/nim-2_2/package.nix +++ b/pkgs/by-name/ni/nim-2_2/package.nix @@ -48,8 +48,8 @@ let runHook preBuild cat >> config/config.nims << WTF - switch("os", "${nimUnwrapped.passthru.nimTarget.os}") - switch("cpu", "${nimUnwrapped.passthru.nimTarget.cpu}") + switch("os", "${stdenv.targetPlatform.nim.os}") + switch("cpu", "${stdenv.targetPlatform.nim.cpu}") switch("define", "nixbuild") # Configure the compiler using the $CC set by Nix at build time @@ -63,8 +63,8 @@ let mv config/nim.cfg config/nim.cfg.old cat > config/nim.cfg << WTF - os = "${nimUnwrapped.passthru.nimTarget.os}" - cpu = "${nimUnwrapped.passthru.nimTarget.cpu}" + os = "${stdenv.targetPlatform.nim.os}" + cpu = "${stdenv.targetPlatform.nim.cpu}" define:"nixbuild" WTF diff --git a/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix b/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix index 69a8926f5f7b..00b39f59eb0a 100644 --- a/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix +++ b/pkgs/by-name/ni/nim-unwrapped-2_2/package.nix @@ -11,77 +11,6 @@ sqlite, darwin, }: - -let - parseCpu = - platform: - with platform; - # Derive a Nim CPU identifier - if isAarch32 then - "arm" - else if isAarch64 then - "arm64" - else if isAlpha then - "alpha" - else if isAvr then - "avr" - else if isMips && is32bit then - "mips" - else if isMips && is64bit then - "mips64" - else if isMsp430 then - "msp430" - else if isPower && is32bit then - "powerpc" - else if isPower && is64bit then - "powerpc64" - else if isRiscV && is64bit then - "riscv64" - else if isSparc then - "sparc" - else if isx86_32 then - "i386" - else if isx86_64 then - "amd64" - else - throw "no Nim CPU support known for ${config}"; - - parseOs = - platform: - with platform; - # Derive a Nim OS identifier - if isAndroid then - "Android" - else if isDarwin then - "MacOSX" - else if isFreeBSD then - "FreeBSD" - else if isGenode then - "Genode" - else if isLinux then - "Linux" - else if isNetBSD then - "NetBSD" - else if isNone then - "Standalone" - else if isOpenBSD then - "OpenBSD" - else if isWindows then - "Windows" - else if isiOS then - "iOS" - else - throw "no Nim OS support known for ${config}"; - - parsePlatform = p: { - cpu = parseCpu p; - os = parseOs p; - }; - - nimHost = parsePlatform stdenv.hostPlatform; - nimTarget = parsePlatform stdenv.targetPlatform; -in - stdenv.mkDerivation (finalAttrs: { pname = "nim-unwrapped"; version = "2.2.4"; @@ -135,8 +64,8 @@ stdenv.mkDerivation (finalAttrs: { ''; kochArgs = [ - "--cpu:${nimHost.cpu}" - "--os:${nimHost.os}" + "--cpu:${stdenv.hostPlatform.nim.cpu}" + "--os:${stdenv.hostPlatform.nim.os}" "-d:release" "-d:useGnuReadline" ] @@ -168,7 +97,8 @@ stdenv.mkDerivation (finalAttrs: { ''; passthru = { - inherit nimHost nimTarget; + nimHost = lib.warn "nimHost is deprecated, please use stdenv.hostPlatform.nim.os instead." stdenv.hostPlatform.nim.os; + nimTarget = lib.warn "nimTarget is deprecated, please use stdenv.hostPlatform.nim.cpu instead." stdenv.hostPlatform.cpu; }; meta = {