Skip to content

Commit a5974a5

Browse files
authored
nim: deprecate and move os and cpu to stdenv.targetPlatform.nim (#513302)
2 parents 092c727 + a8f0a99 commit a5974a5

3 files changed

Lines changed: 66 additions & 78 deletions

File tree

lib/systems/default.nix

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,64 @@ let
621621
else
622622
null;
623623
};
624+
625+
nim = {
626+
# See these locations for a known list of cpu/os idntifeiers:
627+
# - https://nim-lang.org/docs/system.html#hostCPU
628+
# - https://nim-lang.org/docs/system.html#hostOS
629+
cpu =
630+
if final.isAarch32 then
631+
"arm"
632+
else if final.isAarch64 then
633+
"arm64"
634+
else if final.isAlpha then
635+
"alpha"
636+
else if final.isAvr then
637+
"avr"
638+
else if final.isMips && final.is32Bit then
639+
"mips"
640+
else if final.isMips && final.is64Bit then
641+
"mips64"
642+
else if final.isMsp430 then
643+
"msp430"
644+
else if final.isPower && final.is32bit then
645+
"powerpc"
646+
else if final.isPower && final.is64bit then
647+
"powerpc64"
648+
else if final.isRiscV && final.is64bit then
649+
"riscv64"
650+
else if final.isSparc then
651+
"sparc"
652+
else if final.isx86_32 then
653+
"i386"
654+
else if final.isx86_64 then
655+
"amd64"
656+
else
657+
null;
658+
os =
659+
if final.isAndroid then
660+
"Android"
661+
else if final.isDarwin then
662+
"MacOSX"
663+
else if final.isFreeBSD then
664+
"FreeBSD"
665+
else if final.isGenode then
666+
"Genode"
667+
else if final.isLinux then
668+
"Linux"
669+
else if final.isNetBSD then
670+
"NetBSD"
671+
else if final.isNone then
672+
"Standalone"
673+
else if final.isOpenBSD then
674+
"OpenBSD"
675+
else if final.isWindows then
676+
"Windows"
677+
else if final.isiOS then
678+
"iOS"
679+
else
680+
null;
681+
};
624682
};
625683
in
626684
assert final.useAndroidPrebuilt -> final.isAndroid;

pkgs/by-name/ni/nim-2_2/package.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ let
4848
runHook preBuild
4949
cat >> config/config.nims << WTF
5050
51-
switch("os", "${nimUnwrapped.passthru.nimTarget.os}")
52-
switch("cpu", "${nimUnwrapped.passthru.nimTarget.cpu}")
51+
switch("os", "${stdenv.targetPlatform.nim.os}")
52+
switch("cpu", "${stdenv.targetPlatform.nim.cpu}")
5353
switch("define", "nixbuild")
5454
5555
# Configure the compiler using the $CC set by Nix at build time
@@ -63,8 +63,8 @@ let
6363
6464
mv config/nim.cfg config/nim.cfg.old
6565
cat > config/nim.cfg << WTF
66-
os = "${nimUnwrapped.passthru.nimTarget.os}"
67-
cpu = "${nimUnwrapped.passthru.nimTarget.cpu}"
66+
os = "${stdenv.targetPlatform.nim.os}"
67+
cpu = "${stdenv.targetPlatform.nim.cpu}"
6868
define:"nixbuild"
6969
WTF
7070

pkgs/by-name/ni/nim-unwrapped-2_2/package.nix

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,6 @@
1111
sqlite,
1212
darwin,
1313
}:
14-
15-
let
16-
parseCpu =
17-
platform:
18-
with platform;
19-
# Derive a Nim CPU identifier
20-
if isAarch32 then
21-
"arm"
22-
else if isAarch64 then
23-
"arm64"
24-
else if isAlpha then
25-
"alpha"
26-
else if isAvr then
27-
"avr"
28-
else if isMips && is32bit then
29-
"mips"
30-
else if isMips && is64bit then
31-
"mips64"
32-
else if isMsp430 then
33-
"msp430"
34-
else if isPower && is32bit then
35-
"powerpc"
36-
else if isPower && is64bit then
37-
"powerpc64"
38-
else if isRiscV && is64bit then
39-
"riscv64"
40-
else if isSparc then
41-
"sparc"
42-
else if isx86_32 then
43-
"i386"
44-
else if isx86_64 then
45-
"amd64"
46-
else
47-
throw "no Nim CPU support known for ${config}";
48-
49-
parseOs =
50-
platform:
51-
with platform;
52-
# Derive a Nim OS identifier
53-
if isAndroid then
54-
"Android"
55-
else if isDarwin then
56-
"MacOSX"
57-
else if isFreeBSD then
58-
"FreeBSD"
59-
else if isGenode then
60-
"Genode"
61-
else if isLinux then
62-
"Linux"
63-
else if isNetBSD then
64-
"NetBSD"
65-
else if isNone then
66-
"Standalone"
67-
else if isOpenBSD then
68-
"OpenBSD"
69-
else if isWindows then
70-
"Windows"
71-
else if isiOS then
72-
"iOS"
73-
else
74-
throw "no Nim OS support known for ${config}";
75-
76-
parsePlatform = p: {
77-
cpu = parseCpu p;
78-
os = parseOs p;
79-
};
80-
81-
nimHost = parsePlatform stdenv.hostPlatform;
82-
nimTarget = parsePlatform stdenv.targetPlatform;
83-
in
84-
8514
stdenv.mkDerivation (finalAttrs: {
8615
pname = "nim-unwrapped";
8716
version = "2.2.4";
@@ -135,8 +64,8 @@ stdenv.mkDerivation (finalAttrs: {
13564
'';
13665

13766
kochArgs = [
138-
"--cpu:${nimHost.cpu}"
139-
"--os:${nimHost.os}"
67+
"--cpu:${stdenv.hostPlatform.nim.cpu}"
68+
"--os:${stdenv.hostPlatform.nim.os}"
14069
"-d:release"
14170
"-d:useGnuReadline"
14271
]
@@ -168,7 +97,8 @@ stdenv.mkDerivation (finalAttrs: {
16897
'';
16998

17099
passthru = {
171-
inherit nimHost nimTarget;
100+
nimHost = lib.warn "nimHost is deprecated, please use stdenv.hostPlatform.nim.os instead." stdenv.hostPlatform.nim.os;
101+
nimTarget = lib.warn "nimTarget is deprecated, please use stdenv.hostPlatform.nim.cpu instead." stdenv.hostPlatform.cpu;
172102
};
173103

174104
meta = {

0 commit comments

Comments
 (0)