Last active
September 28, 2016 22:39
-
-
Save matejc/fd0eb18fd7f69f093ca1e82365aab208 to your computer and use it in GitHub Desktop.
udev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, config, lib, ... }: | |
let | |
extusbup = pkgs.writeScriptBin "extusb.up" '' | |
#!${pkgs.stdenv.shell} | |
#cryptsetup luksOpen /dev/extusb1 vmware | |
cat /root/keyfile | cryptsetup -v --key-file=- luksOpen /dev/sdc1 vmware | |
vgscan | |
vgchange -ay vgvmware | |
mount /dev/vgvmware/vmware /home/test/Desktop/Virtual | |
''; | |
extusbdown = pkgs.writeScriptBin "extusb.down" '' | |
#!${pkgs.stdenv.shell} | |
umount /home/test/Desktop/Virtual | |
vgchange -an vgvmware | |
cryptsetup luksClose vmware | |
''; | |
in | |
{ | |
. | |
. | |
. | |
udev.extraRules = '' | |
# External USB hard drive | |
ACTION=="add", SUBSYSTEM=="block", ATTRS{model}=="2115 ", NAME="extusb", RUN+="${extusbup}/bin/extusb.up" | |
ACTION=="remove", SUBSYSTEM=="block", ATTRS{model}=="2115 ", RUN+="${extusbdown}/bin/extusb.down" | |
''; | |
. | |
. | |
. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
. | |
. | |
. | |
systemd.services."attach-my-disk" = { | |
script = '' | |
echo "$(date) attached" >> /tmp/usb.log | |
''; | |
serviceConfig.Type = "oneshot"; | |
}; | |
systemd.services."detach-my-disk" = { | |
script = '' | |
echo "$(date) detached" >> /tmp/usb.log | |
''; | |
serviceConfig.Type = "oneshot"; | |
}; | |
services.udev.extraRules = '' | |
ACTION=="add", ATTRS{vendor}=="0x8086", ENV{SYSTEMD_WANTS}="attach-my-disk.service" | |
ACTION=="remove", ATTRS{vendor}=="0x8086", ENV{SYSTEMD_WANTS}="detach-my-disk.service" | |
''; | |
. | |
. | |
. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment