1{ config, lib, pkgs, utils, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.freefall;
8
9in {
10
11 options.services.freefall = {
12
13 enable = mkOption {
14 type = types.bool;
15 default = false;
16 description = ''
17 Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall.
18 '';
19 };
20
21 package = mkOption {
22 type = types.package;
23 default = pkgs.freefall;
24 defaultText = "pkgs.freefall";
25 description = ''
26 freefall derivation to use.
27 '';
28 };
29
30 devices = mkOption {
31 type = types.listOf types.string;
32 default = [ "/dev/sda" ];
33 description = ''
34 Device paths to all internal spinning hard drives.
35 '';
36 };
37
38 };
39
40 config = let
41
42 mkService = dev:
43 assert dev != "";
44 let dev' = utils.escapeSystemdPath dev; in
45 nameValuePair "freefall-${dev'}" {
46 description = "Free-fall protection for ${dev}";
47 after = [ "${dev'}.device" ];
48 wantedBy = [ "${dev'}.device" ];
49 serviceConfig = {
50 ExecStart = "${cfg.package}/bin/freefall ${dev}";
51 Restart = "on-failure";
52 Type = "forking";
53 };
54 };
55
56 in mkIf cfg.enable {
57
58 environment.systemPackages = [ cfg.package ];
59
60 systemd.services = builtins.listToAttrs (map mkService cfg.devices);
61
62 };
63
64}