at v192 1.3 kB view raw
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 description = '' 25 freefall derivation to use. 26 ''; 27 }; 28 29 devices = mkOption { 30 type = types.listOf types.string; 31 default = [ "/dev/sda" ]; 32 description = '' 33 Device paths to all internal spinning hard drives. 34 ''; 35 }; 36 37 }; 38 39 config = let 40 41 mkService = dev: 42 assert dev != ""; 43 let dev' = utils.escapeSystemdPath dev; in 44 nameValuePair "freefall-${dev'}" { 45 description = "Free-fall protection for ${dev}"; 46 after = [ "${dev'}.device" ]; 47 wantedBy = [ "${dev'}.device" ]; 48 serviceConfig = { 49 ExecStart = "${cfg.package}/bin/freefall ${dev}"; 50 Restart = "on-failure"; 51 Type = "forking"; 52 }; 53 }; 54 55 in mkIf cfg.enable { 56 57 environment.systemPackages = [ cfg.package ]; 58 59 systemd.services = builtins.listToAttrs (map mkService cfg.devices); 60 61 }; 62 63}