From 847ed4ef131bc6e6abca7170ec60dfe1bdd41ac1 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 24 May 2023 08:24:33 +0100 Subject: [PATCH] nixos/syndicate-server: use a static configuration Configure the server with a configuration path that points into the Nix store rather than a file that is generated at start-up. --- flake.nix | 22 +++++++++++++++++++--- nixos/syndicate-server.nix | 32 +++++++++++++++----------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index e22ca18..3bef55a 100644 --- a/flake.nix +++ b/flake.nix @@ -90,9 +90,25 @@ with import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; pkgs = pkgs'; - }; - { - # nothing here + }; { + simple = simpleTest { + name = "http"; + nodes.machine = { config, pkgs, ... }: { + imports = [ self.nixosModules.syndicate-server ]; + + nixpkgs.pkgs = pkgs'; + + services.syndicate.tty1 = { + enable = true; + user = "loser"; + config = [ ]; + }; + users.users.loser.isNormalUser = true; + }; + testScript = '' + machine.wait_for_job("syndicate-tty1") + ''; + }; }) { inherit (self.legacyPackages) x86_64-linux; }; }; } diff --git a/nixos/syndicate-server.nix b/nixos/syndicate-server.nix index 7d11e8c..0777764 100644 --- a/nixos/syndicate-server.nix +++ b/nixos/syndicate-server.nix @@ -49,31 +49,23 @@ with lib; config = { systemd.services = let - serverCfgs = - lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.syndicate; - in builtins.listToAttrs (lib.lists.flatten (lib.attrsets.mapAttrsToList - (name: cfg: + configure = name: cfg: let - configFileName = "syndicate-nixos-config.pr"; - runtimeConfig = "\${RUNTIME_DIRECTORY}/${configFileName}"; - configFile = pkgs.writeText configFileName + configFile = lib.pipe cfg.config [ (lib.strings.concatMapStrings (dir: '' > - '') cfg.config); + '')) + (pkgs.writeText "syndicate-nixos-config.pr") + ]; in [{ name = "syndicate-${name}"; value = let - serviceConfig = let - loadConfig = - "${pkgs.coreutils}/bin/cp ${configFile} ${runtimeConfig}"; - in { + serviceConfig = { RuntimeDirectory = name; - ExecStartPre = loadConfig; ExecStart = "${ lib.optionalString cfg.runInDbusSession "${pkgs.dbus}/bin/dbus-run-session " - }${cfg.package}/bin/syndicate-server --no-banner --config ${runtimeConfig}"; - ExecReload = loadConfig; + }${cfg.package}/bin/syndicate-server --no-banner --config ${configFile}"; User = cfg.user; }; in { @@ -106,8 +98,14 @@ with lib; WorkingDirectory = "~"; }; }); - }]) (lib.attrsets.filterAttrs (_: cfg: cfg.enable) - config.services.syndicate))); + }]; + serverCfgs = + lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.syndicate; + in lib.pipe serverCfgs [ + (lib.attrsets.mapAttrsToList configure) + lib.lists.flatten + builtins.listToAttrs + ]; systemd.targets.multi-user.wants = lib.lists.flatten (lib.attrsets.mapAttrsToList