From fa3d7ea77ba1b4dca52b97dfe90755ce7e6edc80 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 6 Sep 2015 03:48:43 +0200 Subject: [PATCH] nixos: freefall module: add `package` option ...and tidy up some of my old cargo-culted code. --- nixos/modules/services/hardware/freefall.nix | 56 ++++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/nixos/modules/services/hardware/freefall.nix b/nixos/modules/services/hardware/freefall.nix index 7867956c1ab0..2be339766069 100644 --- a/nixos/modules/services/hardware/freefall.nix +++ b/nixos/modules/services/hardware/freefall.nix @@ -2,40 +2,42 @@ with lib; -{ +let - ###### interface + cfg = config.services.freefall; - options = with types; { +in { - services.freefall = { + options.services.freefall = { - enable = mkOption { - default = false; - description = '' - Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall. - ''; - type = bool; - }; + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall. + ''; + }; - devices = mkOption { - default = [ "/dev/sda" ]; - description = '' - Device paths to all internal spinning hard drives. - ''; - type = listOf string; - }; + package = mkOption { + type = types.package; + default = pkgs.freefall; + description = '' + freefall derivation to use. + ''; + }; + devices = mkOption { + type = types.listOf types.string; + default = [ "/dev/sda" ]; + description = '' + Device paths to all internal spinning hard drives. + ''; }; }; - ###### implementation - config = let - cfg = config.services.freefall; - mkService = dev: assert dev != ""; let dev' = utils.escapeSystemdPath dev; in @@ -43,12 +45,8 @@ with lib; description = "Free-fall protection for ${dev}"; after = [ "${dev'}.device" ]; wantedBy = [ "${dev'}.device" ]; - path = [ pkgs.freefall ]; - unitConfig = { - DefaultDependencies = false; - }; serviceConfig = { - ExecStart = "${pkgs.freefall}/bin/freefall ${dev}"; + ExecStart = "${cfg.package}/bin/freefall ${dev}"; Restart = "on-failure"; Type = "forking"; }; @@ -56,9 +54,9 @@ with lib; 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); };