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 2 3 3 with lib; 4 4 5 - { 5 + let 6 6 7 - ###### interface 7 + cfg = config.services.freefall; 8 8 9 - options = with types; { 9 + in { 10 10 11 - services.freefall = { 11 + options.services.freefall = { 12 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 - }; 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 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 - }; 21 + package = mkOption { 22 + type = types.package; 23 + default = pkgs.freefall; 24 + description = '' 25 + freefall derivation to use. 26 + ''; 27 + }; 28 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 + ''; 29 35 }; 30 36 31 37 }; 32 38 33 - ###### implementation 34 - 35 39 config = let 36 - 37 - cfg = config.services.freefall; 38 40 39 41 mkService = dev: 40 42 assert dev != ""; ··· 43 45 description = "Free-fall protection for ${dev}"; 44 46 after = [ "${dev'}.device" ]; 45 47 wantedBy = [ "${dev'}.device" ]; 46 - path = [ pkgs.freefall ]; 47 - unitConfig = { 48 - DefaultDependencies = false; 49 - }; 50 48 serviceConfig = { 51 - ExecStart = "${pkgs.freefall}/bin/freefall ${dev}"; 49 + ExecStart = "${cfg.package}/bin/freefall ${dev}"; 52 50 Restart = "on-failure"; 53 51 Type = "forking"; 54 52 }; ··· 56 54 57 55 in mkIf cfg.enable { 58 56 59 - environment.systemPackages = [ pkgs.freefall ]; 57 + environment.systemPackages = [ cfg.package ]; 60 58 61 - systemd.services = listToAttrs (map mkService cfg.devices); 59 + systemd.services = builtins.listToAttrs (map mkService cfg.devices); 62 60 63 61 }; 64 62