diff --git a/doc/languages-frameworks/nim.section.md b/doc/languages-frameworks/nim.section.md index c6ebf49b83f6..c9e5c51e530e 100644 --- a/doc/languages-frameworks/nim.section.md +++ b/doc/languages-frameworks/nim.section.md @@ -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} diff --git a/pkgs/development/compilers/nim/build-nim-package.nix b/pkgs/development/compilers/nim/build-nim-package.nix index a22fb45b507b..2bff3bf8cc85 100644 --- a/pkgs/development/compilers/nim/build-nim-package.nix +++ b/pkgs/development/compilers/nim/build-nim-package.nix @@ -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" diff --git a/pkgs/top-level/nim-overrides.nix b/pkgs/top-level/nim-overrides.nix index 34db79a6a4ea..61717562e89e 100644 --- a/pkgs/top-level/nim-overrides.nix +++ b/pkgs/top-level/nim-overrides.nix @@ -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"