8 , defaultNimVersion ? 2
16 enableParallelBuilding = true;
20 export NIX_NIM_BUILD_INPUTS=''${pkgsHostTarget[@]} $NIX_NIM_BUILD_INPUTS
21 nim_builder --phase:configure
26 nim_builder --phase:build
31 nim_builder --phase:check
36 nim_builder --phase:install
39 meta = { inherit (nim2.meta) maintainers platforms; };
45 fetchzip = { url, sha256, ... }:
46 buildPackages.fetchzip {
50 git = { fetchSubmodules, leaveDotGit, rev, sha256, url, ... }:
51 buildPackages.fetchgit {
52 inherit fetchSubmodules leaveDotGit rev sha256 url;
56 attrs@{ method, ... }:
57 let fod = methods.${method} attrs;
58 in ''--path:"${fod.outPath}/${attrs.srcDir}"'';
60 asFunc = x: if builtins.isFunction x then x else (_: x);
65 composition = finalAttrs:
68 // (asFunc ((asFunc buildNimPackageArgs) finalAttrs)) baseAttrs;
71 lib.attrsets.optionalAttrs (builtins.hasAttr "lockFile" postPkg)
72 (builtins.fromJSON (builtins.readFile postPkg.lockFile));
74 lockDepends = lockAttrs.depends or [ ];
76 lockFileNimFlags = map fodFromLockEntry lockDepends;
78 postNimOverrides = builtins.foldl' (
80 { packages, ... }@lockAttrs:
83 if (builtins.hasAttr name nimOverrides) then
84 (prevAttrs // (nimOverrides.${name} lockAttrs prevAttrs))
88 ) postPkg lockDepends;
91 { depsBuildBuild ? [ ]
92 , nativeBuildInputs ? [ ]
94 , requiredNimVersion ? defaultNimVersion
98 (if requiredNimVersion == 1 then {
99 depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
100 nativeBuildInputs = [ nim1 ] ++ nativeBuildInputs;
101 } else if requiredNimVersion == 2 then {
102 depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
103 nativeBuildInputs = [ nim2 ] ++ nativeBuildInputs;
106 "requiredNimVersion ${toString requiredNimVersion} is not valid") // {
107 nimFlags = lockFileNimFlags ++ nimFlags;
108 passthru = passthru // {
109 # allow overriding the result of buildNimPackageArgs before this composition is applied
110 # this allows overriding the lockFile for packages built using buildNimPackage
111 # this is adapted from mkDerivationExtensible in stdenv.mkDerivation
112 overrideNimAttrs = f0:
117 if builtins.isFunction x
123 let super = (asFunc ((asFunc buildNimPackageArgs) self)) baseAttrs;
125 super // (if builtins.isFunction f0 || f0?__functor then f self super else f0));
129 attrs = postNimOverrides // finalOverride postNimOverrides;
131 lib.trivial.warnIf (builtins.hasAttr "nimBinOnly" attrs)
132 "the nimBinOnly attribute is deprecated for buildNimPackage"
136 stdenv.mkDerivation composition