Recently I was trying to build git statically, and discovered that one of its dependencies, keyutils, fails to build. After some investigation with nix-shell -A pkgsStatic.keyutils
I discovered that to make things work I need to set extra environment variable in case of pkgsStatic
. Question is how to write fix derivation in nixpkgs.
I would add something like
makeFlags = if stdenv.isStatic then ["NO_SOLIB=1"] else [ ];
except I wasn’t able to find nothing like isStatic
. There is stdenv.targetPlatform.libc
that distinguishes glibc and musl, but it is not enough to distingush pkgsMusl
and pkgsStatic
. How do I do this check?
2 Likes
To add a static package you need to alter the nix expression needs to have a static switch added to it, then you need to add the entry to https://github.com/NixOS/nixpkgs/blob/0c7803f1441580f70998709b1e9749143fcc0ab1/pkgs/top-level/static.nix where an overlay is created in which the static switch will be turned on.
For the difference between musl and static, I’m assuming that musl is replacing gcc as libc.
1 Like
Seems I wasn’t clear enough or I do not understand your reply. Let me try again.
Of course, I know what the difference between muslPkgs and staticPkgs. Question is how to write derivation that behaves differently in these two cases. For example, in pkgs/development/libraries/tbb/default.nix
there is following line:
patches = stdenv.lib.optional stdenv.hostPlatform.isMusl ./glibc-struct-mallinfo.patch;
so when derviation is built with glibc (e.g nix-env -iA nixpkgs.tdd
) patch is NOT applied, but when derivation is built with musl, either statically or dynamically (e.g nix-env -iA nixpkgs.pkgsMusl.tdd
or nix-env -iA nixpkgs.pkgsStatic.tdd
) then patch IS applied. My question is to how write derivation that behaves differently (e.g patch applied) in case of pkgsStatic
but not in case of pkgsMusl
.
generally you add a switch at the top of the file, like , static ? false
and then assert on that.
an example can be found https://github.com/NixOS/nixpkgs/blob/0fa82116835b07f958755c29ef30706eebdde66b/pkgs/development/web/woff2/default.nix
for this to apply to pkgsStatic
though, you still need to follow the directions in my first post
1 Like
Thanks. I created pull request based on your suggestion: https://github.com/NixOS/nixpkgs/pull/96223
1 Like