Setting `programs.nix-ld.libraries = [];` seems to have no effect

I just upgraded my main channel and got nix-ld errors because of some interaction with curl being on the path.

However, removing it from programs.nix-ld.libraries by setting it to the empty list does not seem to anything. All standard libraries like are still linked. that is very unfortunate.

Can others replicate this behaviour? What could be wrong that the library change is not picked up? I also restartet the entire OS… nothing

Expected. Values in the module system are merged, if they have the same highest priority. And in this case the defaults for that option are set with regular priority:

This is to prevent people getting surprised that the defaults went missing if they set their own values.

If you want yours to have higher precedence, use lib.mkForce.

{ lib, ... }:
{
  programs.nix-ld.libraries = lib.mkForce [];
}

See https://nixos.org/manual/nixos/stable/#sec-option-definitions-setting-priorities.

Though at that point, it seems easier to just not use nix-ld in the first place.

3 Likes

thank you so much for your instant help!

It is an external binary which is run here for my case, so nix-ld makes sense. There is only an interaction with curl, so that I bet I get the best out of both worlds by turning of curl in the standard nix-ld libraries. Sure it would be nice to create a custom wrapper around my executable, but it is easier to just take it off the entire system for now.

wait… I already tried lib.mkForce apparently - it hasn’t worked for me, does it work for you?

I don’t use nix-ld. If you have a specific set of code for me to test with, along with the full error, I could help further, otherwise that’s about all I could comment on that.

It is just that setting it empty won’t make /run/current-system/sw/share/nix-ld/lib empty, which is the location for nix-ld. E.g. curl will still be in there as well as everything else. (at least on my system).

I was expecting this to get empty by setting

programs.nix-ld.libraries = lib.mkForce [];
$ bat -p flake.nix                                                  
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs =
    { nixpkgs, ... }:
    {
      nixosConfigurations.test = nixpkgs.lib.nixosSystem {
        modules = [
          (
            { lib, modulesPath, ... }:
            {
              imports = [ "${modulesPath}/profiles/minimal.nix" ];

              boot.loader.grub.enable = false;
              fileSystems."/".device = "nodev";
              nixpkgs.hostPlatform = "x86_64-linux";
              system.stateVersion = "24.05";

              # custom config here
              programs.nix-ld = {
                enable = true;
                libraries = lib.mkForce [];
              };
            }
          )
        ];
      };
    };
}

$ nixos-rebuild build --flake .#test --no-build-nix
...snip...
$ ls result/sw/share/nix-ld/lib/
ld.so

How did you rebuild your system?

1 Like

thank you, indeed I was confusing options and now it works :slight_smile: