1 { config, lib, pkgs, utils, ... }:
4 cfg = config.services.freefall;
8 options.services.freefall = {
10 enable = lib.mkOption {
11 type = lib.types.bool;
14 Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall.
18 package = lib.mkPackageOption pkgs "freefall" { };
20 devices = lib.mkOption {
21 type = lib.types.listOf lib.types.str;
22 default = [ "/dev/sda" ];
24 Device paths to all internal spinning hard drives.
34 let dev' = utils.escapeSystemdPath dev; in
35 lib.nameValuePair "freefall-${dev'}" {
36 description = "Free-fall protection for ${dev}";
37 after = [ "${dev'}.device" ];
38 wantedBy = [ "${dev'}.device" ];
40 ExecStart = "${cfg.package}/bin/freefall ${dev}";
41 Restart = "on-failure";
46 in lib.mkIf cfg.enable {
48 environment.systemPackages = [ cfg.package ];
50 systemd.services = builtins.listToAttrs (map mkService cfg.devices);