Skip to content

Commit

Permalink
fix: Resurrect the docker-image NixOS test.
Browse files Browse the repository at this point in the history
Note: for some reason, we need to use `hostPkgs` in the NixOS config
wherever we want to use a Primer package (e.g., the Docker image), for
some reason I don't understand. It seems to have something to do with
the haskell.nix overlay, because other packages that are in our
overlay, but that don't rely on haskell.nix (e.g., `primer-sqitch`),
work fine from the `pkgs` set.
  • Loading branch information
dhess committed Jan 25, 2023
1 parent c1bed2e commit dfc4ca1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@
lib = (prev.lib or { }) // {
primer = (prev.lib.primer or { }) // {
defaultServicePort = 8081;
inherit version;
inherit postgres-dev-password;
inherit postgres-dev-base-url;
inherit postgres-dev-primer-url;
Expand Down Expand Up @@ -686,7 +687,7 @@
);

nixosModules.default = {
nixpkgs.overlays = [ inputs.self.overlays.default ];
nixpkgs.overlays = allOverlays;
};

hydraJobs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
, ...
}:
let
database_url = hostPkgs.lib.primer.databaseUrl;
port = toString hostPkgs.lib.primer.defaultPort;
dbPassword = "foopass";
dbUser = "primer";
dbName = "primer";
dbUrl = "postgres://${dbUser}:${dbPassword}@postgres:5432/${dbName}";

port = toString hostPkgs.lib.primer.defaultServicePort;
version = hostPkgs.lib.primer.version;
in
{
Expand All @@ -14,12 +18,12 @@ in
package = pkgs.postgresql;
enableTCPIP = true;
authentication = ''
hostnossl primer primer 192.168.0.0/16 md5
hostnossl ${dbName} ${dbUser} 192.168.0.0/16 md5
'';
initialScript = pkgs.writeText "postgresql-init.sql" ''
CREATE DATABASE primer TEMPLATE template0 ENCODING UTF8;
CREATE USER primer WITH PASSWORD 'foopass';
GRANT ALL PRIVILEGES ON DATABASE primer TO primer;
CREATE DATABASE ${dbName} TEMPLATE template0 ENCODING UTF8;
CREATE USER ${dbUser} WITH PASSWORD '${dbPassword}';
GRANT ALL PRIVILEGES ON DATABASE ${dbName} TO ${dbUser};
'';
};

Expand Down Expand Up @@ -58,12 +62,19 @@ in

virtualisation.oci-containers = {
containers.primer-service = {
image = "primer-service:${pkgs.primer-service-docker-image.imageTag}";
imageFile = pkgs.primer-service-docker-image;

# Note: we need to use `hostPkgs` here rather than `pkgs`,
# for some reason I don't understand. It seems to have
# something to do with the haskell.nix overlay, because
# other packages that are in our overlay, but don't rely
# on haskell.nix, work fine from `pkgs`.
image = "primer-service:${hostPkgs.primer-service-docker-image.imageTag}";
imageFile = hostPkgs.primer-service-docker-image;

ports = [ "${port}:${port}" ];
extraOptions = [ "--network=host" ];
environment = {
DATABASE_URL = database_url;
DATABASE_URL = dbUrl;
};
};
};
Expand Down Expand Up @@ -102,7 +113,7 @@ in
primer.systemctl("stop podman-primer-service.service")
postgres.succeed(
"primer-sqitch deploy --verify db:${database_url}"
"primer-sqitch deploy --verify db:${dbUrl}"
)
primer.systemctl("start podman-primer-service.service")
Expand All @@ -112,4 +123,7 @@ in
with subtest("version check"):
primer.succeed("primer-version-check")
'';

# Don't wait forever in the event of a problem.
meta.timeout = 600;
}

0 comments on commit dfc4ca1

Please sign in to comment.