How to distinguish pkgsMusl and pkgsStatic?

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?


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 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

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:

1 Like