diff --git a/module.nix b/module.nix index b761f80..aa37337 100644 --- a/module.nix +++ b/module.nix @@ -6,23 +6,42 @@ in options = { services.gatekeeper = { enable = lib.mkEnableOption "Enable the gatekeeper api service."; - dotenv = lib.mkOption { - type = lib.types.path; - description = "The path to a .env file with the keys"; + envFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; + description = "The path to a .env file with all the other options"; }; db = lib.mkOption { type = lib.types.path; description = "Where to save the database."; + default = "/var/lib/gatekeeper"; + }; + mockGpio = lib.mkOption { + type = lib.types.str; + default = "True"; + description = "Mock GPIO pins. Has to be a string!"; }; }; }; config = lib.mkIf cfg.enable { users.groups.gatekeeper = {}; + users.groups.gpio = {}; users.users.gatekeeper = { description = "gatekeeper user"; group = "gatekeeper"; + extraGroups = ["gpio"]; isSystemUser = true; }; + services.udev.extraRules = lib.mkBefore '' + KERNEL=="gpiomem", GROUP="gpio", MODE="0660" + SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k && ${pkgs.coreutils}/bin/chgrp -R gpio /sys/class/gpio && ${pkgs.coreutils}/bin/chmod -R g=u /sys/class/gpio'" + SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp -R gpio /sys%p && ${pkgs.coreutils}/bin/chmod -R g=u /sys%p'" + ''; + + boot.kernelParams = [ + "iomem=relaxed" # for pigpiod + "strict-devmem=0" + ]; + services.pcscd = { enable = true; plugins = [ pkgs.acsccid ]; @@ -43,6 +62,12 @@ in RestartSec = "20"; StateDirectory = "gatekeeper"; WorkingDirectory = "/var/lib/gatekeeper"; + EnvironmentFile = cfg.envFile; + }; + environment = { + SQLALCHEMY_DATABASE_URL = "sqlite:///${cfg.db}/gatekeeper.db"; + ALEMBIC_CONFIG = "${self}/alembic.ini"; + MOCK_GPIO = cfg.mockGpio; }; }; };