nixos: freefall module: add package option

...and tidy up some of my old cargo-culted code.
This commit is contained in:
Tobias Geerinckx-Rice 2015-09-06 03:48:43 +02:00
parent a56eed5405
commit fa3d7ea77b

View File

@ -2,40 +2,42 @@
with lib; with lib;
{ let
###### interface cfg = config.services.freefall;
options = with types; { in {
services.freefall = { options.services.freefall = {
enable = mkOption { enable = mkOption {
default = false; type = types.bool;
description = '' default = false;
Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall. description = ''
''; Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall.
type = bool; '';
}; };
devices = mkOption { package = mkOption {
default = [ "/dev/sda" ]; type = types.package;
description = '' default = pkgs.freefall;
Device paths to all internal spinning hard drives. description = ''
''; freefall derivation to use.
type = listOf string; '';
}; };
devices = mkOption {
type = types.listOf types.string;
default = [ "/dev/sda" ];
description = ''
Device paths to all internal spinning hard drives.
'';
}; };
}; };
###### implementation
config = let config = let
cfg = config.services.freefall;
mkService = dev: mkService = dev:
assert dev != ""; assert dev != "";
let dev' = utils.escapeSystemdPath dev; in let dev' = utils.escapeSystemdPath dev; in
@ -43,12 +45,8 @@ with lib;
description = "Free-fall protection for ${dev}"; description = "Free-fall protection for ${dev}";
after = [ "${dev'}.device" ]; after = [ "${dev'}.device" ];
wantedBy = [ "${dev'}.device" ]; wantedBy = [ "${dev'}.device" ];
path = [ pkgs.freefall ];
unitConfig = {
DefaultDependencies = false;
};
serviceConfig = { serviceConfig = {
ExecStart = "${pkgs.freefall}/bin/freefall ${dev}"; ExecStart = "${cfg.package}/bin/freefall ${dev}";
Restart = "on-failure"; Restart = "on-failure";
Type = "forking"; Type = "forking";
}; };
@ -56,9 +54,9 @@ with lib;
in mkIf cfg.enable { in mkIf cfg.enable {
environment.systemPackages = [ pkgs.freefall ]; environment.systemPackages = [ cfg.package ];
systemd.services = listToAttrs (map mkService cfg.devices); systemd.services = builtins.listToAttrs (map mkService cfg.devices);
}; };