feat: rewrite pi to be simple and nix based
This commit is contained in:
parent
b2c8d08bdc
commit
c6e726c430
28 changed files with 880 additions and 2458 deletions
81
pi/flake.nix
Normal file
81
pi/flake.nix
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
{
|
||||
description = "NixOS configuration for noisebell Pi";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
noisebell.url = "path:./pi-service";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, noisebell }:
|
||||
let
|
||||
nixosModule = { config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.noisebell;
|
||||
in
|
||||
{
|
||||
options.services.noisebell = {
|
||||
enable = lib.mkEnableOption "noisebell GPIO door monitor";
|
||||
|
||||
gpioPin = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 17;
|
||||
description = "GPIO pin number to monitor.";
|
||||
};
|
||||
|
||||
debounceSecs = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 5;
|
||||
description = "Debounce delay in seconds.";
|
||||
};
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8080;
|
||||
description = "HTTP port for the status endpoint.";
|
||||
};
|
||||
|
||||
endpointUrl = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "URL to POST state changes to.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.noisebell = {
|
||||
description = "Noisebell GPIO door monitor";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
|
||||
environment = {
|
||||
NOISEBELL_GPIO_PIN = toString cfg.gpioPin;
|
||||
NOISEBELL_DEBOUNCE_SECS = toString cfg.debounceSecs;
|
||||
NOISEBELL_PORT = toString cfg.port;
|
||||
NOISEBELL_ENDPOINT_URL = cfg.endpointUrl;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${noisebell.packages.aarch64-linux.default}/bin/noisebell";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
DynamicUser = true;
|
||||
SupplementaryGroups = [ "gpio" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
nixosModules.default = nixosModule;
|
||||
|
||||
nixosConfigurations.pi = nixpkgs.lib.nixosSystem {
|
||||
system = "aarch64-linux";
|
||||
modules = [
|
||||
nixosModule
|
||||
./configuration.nix
|
||||
./hardware-configuration.nix
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue