How to create folder in /var/lib with Nix?

For my NixOS in VPS, I have an image that is going to mount the volume in /var/lib, but I got file doesn’t exist right now. I don’t want to mkdir manually.

How do you mkdir in /var with Nix? Is that possible? I am not using home-manager on my VPS.

              virtualisation.oci-containers.containers = {
                vw = {
                  image = "vaultwarden/server:latest";
                  ports = [ "30625:80" ];
                  volumes = [
                    "/var/lib/vaultwarden/:/data/"
                  ];
                };
              };

You could do this in system.activationScripts, NixOS does something similar:

{
  config.system.activationScripts.makeVaultWardenDir = lib.stringAfter [ "var" ] ''
    mkdir -p /var/lib/vaultwarden
  '';
}
3 Likes

Yes this is what I need. Thanks!