Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@
};

registry =
{ lib, modulesPath, ... }:
{
lib,
modulesPath,
pkgs,
...
}:
let
host = "registry.purescript.org";
in
Expand All @@ -283,9 +288,9 @@
# the state directory, unless there are viable defaults.
inherit
DHALL_PRELUDE
DHALL_TYPES
GIT_TERMINAL_PROMPT
;
DHALL_TYPES = "${pkgs.registry-server}/bin/types";
};
};
system.stateVersion = "24.05";
Expand Down
7 changes: 6 additions & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,12 @@ in
description = "PureScript Registry API server";
src = ../app;
spagoLock = app;
extraInstall = "cp -r ${../db} $out/bin/db";
# Keep runtime schemas in the server closure rather than relying on a
# separately referenced source path in the deployed environment.
extraInstall = ''
cp -r ${../db} $out/bin/db
cp -r ${../types} $out/bin/types
'';
}) { };

registry-github-importer = prev.callPackage (buildRegistryPackage {
Expand Down
4 changes: 3 additions & 1 deletion nix/registry-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ let
mkdir -p ${cfg.stateDir}/db

set -o allexport
source ${envFile}
[ -f ${cfg.stateDir}/.env ] && source ${cfg.stateDir}/.env
# Deployment-managed values must override state-dir values. Otherwise a
# stale non-secret setting such as DHALL_TYPES can survive a deployment.
source ${envFile}
set +o allexport

export DATABASE_URL="sqlite:${cfg.stateDir}/db/registry.sqlite3"
Expand Down
11 changes: 11 additions & 0 deletions nix/test/smoke.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ else
envVars = testConfig.testEnv;
stateDir = "/var/lib/registry-server";
repoFixturesDir = "${stateDir}/repo-fixtures";
dhallTypes = "${pkgs.registry-server}/bin/types";
in
pkgs.testers.nixosTest {
name = "registry-smoke";
Expand Down Expand Up @@ -61,6 +62,13 @@ else
# Check that the service is still running (didn't crash)
registry.succeed("systemctl is-active server.service")

# A stale state-dir value must not override deployment-managed schema paths.
pid = registry.succeed("systemctl show --value --property MainPID server.service").strip()
registry.succeed(
f"tr '\\0' '\\n' < /proc/{pid}/environ | grep -Fx 'DHALL_TYPES=${dhallTypes}'"
)
registry.succeed("test -f ${dhallTypes}/v1/Manifest.dhall")

# Give the job executor a moment to start and potentially fail
time.sleep(2)

Expand Down Expand Up @@ -96,6 +104,8 @@ else
RemainAfterExit = true;
};
script = ''
mkdir -p ${stateDir}
echo 'DHALL_TYPES=/defunct/types' > ${stateDir}/.env
${testConfig.setupGitFixtures}/bin/setup-git-fixtures ${repoFixturesDir}
'';
};
Expand All @@ -108,6 +118,7 @@ else
inherit stateDir;
envVars = envVars // {
REPO_FIXTURES_DIR = repoFixturesDir;
DHALL_TYPES = dhallTypes;
};
};
};
Expand Down