Create symlink automatically in configuration.nix?

Hello,

I use Kubernetes and iscsi, that requires the binary “iscsiadm” to be present in /usr/bin.

I solve it manually by creating a symlink like so:

/usr/bin/iscsiadm → /nix/store/dprf8xwnb2Preformatted texts82lyld9ldv2lkb7jj811v-system-path/bin/iscsiadm

How can I add this to configuration.nix so Its always there and gets updated automatically if the nix path were to change?

Thanks!!

I guess I could just create a systemd start script that checks and fixes it on each boot, but that feels a bit ugly.

Yes, this seem to work:

  system.activationScripts.iscsiadm = {
    deps = [ "binsh" ];
    text = ''
         ln -sf /run/current-system/sw/bin/iscsiadm /usr/bin/iscsiadm
    '';
  };

You could use systemd-tmpfiles, contrary to the name they do not need to be temporary
But ideally you would patch the software to stop looking in /usr/bin in the first place

1 Like

I tried to change the csi controller, but I had to compile and release my own version to be able to use something other than /usr/bin. And I really don’t want another software to have to keep updated so that was not an option.

I don’t understand what you mean with the systemd-tempfiles thing. :cry:

https://home-manager-options.extranix.com/?query=systemd.user.tmpfiles&release=release-24.05

Read the overriding section of the nixpkgs manual - Nixpkgs Reference Manual

1 Like