davfs: handle password file

This commit is contained in:
ibizaman 2026-06-23 16:31:02 +02:00 committed by Pierre Penninckx
parent ba0d3cac4a
commit 3432df47f1
2 changed files with 26 additions and 0 deletions

View file

@ -75,6 +75,30 @@ in
config = { config = {
services.davfs2.enable = builtins.length cfg.mounts > 0; services.davfs2.enable = builtins.length cfg.mounts > 0;
systemd.services = lib.optionalAttrs (builtins.length cfg.mounts > 0) {
davfs2-password-generation = {
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /etc/davfs2
[ -f /etc/davfs2/secrets ] && mv /etc/davfs2/secrets /etc/davfs2/secrets.prev
touch /etc/davfs2/secrets
chown root: /etc/davfs2
chown root: /etc/davfs2/secrets
chmod 700 /etc/davfs2
chmod 600 /etc/davfs2/secrets
''
+ (
let
mkPasswordCmd = cfg': ''
printf "%s %s %s\n" "${cfg'.mountPoint}" "${cfg'.username}" "$(cat ${cfg'.passwordFile})" >> /etc/davfs2/secrets
'';
in
lib.concatStringsSep "\n" (map mkPasswordCmd cfg.mounts)
);
};
};
systemd.mounts = systemd.mounts =
let let
mkMountCfg = c: { mkMountCfg = c: {
@ -82,6 +106,7 @@ in
description = "Webdav mount point"; description = "Webdav mount point";
after = [ "network-online.target" ]; after = [ "network-online.target" ];
wants = [ "network-online.target" ]; wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
what = c.remoteUrl; what = c.remoteUrl;
where = c.mountPoint; where = c.mountPoint;

View file

@ -34,6 +34,7 @@ in
expected = { expected = {
services.davfs2.enable = false; services.davfs2.enable = false;
systemd.mounts = [ ]; systemd.mounts = [ ];
systemd.services = { };
}; };
expr = testConfig { }; expr = testConfig { };
}; };