From 84f7b0509a34269efcea8ff3d240e625df6d8b85 Mon Sep 17 00:00:00 2001 From: Lillian-Violet Date: Thu, 21 Mar 2024 00:05:37 +0100 Subject: [PATCH] Let's try this then --- nixos/hosts/shodan/auto-mount.nix | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/nixos/hosts/shodan/auto-mount.nix b/nixos/hosts/shodan/auto-mount.nix index 4aef501..ff638fb 100644 --- a/nixos/hosts/shodan/auto-mount.nix +++ b/nixos/hosts/shodan/auto-mount.nix @@ -9,20 +9,35 @@ services.udev.extraRules = '' KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="add", RUN+="${pkgs.systemd}/bin/systemctl start --no-block external-drive-mount@%k.service" KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="remove", RUN+="${pkgs.systemd}/bin/systemctl stop --no-block external-drive-mount@%k.service" + KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="remove", RUN+="${pkgs.systemd}/bin/systemctl start --no-block external-drive-unmount@%k.service" KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="add", RUN+="${pkgs.systemd}/bin/systemctl start --no-block external-drive-mount@%k.service" KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="remove", RUN+="${pkgs.systemd}/bin/systemctl stop --no-block external-drive-mount@%k.service" + KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="remove", RUN+="${pkgs.systemd}/bin/systemctl start --no-block external-drive-unmount@%k.service" KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="add", RUN+="${pkgs.systemd}/bin/systemctl start --no-block external-drive-mount@%k.service" KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="remove", RUN+="${pkgs.systemd}/bin/systemctl stop --no-block external-drive-mount@%k.service" + KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="remove", RUN+="${pkgs.systemd}/bin/systemctl start --no-block external-drive-unmount@%k.service" ''; systemd.services."external-drive-mount@" = { path = with pkgs; [jq coreutils udisks bash util-linux auto-mount]; enable = true; description = "Mount External Drive on %i"; + script = "auto-mount"; + scriptArgs = "add %i"; serviceConfig = { - ExecStart = "${pkgs.auto-mount} add %i"; - ExecStop = "${pkgs.auto-mount} remove %i"; Type = "oneshot"; RemainAfterExit = true; }; }; + + systemd.services."external-drive-unmount@" = { + path = with pkgs; [jq coreutils udisks bash util-linux auto-mount]; + enable = true; + description = "Mount External Drive on %i"; + script = "auto-mount"; + scriptArgs = "remove %i"; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = false; + }; + }; }