at 24.11-pre 1.2 kB view raw
1{ config, lib, pkgs, utils, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.freefall; 8 9in { 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 = mkPackageOption pkgs "freefall" { }; 22 23 devices = mkOption { 24 type = types.listOf types.str; 25 default = [ "/dev/sda" ]; 26 description = '' 27 Device paths to all internal spinning hard drives. 28 ''; 29 }; 30 31 }; 32 33 config = let 34 35 mkService = dev: 36 assert dev != ""; 37 let dev' = utils.escapeSystemdPath dev; in 38 nameValuePair "freefall-${dev'}" { 39 description = "Free-fall protection for ${dev}"; 40 after = [ "${dev'}.device" ]; 41 wantedBy = [ "${dev'}.device" ]; 42 serviceConfig = { 43 ExecStart = "${cfg.package}/bin/freefall ${dev}"; 44 Restart = "on-failure"; 45 Type = "forking"; 46 }; 47 }; 48 49 in mkIf cfg.enable { 50 51 environment.systemPackages = [ cfg.package ]; 52 53 systemd.services = builtins.listToAttrs (map mkService cfg.devices); 54 55 }; 56 57}