diff --git a/nix/module.nix b/nix/module.nix index 224c29c..494335b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -112,6 +112,10 @@ in { }; systemd.services."pi-air-quality-monitor" = let + globalEnv = pkgs.writeText "global.env" '' + SERIAL_DEVICE=${cfg.settings.serialPort} + ''; + redisEnv = pkgs.writeText "redis.env" '' REDIS_HOST=${cfg.settings.redis.host} REDIS_PORT=${toString cfg.settings.redis.port} @@ -125,7 +129,11 @@ in { Type = "simple"; User = cfg.settings.user; Group = cfg.settings.group; - EnvironmentFile = [redisEnv] ++ optional (cfg.settings.environmentFile != null) cfg.settings.environmentFile; + EnvironmentFile = lib.concatLists [ + [globalEnv] + (optional (cfg.settings.environmentFile != null) [cfg.settings.environmentFile]) + (optional cfg.settings.redis.createLocally [redisEnv]) + ]; WorkingDirectory = "${cfg.settings.dataDir}"; ExecStart = "${lib.getExe cfg.package}"; Restart = "always"; diff --git a/nix/tests/checks/basic.nix b/nix/tests/checks/basic.nix index 745c0c1..5370156 100644 --- a/nix/tests/checks/basic.nix +++ b/nix/tests/checks/basic.nix @@ -57,18 +57,17 @@ in log.info("Check if unit is running correctly") server.wait_for_unit("pi-air-quality-monitor.service") server.succeed("systemctl status pi-air-quality-monitor.service | grep 'Active: active (running)' >&2") - server.succeed("journalctl -u pi-air-quality-monitor.service >&2") + server.fail("journalctl -u pi-air-quality-monitor.service | grep 'RuntimeError'") log.info("Showing units content") server.succeed("systemctl status pi-air-quality-monitor.service >&2") server.succeed("systemctl cat pi-air-quality-monitor.service >&2") - server.succeed("systemctl cat pi-air-quality-monitor.socket >&2") log.info("Checking if service is accessible locally") server.succeed("nc -vz localhost 8080") client.start() client.wait_for_unit("default.target") - #client.succeed("nc -vz server 8080") + client.succeed("nc -vz server 8080") ''; }