at 15.09-beta 1.3 kB view raw
1{ config, lib, pkgs, utils, ... }: 2 3with 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 != ""; 41 let dev' = utils.escapeSystemdPath dev; in 42 nameValuePair "freefall-${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 }; 55 }; 56 57 in mkIf cfg.enable { 58 59 environment.systemPackages = [ pkgs.freefall ]; 60 61 systemd.services = listToAttrs (map mkService cfg.devices); 62 63 }; 64 65}