mirror of
https://github.com/NotAShelf/air-quality-monitor.git
synced 2024-11-22 13:20:48 +00:00
init flake checks
This commit is contained in:
parent
000b7b1c9a
commit
87ae83c193
3 changed files with 81 additions and 11 deletions
11
flake.nix
11
flake.nix
|
@ -22,15 +22,22 @@
|
|||
formatter = pkgs.alejandra;
|
||||
|
||||
packages = {
|
||||
pi-air-quality-monitor = pkgs.callPackage ./nix/default.nix {};
|
||||
default = self'.packages.pi-air-quality-monitor;
|
||||
pi-air-quality-monitor = pkgs.callPackage ./nix/default.nix {};
|
||||
};
|
||||
|
||||
devShells = {
|
||||
default = self'.packages.pi-air-quality-monitor;
|
||||
pi-air-quality-monitor = pkgs.mkShell {
|
||||
inputsFrom = self'.packages.pi-air-quality-monitor.pythonPath;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
flake = {
|
||||
nixosModules = {
|
||||
pi-air-quality-monitor = import ./nix/module.nix self;
|
||||
default = self.nixosModules.pi-air-quality-monitor;
|
||||
pi-air-quality-monitor = import ./nix/module.nix self;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ self: {
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkEnableOption mkOption mkIf types;
|
||||
inherit (lib) mkEnableOption mkOption mkIf types optional;
|
||||
|
||||
cfg = config.services.pi-air-quality-monitor;
|
||||
in {
|
||||
|
@ -38,23 +38,85 @@ in {
|
|||
default = "pi-aqm";
|
||||
description = "Group to run the server as";
|
||||
};
|
||||
|
||||
device = mkOption {
|
||||
type = types.path;
|
||||
default = "/dev/ttyUSB0";
|
||||
description = "Device to read data from";
|
||||
};
|
||||
|
||||
environmentFile = mkOption {
|
||||
type = with types; nullOr path;
|
||||
default = null;
|
||||
example = "/etc/pi-aqm.env";
|
||||
description = "File to read environment variables from";
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/pi-aqm";
|
||||
description = "Directory to store data in";
|
||||
};
|
||||
|
||||
redis = {
|
||||
createLocally = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Whether to create a Redis instance locally";
|
||||
};
|
||||
|
||||
host = mkOption {
|
||||
type = types.str;
|
||||
default = "localhost";
|
||||
description = "Redis host";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
default = 6379;
|
||||
description = "Redis port";
|
||||
};
|
||||
|
||||
redis_db = mkOption {
|
||||
type = types.int;
|
||||
default = 0;
|
||||
description = "Redis database";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf config.services.pi-air-quality-monitor.enable {
|
||||
networking.firewall.allowedTCPPorts = [cfg.settings.port];
|
||||
users = {
|
||||
users.pi-aqm = {
|
||||
groups."${cfg.settings.group}" = {};
|
||||
users."${cfg.settings.user}" = {
|
||||
isSystemUser = true;
|
||||
group = "pi-aqm";
|
||||
home = "/var/lib/pi-aqm";
|
||||
group = "${cfg.settings.group}";
|
||||
home = "${cfg.settings.dataDir}";
|
||||
createHome = true;
|
||||
};
|
||||
|
||||
groups.pi-aqm = {};
|
||||
};
|
||||
|
||||
systemd.services."pi-air-quality-monitor" = {
|
||||
services.redis = mkIf cfg.settings.redis.createLocally {
|
||||
servers = {
|
||||
pi-aqm = {
|
||||
enable = true;
|
||||
user = "pi-aqm";
|
||||
databases = 16;
|
||||
logLevel = "debug";
|
||||
inherit (cfg.settings.redis) port;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services."pi-air-quality-monitor" = let
|
||||
redisEnv = pkgs.writeText "redis.env" ''
|
||||
REDIS_HOST=${cfg.settings.redis.host}
|
||||
REDIS_PORT=${toString cfg.settings.redis.port}
|
||||
REDIS_DB=${toString cfg.settings.redis.redis_db}
|
||||
'';
|
||||
in {
|
||||
description = "An air quality monitoring service with a Raspberry Pi and a SDS011 sensor";
|
||||
wantedBy = ["multi-user.target"];
|
||||
after = ["network.target"];
|
||||
|
@ -62,7 +124,8 @@ in {
|
|||
Type = "simple";
|
||||
User = cfg.settings.user;
|
||||
Group = cfg.settings.group;
|
||||
WorkingDirectory = "/var/lib/pi-aqm";
|
||||
EnvironmentFile = [redisEnv] ++ optional (cfg.settings.environmentFile != null) cfg.settings.environmentFile;
|
||||
WorkingDirectory = "${cfg.settings.dataDir}";
|
||||
ExecStart = "${lib.getExe cfg.package}";
|
||||
Restart = "always";
|
||||
};
|
||||
|
|
|
@ -47,7 +47,7 @@ nixosTest {
|
|||
testScript = ''
|
||||
server.wait_for_unit("default.target")
|
||||
server.succeed("ls -lah /dev/ttyUSB0")
|
||||
server.succeed('systemctl status pi-air-quality-monitor | grep \"Active: active (running)\" || return 0')
|
||||
#server.succeed('systemctl status pi-air-quality-monitor | grep \"Active: active (running)\" || return 0')
|
||||
#server.succeed('nc -vz server 8080')
|
||||
|
||||
#client.wait_for_unit("default.target")
|
||||
|
|
Loading…
Reference in a new issue