NixOS-Config/nixos/hosts/shodan/auto-mount.nix

31 lines
1.2 KiB
Nix
Raw Normal View History

{
inputs,
outputs,
lib,
config,
pkgs,
...
}: {
services.udev.extraRules = ''
KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="add", RUN+="/bin/systemctl start --no-block external-drive-mount@%k.service"
KERNEL=="sd[a-z]|sd[a-z][0-9]", ACTION=="remove", RUN+="/bin/systemctl stop --no-block external-drive-mount@%k.service"
KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="add", RUN+="/bin/systemctl start --no-block external-drive-mount@%k.service"
KERNEL=="mmcblk0|mmcblk0p[0-9]", ACTION=="remove", RUN+="/bin/systemctl stop --no-block external-drive-mount@%k.service"
KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="add", RUN+="/bin/systemctl start --no-block external-drive-mount@%k.service"
KERNEL=="nvme0n1p9|nvme0n1p1[0-9]", ACTION=="remove", RUN+="/bin/systemctl stop --no-block external-drive-mount@%k.service"
'';
systemd.services.auto-mount = {
enable = true;
description = "Mount External Drive on %i";
unitConfig = {
};
serviceConfig = {
Type = "oneshot";
ExecStart = "/run/current-system/sw/bin/automount add %i";
ExecStop = "/run/current-system/sw/bin/automount remove %i";
RemainAfterExit = true;
};
wantedBy = ["multi-user.target"];
};
}