Specifying a key multiple times for systemd serviceConfig

I’m trying to use LoadCredential for a service I’m configuring because it seems like a good idea - unfortunately the current stable systemd version doesn’t support specifying a directory for this setting, so I need to specify it multiple times to pass multiple credentials. I.e.:

systemd.service.name.serviceConfig = {
    LoadCredential = "name:/run/secrets/secret1";
    LoadCredential = "name:/run/secrets/secret2";
};

This of course gives:

error: attribute 'LoadCredential' already defined at /nix/store/m3c0lbnqhby7as4i8mgd4kzkiccdwp5p-source/configuration/services/name.nix:19:7

       at /nix/store/m3c0lbnqhby7as4i8mgd4kzkiccdwp5p-source/configuration/services/name.nix:20:7:

           19|       LoadCredential = "name:/run/secrets/secret1";
           20|       LoadCredential = "name:/run/secrets/secret2";
             |       ^
           21|
(use '--show-trace' to show detailed location information)

Is this just impossible with nix? Do I need to write a service file by hand?

1 Like

Can’t you specify it as a list:

LoadCredential = [ "secret1" "secret2" ];

Grepping through nixpkgs shows this should be possible.

2 Likes

Yep! That makes so much sense too! I’m used to nix complaining about not specifying lists if they are an option, so I never realized that this is how the systemd conversion works - and I also neglected to check for prior art. Not one of my brightest moments.

Thanks!

2 Likes