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

29 lines
1.2 KiB
Nix
Raw Normal View History

{
inputs,
outputs,
lib,
config,
pkgs,
...
}: {
services.udev.extraRules = ''
2024-03-18 15:09:12 +01:00
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=="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=="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"
'';
2024-03-18 15:19:43 +01:00
systemd.services."external-drive-mount@" = {
2024-03-20 23:21:23 +01:00
path = with pkgs; [jq coreutils udisks bash auto-mount];
enable = true;
description = "Mount External Drive on %i";
serviceConfig = {
Type = "oneshot";
2024-03-18 15:19:43 +01:00
RemainAfterExit = true;
2024-03-20 23:35:27 +01:00
script = "auto-mount add %i";
preStop = "auto-mount remove %i";
};
};
}