hydrophonitor/modules/shutdown-button/service.nix
Satu Koskinen b5e34360a7
Rewrite hydrophonitor as a NixOS RPi SD image (#19)
- Initially tested on Raspberry Pi 4B & Raspberry Pi 3B
- Create user + password, enable SSH, connect to local network
- Implemented modules: audio-recorder, gps-recorder, real-time-clock,
shutdown-button
- Deployment option with deploy-rs

Signed-off-by: Satu Koskinen <satu.a.koskinen@gmail.com>
2023-09-12 13:40:22 +03:00

44 lines
1.2 KiB
Nix

{
config,
pkgs,
lib,
...
}: let
shutdownButton = pkgs.callPackage ./default.nix {};
in {
options = {
services.shutdown-button = {
enable = lib.mkEnableOption "Whether to enable the shutdown-button service.";
gpio-pin = lib.mkOption {
type = lib.types.int;
default = 21;
description = "GPIO pin number to which button is connected";
};
shutdown-press-secs = lib.mkOption {
type = lib.types.int;
default = 1;
description = "How many seconds button must be pushed down to trigger shutdown signal";
};
};
};
config = lib.mkIf config.services.shutdown-button.enable {
systemd.services.shutdown-button = {
description = "Shutdown button service";
wantedBy = ["multi-user.target"];
script = ''
#!/usr/bin/env bash
set -x
${shutdownButton}/bin/shutdown-button --gpio-pin ${toString config.services.shutdown-button.gpio-pin} --shutdown-press-secs ${toString config.services.shutdown-button.shutdown-press-secs}
'';
serviceConfig = {
User = "root"; # Replace with appropriate user
Restart = "always";
};
startLimitIntervalSec = 0;
};
};
}