2023-10-30 22:17:59 +00:00
|
|
|
{ lib
|
|
|
|
, buildPackages
|
|
|
|
, callPackage
|
|
|
|
, stdenv
|
|
|
|
, nim1
|
|
|
|
, nim2
|
|
|
|
, nim_builder
|
|
|
|
, defaultNimVersion ? 2
|
|
|
|
, nimOverrides
|
|
|
|
}:
|
2021-09-02 18:03:01 +01:00
|
|
|
|
2023-06-14 10:43:26 +01:00
|
|
|
let
|
|
|
|
baseAttrs = {
|
|
|
|
strictDeps = true;
|
|
|
|
enableParallelBuilding = true;
|
2023-06-14 12:11:20 +01:00
|
|
|
doCheck = true;
|
2023-06-14 10:43:26 +01: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 10:43:26 +01:00
|
|
|
};
|
2021-09-02 18:03:01 +01: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}"'';
|
|
|
|
|
|
|
|
callAnnotations = { packages, ... }@lockAttrs:
|
|
|
|
map (packageName: nimOverrides.${packageName} or (_: [ ]) lockAttrs)
|
|
|
|
packages;
|
|
|
|
|
|
|
|
asFunc = x: if builtins.isFunction x then x else (_: x);
|
2021-09-02 18:03:01 +01:00
|
|
|
|
2023-10-30 22:17:59 +00:00
|
|
|
in
|
|
|
|
buildNimPackageArgs:
|
|
|
|
let
|
2023-06-14 10:43:26 +01: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;
|
|
|
|
|
|
|
|
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;
|
2021-09-02 18:03:01 +01:00
|
|
|
|
2023-10-30 22:17:59 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation composition
|