1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
{ lib
, buildPackages
, callPackage
, stdenv
, nim1
, nim2
, nim_builder
, defaultNimVersion ? 2
, nimOverrides
}:
let
baseAttrs = {
strictDeps = true;
enableParallelBuilding = true;
doCheck = true;
configurePhase = ''
runHook preConfigure
export NIX_NIM_BUILD_INPUTS=''${pkgsHostTarget[@]} $NIX_NIM_BUILD_INPUTS
nim_builder --phase:configure
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
nim_builder --phase:build
runHook postBuild
'';
checkPhase = ''
runHook preCheck
nim_builder --phase:check
runHook postCheck
'';
installPhase = ''
runHook preInstall
nim_builder --phase:install
runHook postInstall
'';
meta = { inherit (nim2.meta) maintainers platforms; };
};
fodFromLockEntry =
let
methods = {
fetchzip = { url, sha256, ... }:
buildPackages.fetchzip {
name = "source";
inherit url sha256;
};
git = { fetchSubmodules, leaveDotGit, rev, sha256, url, ... }:
buildPackages.fetchgit {
inherit fetchSubmodules leaveDotGit rev sha256 url;
};
};
in
attrs@{ method, ... }:
let fod = methods.${method} attrs;
in ''--path:"${fod.outPath}/${attrs.srcDir}"'';
callAnnotations = { packages, ... }@lockAttrs:
map (packageName: nimOverrides.${packageName} or (_: [ ]) lockAttrs)
packages;
asFunc = x: if builtins.isFunction x then x else (_: x);
in
buildNimPackageArgs:
let
composition = finalAttrs:
let
postPkg = baseAttrs
// (asFunc ((asFunc buildNimPackageArgs) finalAttrs)) baseAttrs;
lockAttrs =
lib.attrsets.optionalAttrs (builtins.hasAttr "lockFile" postPkg)
(builtins.fromJSON (builtins.readFile postPkg.lockFile));
lockDepends = lockAttrs.depends or [ ];
lockFileNimFlags = map fodFromLockEntry lockDepends;
annotationOverlays = lib.lists.flatten (map callAnnotations lockDepends);
postLock = builtins.foldl'
(prevAttrs: overlay: prevAttrs // (overlay finalAttrs prevAttrs))
postPkg
annotationOverlays;
finalOverride =
{ depsBuildBuild ? [ ]
, nativeBuildInputs ? [ ]
, nimFlags ? [ ]
, requiredNimVersion ? defaultNimVersion
, ...
}:
(if requiredNimVersion == 1 then {
depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
nativeBuildInputs = [ nim1 ] ++ nativeBuildInputs;
} else if requiredNimVersion == 2 then {
depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
nativeBuildInputs = [ nim2 ] ++ nativeBuildInputs;
} else
throw
"requiredNimVersion ${toString requiredNimVersion} is not valid") // {
nimFlags = lockFileNimFlags ++ nimFlags;
};
attrs = postLock // finalOverride postLock;
in
lib.trivial.warnIf (builtins.hasAttr "nimBinOnly" attrs)
"the nimBinOnly attribute is deprecated for buildNimPackage"
attrs;
in
stdenv.mkDerivation composition
|