From 0e96cd7d38a6ec30f01df6b7abb134aaab44246c Mon Sep 17 00:00:00 2001 From: Crony Akatsuki Date: Wed, 25 Jun 2025 19:08:09 +0200 Subject: [PATCH] feat(nfs-mount): disable automout service if nas not on network. --- modules/linux/nixos/nfs-share.nix | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/linux/nixos/nfs-share.nix b/modules/linux/nixos/nfs-share.nix index 492d322..8707d53 100644 --- a/modules/linux/nixos/nfs-share.nix +++ b/modules/linux/nixos/nfs-share.nix @@ -1,8 +1,22 @@ { config, + pkgs, 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 = { crony.nfs-share.enable = lib.mkEnableOption "Setup personal nfs share mount."; }; @@ -14,5 +28,19 @@ fsType = "nfs"; 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"; + }; }; }