nixos: freefall module: add `package` option

...and tidy up some of my old cargo-culted code.

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