From 8e5b6624b364d81cabfe15630d2a866840a71f80 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Mon, 27 Nov 2023 17:27:18 +0200 Subject: [PATCH] Synit: implement test module --- nixproc/backends/synit/build-synit-env.nix | 11 ++++-- .../backends/synit/test-module/default.nix | 30 +++++++++++++++ .../test-module/nixos-syndicate-server.nix | 38 +++++++++++++++++++ nixproc/test-driver/universal.nix | 1 + tools/synit/nixproc-synit-deploy.in | 16 +++++++- 5 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 nixproc/backends/synit/test-module/default.nix create mode 100644 nixproc/backends/synit/test-module/nixos-syndicate-server.nix diff --git a/nixproc/backends/synit/build-synit-env.nix b/nixproc/backends/synit/build-synit-env.nix index 7f557da..14fb480 100644 --- a/nixproc/backends/synit/build-synit-env.nix +++ b/nixproc/backends/synit/build-synit-env.nix @@ -15,7 +15,10 @@ let (args // { processManager = "synit"; } // extraParams); processes = if exprFile == null then { } else processesFun processesArgs; -in pkgs.buildEnv { - name = "synit"; - paths = map (builtins.getAttr "pkg") (builtins.attrValues processes); -} +in pkgs.runCommand "synit-processes.pr" { + nativeBuildInputs = [ pkgs.preserves-tools ]; + env.config_inputs = + pkgs.lib.strings.concatMapStringsSep " " (builtins.getAttr "pkg") (builtins.attrValues processes); +} '' + cat $(find $config_inputs -name '*.pr') | preserves-tool convert > "$out" +'' diff --git a/nixproc/backends/synit/test-module/default.nix b/nixproc/backends/synit/test-module/default.nix new file mode 100644 index 0000000..fb55ef7 --- /dev/null +++ b/nixproc/backends/synit/test-module/default.nix @@ -0,0 +1,30 @@ +{ profileSettings, exprFile, extraParams, tools, pkgs, system }: + +let + executeDeploy = + import ../../../test-driver/util/execute-deploy.nix { inherit (pkgs) lib; }; + + processesEnvSystem = import ../build-synit-env.nix + ({ inherit pkgs system exprFile extraParams; } // profileSettings.params); +in { + inherit (profileSettings) params; + + nixosModules = [ ./nixos-syndicate-server.nix ]; + + systemPackages = [ tools.synit ]; + + additionalPaths = [ processesEnvSystem ]; + + deployProcessManager = ""; + + deploySystem = '' + machine.wait_for_unit("syndicate-server.service") + machine.succeed("${ + executeDeploy { + inherit profileSettings; + processManager = "synit"; + processesEnv = processesEnvSystem; + } + }") + ''; +} diff --git a/nixproc/backends/synit/test-module/nixos-syndicate-server.nix b/nixproc/backends/synit/test-module/nixos-syndicate-server.nix new file mode 100644 index 0000000..83c79c1 --- /dev/null +++ b/nixproc/backends/synit/test-module/nixos-syndicate-server.nix @@ -0,0 +1,38 @@ +{ lib, pkgs, ... }: + +let + syndicate-server = pkgs.syndicate-server or (let + repo = builtins.fetchTarball + "https://git.syndicate-lang.org/ehmry/syndicate-flake/archive/trunk.tar.gz"; + pkgs' = import repo { inherit pkgs; }; + in pkgs'.syndicate-server); + + synit = pkgs.fetchFromGitea { + domain = "git.syndicate-lang.org"; + owner = "synit"; + repo = "synit"; + rev = "a2ecd8a4e441f8622a57a99987cb0aa5be9e1dcd"; + hash = "sha256-M79AJ8/Synzm4CYkt3+GYViJLJcuYBW+x32Vfy+oFUM="; + }; + +in { + systemd.services.syndicate-server = { + description = "Syndicate dataspace server"; + wantedBy = [ "basic.target" ]; + preStart = '' + mkdir -p "/etc/syndicate/services" + ${lib.getExe pkgs.rsync} -r \ + --exclude 001-console-getty.pr \ + --exclude configdirs.pr \ + --exclude eudev.pr \ + --exclude hostname.pr \ + --exclude services \ + "${synit}/packaging/packages/synit-config/files/etc/syndicate/" \ + "/etc/syndicate" + ''; + serviceConfig = { + ExecStart = + "${lib.getExe syndicate-server} --no-banner --config /etc/syndicate"; + }; + }; +} diff --git a/nixproc/test-driver/universal.nix b/nixproc/test-driver/universal.nix index f047fbf..2ddc0ad 100644 --- a/nixproc/test-driver/universal.nix +++ b/nixproc/test-driver/universal.nix @@ -10,6 +10,7 @@ import ./agnostic.nix { docker = ../backends/docker/test-module; s6-rc = ../backends/s6-rc/test-module; supervisord = ../backends/supervisord/test-module; + synit = ../backends/synit/test-module; systemd = ../backends/systemd/test-module; sysvinit = ../backends/sysvinit/test-module; }; diff --git a/tools/synit/nixproc-synit-deploy.in b/tools/synit/nixproc-synit-deploy.in index aeafae9..af89790 100644 --- a/tools/synit/nixproc-synit-deploy.in +++ b/tools/synit/nixproc-synit-deploy.in @@ -122,7 +122,21 @@ checkNixStateDir checkProfile composeOldProfilePath -# TODO +if [ "$profilePath" = "" ] +then + echo "No profile path was provided!" >&2 + exit 1 +fi + +# Initialize all state + +nixproc-init-state $stateDirArg $runtimeDirArg $logDirArg $tmpDirArg $cacheDirArg $spoolDirArg $lockDirArg $libDirArg $forceDisableUserChangeArg + +# Create new groups and users +createNewGroups +createNewUsers + +cp -v $profilePath /etc/syndicate/services/processes.pr # Delete obsolete users and groups deleteObsoleteUsers