2023-10-30 22:17:59 +00:00
|
|
|
{ lib
|
|
|
|
, buildPackages
|
|
|
|
, callPackage
|
|
|
|
, stdenv
|
|
|
|
, nim1
|
|
|
|
, nim2
|
|
|
|
, nim_builder
|
|
|
|
, defaultNimVersion ? 2
|
|
|
|
, nimOverrides
|
2023-12-06 08:44:17 +00:00
|
|
|
, buildNimPackage
|
2023-10-30 22:17:59 +00:00
|
|
|
}:
|
2021-09-02 17:03:01 +00:00
|
|
|
|
2023-06-14 09:43:26 +00:00
|
|
|
let
|
|
|
|
baseAttrs = {
|
|
|
|
strictDeps = true;
|
|
|
|
enableParallelBuilding = true;
|
2023-06-14 11:11:20 +00:00
|
|
|
doCheck = true;
|
2023-06-14 09:43:26 +00:00
|
|
|
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
|
|
|
|
'';
|
2023-11-20 08:12:30 +00:00
|
|
|
meta = { inherit (nim2.meta) maintainers platforms; };
|
2023-06-14 09:43:26 +00:00
|
|
|
};
|
2021-09-02 17:03:01 +00:00
|
|
|
|
2023-10-30 22:17:59 +00:00
|
|
|
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}"'';
|
|
|
|
|
|
|
|
asFunc = x: if builtins.isFunction x then x else (_: x);
|
2021-09-02 17:03:01 +00:00
|
|
|
|
2023-10-30 22:17:59 +00:00
|
|
|
in
|
|
|
|
buildNimPackageArgs:
|
|
|
|
let
|
2023-06-14 09:43:26 +00:00
|
|
|
composition = finalAttrs:
|
|
|
|
let
|
2023-10-30 22:17:59 +00:00
|
|
|
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;
|
|
|
|
|
2024-05-30 06:21:09 +00:00
|
|
|
postNimOverrides = builtins.foldl' (
|
|
|
|
prevAttrs:
|
|
|
|
{ packages, ... }@lockAttrs:
|
|
|
|
builtins.foldl' (
|
|
|
|
prevAttrs: name:
|
|
|
|
if (builtins.hasAttr name nimOverrides) then
|
|
|
|
(prevAttrs // (nimOverrides.${name} lockAttrs prevAttrs))
|
|
|
|
else
|
|
|
|
prevAttrs
|
|
|
|
) prevAttrs packages
|
|
|
|
) postPkg lockDepends;
|
2023-10-30 22:17:59 +00:00
|
|
|
|
|
|
|
finalOverride =
|
|
|
|
{ depsBuildBuild ? [ ]
|
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, nimFlags ? [ ]
|
|
|
|
, requiredNimVersion ? defaultNimVersion
|
2023-12-06 08:44:17 +00:00
|
|
|
, passthru ? { }
|
2023-10-30 22:17:59 +00:00
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
(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;
|
2023-12-06 08:44:17 +00:00
|
|
|
passthru = passthru // {
|
|
|
|
# allow overriding the result of buildNimPackageArgs before this composition is applied
|
|
|
|
# this allows overriding the lockFile for packages built using buildNimPackage
|
|
|
|
# this is adapted from mkDerivationExtensible in stdenv.mkDerivation
|
|
|
|
overrideNimAttrs = f0:
|
|
|
|
let
|
|
|
|
f = self: super:
|
|
|
|
let x = f0 super;
|
|
|
|
in
|
|
|
|
if builtins.isFunction x
|
|
|
|
then f0 self super
|
|
|
|
else x;
|
|
|
|
in
|
|
|
|
buildNimPackage
|
|
|
|
(self:
|
|
|
|
let super = (asFunc ((asFunc buildNimPackageArgs) self)) baseAttrs;
|
|
|
|
in
|
|
|
|
super // (if builtins.isFunction f0 || f0?__functor then f self super else f0));
|
|
|
|
};
|
2023-10-30 22:17:59 +00:00
|
|
|
};
|
|
|
|
|
2024-05-30 06:21:09 +00:00
|
|
|
attrs = postNimOverrides // finalOverride postNimOverrides;
|
2023-10-30 22:17:59 +00:00
|
|
|
in
|
|
|
|
lib.trivial.warnIf (builtins.hasAttr "nimBinOnly" attrs)
|
|
|
|
"the nimBinOnly attribute is deprecated for buildNimPackage"
|
|
|
|
attrs;
|
2021-09-02 17:03:01 +00:00
|
|
|
|
2023-10-30 22:17:59 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation composition
|