1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-20 00:19:25 +03:00
nixpkgs/nixos/modules/services/hardware/freefall.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.3 KiB
Nix
Raw Normal View History

2015-01-08 23:38:10 +01:00
{
config,
lib,
pkgs,
utils,
...
}:
let
2015-01-08 23:38:10 +01:00
cfg = config.services.freefall;
2015-01-08 23:38:10 +01:00
in
{
2015-01-08 23:38:10 +01:00
options.services.freefall = {
2015-01-08 23:38:10 +01:00
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to protect HP/Dell laptop hard drives (not SSDs) in free fall.
'';
};
2015-01-08 23:38:10 +01:00
package = lib.mkPackageOption pkgs "freefall" { };
2015-01-08 23:38:10 +01:00
devices = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "/dev/sda" ];
description = ''
Device paths to all internal spinning hard drives.
'';
2015-01-08 23:38:10 +01:00
};
};
config =
let
2015-01-08 23:38:10 +01:00
mkService =
dev:
assert dev != "";
let
dev' = utils.escapeSystemdPath dev;
in
lib.nameValuePair "freefall-${dev'}" {
2015-08-03 18:27:57 +02:00
description = "Free-fall protection for ${dev}";
2015-01-08 23:38:10 +01:00
after = [ "${dev'}.device" ];
wantedBy = [ "${dev'}.device" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/freefall ${dev}";
2015-01-08 23:38:10 +01:00
Restart = "on-failure";
Type = "forking";
};
2015-01-08 23:38:10 +01:00
};
in
lib.mkIf cfg.enable {
2015-01-08 23:38:10 +01:00
environment.systemPackages = [ cfg.package ];
2015-01-08 23:38:10 +01:00
systemd.services = builtins.listToAttrs (map mkService cfg.devices);
2015-01-08 23:38:10 +01:00
};
}