nimOverrides: do not pass final attrset to override funcs

The final attrset is not used by any of the overrides and presents
a infinite recursion hazard.

Performance of buildNimPackage is improved.
This commit is contained in:
Emery Hemingway 2024-05-30 09:21:09 +03:00
parent 9ff0a5bb34
commit 5b321ac6b3
3 changed files with 24 additions and 26 deletions

View File

@ -80,7 +80,6 @@ For example, to propagate a dependency on SDL2 for lockfiles that select the Nim
/* … */
sdl2 =
lockAttrs:
finalAttrs:
{ buildInputs ? [ ], ... }:
{
buildInputs = buildInputs ++ [ SDL2 ];
@ -89,9 +88,8 @@ For example, to propagate a dependency on SDL2 for lockfiles that select the Nim
}
```
The annotations in the `nim-overrides.nix` set are functions that take three arguments and return a new attrset to be overlayed on the package being built.
The annotations in the `nim-overrides.nix` set are functions that take two arguments and return a new attrset to be overlayed on the package being built.
- lockAttrs: the attrset for this library from within a lockfile. This can be used to implement library version constraints, such as marking libraries as broken or insecure.
- finalAttrs: the final attrset passed by `buildNimPackage` to `stdenv.mkDerivation`.
- prevAttrs: the attrset produced by initial arguments to `buildNimPackage` and any preceding lockfile overlays.
### Overriding an Nim library override {#nim-lock-overrides-overrides}

View File

@ -57,10 +57,6 @@ let
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
@ -79,12 +75,17 @@ let
lockFileNimFlags = map fodFromLockEntry lockDepends;
annotationOverlays = lib.lists.flatten (map callAnnotations lockDepends);
postLock = builtins.foldl'
(prevAttrs: overlay: prevAttrs // (overlay finalAttrs prevAttrs))
postPkg
annotationOverlays;
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;
finalOverride =
{ depsBuildBuild ? [ ]
@ -125,7 +126,7 @@ let
};
};
attrs = postLock // finalOverride postLock;
attrs = postNimOverrides // finalOverride postNimOverrides;
in
lib.trivial.warnIf (builtins.hasAttr "nimBinOnly" attrs)
"the nimBinOnly attribute is deprecated for buildNimPackage"

View File

@ -11,22 +11,21 @@
, xorg
}:
# The following is list of overrides that take three arguments each:
# The following is list of overrides that take two arguments each:
# - lockAttrs: - an attrset from a Nim lockfile, use this for making constraints on the locked library
# - finalAttrs: - final arguments to the depender package
# - prevAttrs: - preceding arguments to the depender package
{
jester = lockAttrs: finalAttrs:
jester = lockAttrs:
{ buildInputs ? [ ], ... }: {
buildInputs = buildInputs ++ [ openssl ];
};
hts = lockAttrs: finalAttrs:
hts = lockAttrs:
{ buildInputs ? [ ], ... }: {
buildInputs = buildInputs ++ [ htslib ];
};
getdns = lockAttrs: finalAttrs:
getdns = lockAttrs:
{ nativeBuildInputs ? [ ], buildInputs ? [ ], ... }: {
nativeBuildInputs = nativeBuildInputs ++ [ pkg-config ];
buildInputs = buildInputs ++ [ getdns ];
@ -38,35 +37,35 @@
"the selected version of the hashlib Nim library is hardware specific"
# https://github.com/khchen/hashlib/pull/4
# remove when fixed upstream
(_: _: { });
(_: { });
nimraylib_now = lockAttrs: finalAttrs:
nimraylib_now = lockAttrs:
{ buildInputs ? [ ], ... }: {
buildInputs = buildInputs ++ [ raylib ];
};
sass = lockAttrs: finalAttrs:
sass = lockAttrs:
{ buildInputs ? [ ], ... }: {
buildInputs = buildInputs ++ [ libsass ];
};
sdl2 = lockAttrs: finalAttrs:
sdl2 = lockAttrs:
{ buildInputs ? [ ], ... }: {
buildInputs = buildInputs ++ [ SDL2 ];
};
tkrzw = lockAttrs: finalAttrs:
tkrzw = lockAttrs:
{ nativeBuildInputs ? [ ], buildInputs ? [ ], ... }: {
nativeBuildInputs = nativeBuildInputs ++ [ pkg-config ];
buildInputs = buildInputs ++ [ tkrzw ];
};
x11 = lockAttrs: finalAttrs:
x11 = lockAttrs:
{ buildInputs ? [ ], ... }: {
buildInputs = buildInputs ++ (with xorg; [ libX11 libXft libXinerama ]);
};
zippy = lockAttrs: finalAttrs:
zippy = lockAttrs:
{ nimFlags ? [ ], ... }: {
nimFlags = nimFlags ++ lib.optionals stdenv.hostPlatform.isx86_64 [
"--passC:-msse4.1"