Skip to content

Instantly share code, notes, and snippets.

@msteen
Created April 5, 2020 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msteen/1d49accb64fb7800c7f917480dd74609 to your computer and use it in GitHub Desktop.
Save msteen/1d49accb64fb7800c7f917480dd74609 to your computer and use it in GitHub Desktop.
{
systemd.services."unlock-backup-disks" = {
description = "Unlock the LUKS encrypted ZFS backup disks";
unitConfig = {
DefaultDependencies = "no";
};
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
if [[ ! -e /dev/mapper/luks ]]; then
${pkgs.cryptsetup}/bin/cryptsetup luksOpen /dev/disk/by-uuid/${cfg.luks} luks --key-file=/wheel/arc/${config.host.name}-luks.key
fi
${pkgs.zfs}/bin/zpool import -a
'';
after = [ "systemd-udev-settle.service" "systemd-modules-load.service" ];
requires = [ "systemd-udev-settle.service" ];
before = [ "local-fs.target" "zfs-import.target" ];
wantedBy = [ "local-fs.target" ];
requiredBy = [ "zfs-import.target" ];
restartIfChanged = false;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment