mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-21 06:39:09 -04:00
starting safe_reboot
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
./nh.nix
|
||||
./nix.nix
|
||||
./programs.nix
|
||||
./safe_reboot.nix
|
||||
./ssh.nix
|
||||
./snapshot_manager.nix
|
||||
];
|
||||
@@ -49,6 +50,11 @@
|
||||
PYTHONPATH = "${inputs.self}/";
|
||||
};
|
||||
|
||||
safe_reboot = {
|
||||
enable = lib.mkDefault true;
|
||||
datasetPrefix = "root_pool/";
|
||||
};
|
||||
|
||||
zfs = {
|
||||
trim.enable = lib.mkDefault true;
|
||||
autoScrub.enable = lib.mkDefault true;
|
||||
|
||||
56
common/global/safe_reboot.nix
Normal file
56
common/global/safe_reboot.nix
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
config,
|
||||
inputs,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.safe_reboot;
|
||||
python_command =
|
||||
lib.escapeShellArgs (
|
||||
[
|
||||
"${pkgs.my_python}/bin/python"
|
||||
"-m"
|
||||
"python.tools.safe_reboot"
|
||||
]
|
||||
++ lib.optionals (cfg.drivePath != null) [ cfg.drivePath ]
|
||||
++ [
|
||||
"--dataset-prefix"
|
||||
cfg.datasetPrefix
|
||||
"--check-only"
|
||||
]
|
||||
);
|
||||
in
|
||||
{
|
||||
options.services.safe_reboot = {
|
||||
enable = lib.mkEnableOption "Safe reboot dataset/drive validation";
|
||||
datasetPrefix = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "root_pool/";
|
||||
description = "Dataset prefix that must have exec enabled before rebooting.";
|
||||
};
|
||||
drivePath = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = "Drive path that must exist before rebooting. Set to null to skip.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.safe-reboot-check = {
|
||||
description = "Safe reboot validation";
|
||||
before = [ "systemd-reboot.service" ];
|
||||
wantedBy = [ "reboot.target" ];
|
||||
partOf = [ "reboot.target" ];
|
||||
path = [ pkgs.zfs ];
|
||||
environment = {
|
||||
PYTHONPATH = "${inputs.self}/";
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = python_command;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user