feat(nfs-mount): disable automout service if nas not on network.

This commit is contained in:
CronyAkatsuki 2025-06-25 19:08:09 +02:00
parent e6d21b8850
commit 0e96cd7d38

View file

@ -1,8 +1,22 @@
{ {
config, config,
pkgs,
lib, lib,
... ...
}: { }: let
auto_mount = pkgs.writeShellScriptBin "auto_mount" ''
timeout 1 ${pkgs.bash}/bin/bash -c ": < /dev/tcp/192.168.0.4/2049"
if [ $? -ne 0 ]; then
systemctl stop mnt-share.automount
echo "Nas device not available"
else
systemctl start mnt-share.automount
echo "Nas device available"
fi
exit 0
'';
in {
options = { options = {
crony.nfs-share.enable = lib.mkEnableOption "Setup personal nfs share mount."; crony.nfs-share.enable = lib.mkEnableOption "Setup personal nfs share mount.";
}; };
@ -14,5 +28,19 @@
fsType = "nfs"; fsType = "nfs";
options = ["_netdev" "noauto" "x-systemd.automount" "x-systemd.mount-timeout=10" "timeo=14" "x-systemd.idle-timeout=600"]; options = ["_netdev" "noauto" "x-systemd.automount" "x-systemd.mount-timeout=10" "timeo=14" "x-systemd.idle-timeout=600"];
}; };
systemd.timers.auto_mount = {
enable = true;
timerConfig = {
OnBootSec = "1m";
# OnUnitActiveSec = "1m";
};
wantedBy = ["timers.target"];
};
systemd.services.auto_mount = {
serviceConfig.Type = "oneshot";
serviceConfig.ExecStart = "${auto_mount}/bin/auto_mount";
};
}; };
} }