2015-01-08 22:38:10 +00:00
|
|
|
{ config, lib, pkgs, utils, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
let
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
cfg = config.services.freefall;
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
in {
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
options.services.freefall = {
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-09-06 01:48:43 +00:00
|
|
|
Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall.
|
|
|
|
'';
|
|
|
|
};
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.freefall;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.freefall";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-09-06 01:48:43 +00:00
|
|
|
freefall derivation to use.
|
|
|
|
'';
|
|
|
|
};
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
devices = mkOption {
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.listOf types.str;
|
2015-09-06 01:48:43 +00:00
|
|
|
default = [ "/dev/sda" ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-09-06 01:48:43 +00:00
|
|
|
Device paths to all internal spinning hard drives.
|
|
|
|
'';
|
2015-01-08 22:38:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
|
|
|
|
|
|
|
mkService = dev:
|
|
|
|
assert dev != "";
|
|
|
|
let dev' = utils.escapeSystemdPath dev; in
|
2015-08-03 16:27:57 +00:00
|
|
|
nameValuePair "freefall-${dev'}" {
|
|
|
|
description = "Free-fall protection for ${dev}";
|
2015-01-08 22:38:10 +00:00
|
|
|
after = [ "${dev'}.device" ];
|
|
|
|
wantedBy = [ "${dev'}.device" ];
|
|
|
|
serviceConfig = {
|
2015-09-06 01:48:43 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/freefall ${dev}";
|
2015-01-08 22:38:10 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
Type = "forking";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2015-01-08 22:38:10 +00:00
|
|
|
|
2015-09-06 01:48:43 +00:00
|
|
|
systemd.services = builtins.listToAttrs (map mkService cfg.devices);
|
2015-01-08 22:38:10 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|