nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

buildNimPackage: allow overriding nim package args

Without this, it's impossible to override the lockFile as the default
overrideAttrs is applied after the composition in buildNimPackage has
read the lock file and generated the nim flags from it.

authored by

Sophie Tauchert and committed by
Emery Hemingway
3b40e1bd db3bd72e

+36 -2
+15 -2
doc/languages-frameworks/nim.section.md
··· 50 50 $ nix run -f . nim_lk ./result | jq --sort-keys > pkgs/by-name/tt/ttop/lock.json 51 51 ``` 52 52 53 - ## Lockfile dependency overrides {#nimoverrides} 53 + ## Overriding Nim packages {#nim-overrides} 54 + 55 + The `buildNimPackage` function generates flags and additional build dependencies from the `lockFile` parameter passed to `buildNimPackage`. Using [`overrideAttrs`](#sec-pkg-overrideAttrs) on the final package will apply after this has already been generated, so this can't be used to override the `lockFile` in a package built with `buildNimPackage`. To be able to override parameters before flags and build dependencies are generated from the `lockFile`, use `overrideNimAttrs` instead with the same syntax as `overrideAttrs`: 56 + 57 + ```nix 58 + pkgs.nitter.overrideNimAttrs { 59 + # using a different source which has different dependencies from the standard package 60 + src = pkgs.fetchFromGithub { /* … */ }; 61 + # new lock file generated from the source 62 + lockFile = ./custom-lock.json; 63 + } 64 + ``` 65 + 66 + ## Lockfile dependency overrides {#nim-lock-overrides} 54 67 55 68 The `buildNimPackage` function matches the libraries specified by `lockFile` to attrset of override functions that are then applied to the package derivation. 56 69 The default overrides are maintained as the top-level `nimOverrides` attrset at `pkgs/top-level/nim-overrides.nix`. ··· 94 81 - finalAttrs: the final attrset passed by `buildNimPackage` to `stdenv.mkDerivation`. 95 82 - prevAttrs: the attrset produced by initial arguments to `buildNimPackage` and any preceding lockfile overlays. 96 83 97 - ### Overriding an Nim library override {#nimoverrides-overrides} 84 + ### Overriding an Nim library override {#nim-lock-overrides-overrides} 98 85 99 86 The `nimOverrides` attrset makes it possible to modify overrides in a few different ways. 100 87
+21
pkgs/development/compilers/nim/build-nim-package.nix
··· 7 7 , nim_builder 8 8 , defaultNimVersion ? 2 9 9 , nimOverrides 10 + , buildNimPackage 10 11 }: 11 12 12 13 let ··· 91 90 , nativeBuildInputs ? [ ] 92 91 , nimFlags ? [ ] 93 92 , requiredNimVersion ? defaultNimVersion 93 + , passthru ? { } 94 94 , ... 95 95 }: 96 96 (if requiredNimVersion == 1 then { ··· 104 102 throw 105 103 "requiredNimVersion ${toString requiredNimVersion} is not valid") // { 106 104 nimFlags = lockFileNimFlags ++ nimFlags; 105 + passthru = passthru // { 106 + # allow overriding the result of buildNimPackageArgs before this composition is applied 107 + # this allows overriding the lockFile for packages built using buildNimPackage 108 + # this is adapted from mkDerivationExtensible in stdenv.mkDerivation 109 + overrideNimAttrs = f0: 110 + let 111 + f = self: super: 112 + let x = f0 super; 113 + in 114 + if builtins.isFunction x 115 + then f0 self super 116 + else x; 117 + in 118 + buildNimPackage 119 + (self: 120 + let super = (asFunc ((asFunc buildNimPackageArgs) self)) baseAttrs; 121 + in 122 + super // (if builtins.isFunction f0 || f0?__functor then f self super else f0)); 123 + }; 107 124 }; 108 125 109 126 attrs = postLock // finalOverride postLock;