Browse Source

Perhaps finalize HydraCI

Signed-off-by: Magic_RB <magic_rb@redalder.org>
master
Magic_RB 2 weeks ago
parent
commit
b9db7035cd
Signed by: Magic_RB GPG Key ID: 08D5287CC5DDCA0E
3 changed files with 46 additions and 9 deletions
  1. +4
    -0
      examples/hydra/default.nix
  2. +19
    -2
      modules/services/hydra.nix
  3. +23
    -7
      modules/services/postgresql.nix

+ 4
- 0
examples/hydra/default.nix View File

@ -26,6 +26,10 @@ nglib:
useSubstitutes = true;
};
services.postgresql.package = pkgs.postgresql_12;
services.socklog = {
enable = true;
unix = "/dev/log";
};
};
}
);


+ 19
- 2
modules/services/hydra.nix View File

@ -353,6 +353,9 @@ in
hydra-update-gc-roots = pkgs.writeShellScript "hydra-update-gc-roots"
''
sv -c -w 0 once hydra-init
while [[ ! -e ${baseDir}/.init-hydra ]]; do
sleep 1
done
${hydra-package}/bin/hydra-update-gc-roots hydra-update-gc-roots
'';
@ -369,10 +372,16 @@ in
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then
echo "stopping Hydra queue runner due to lack of free space..."
sv stop hydra-queue-runner
elif [ $(sv status hydra-queue-runner) -eq "up" ]; then
echo "restarting Hydra queue runner"
sv start hydra-queue-runner
fi
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFreeEvaluator} * 1024**3)) ]; then
echo "stopping Hydra evaluator due to lack of free space..."
sv stop hydra-evaluator
elif [ $(sv status hydra-evaluator) -eq "up" ]; then
echo "stopping Hydra evaluator"
sv start hydra-evaluator
fi
'';
hydra-compress-logs = pkgs.writeShellScript "hydra-compress-logs"
@ -394,6 +403,8 @@ in
hydra-init = {
environment = env;
script = pkgs.writeShellScript "hydra-init" ''
[[ -e ${baseDir}/.init-hydra ]] && exit 0
mkdir -p ${baseDir}
chown hydra.hydra ${baseDir}
chmod 0750 ${baseDir}
@ -412,7 +423,8 @@ in
chown hydra.hydra ${cfg.gcRootsDir}
export PATH=${pkgs.nettools}/bin:$PATH # Hydra runs some variant of `hostname --fqdn`, which BusyBox doesn't support
HOME=~hydra exec chpst -u hydra:hydra ${hydra-package}/bin/hydra-init
HOME=~hydra chpst -u hydra:hydra ${hydra-package}/bin/hydra-init || exit 1
touch ${baseDir}/.init-hydra
'';
};
@ -426,6 +438,7 @@ in
pwd = "${baseDir}/queue-runner";
script = pkgs.writeShellScript "hydra-server" ''
sv -v -w 0 once hydra-init
[[ ! -e ${baseDir}/.init-hydra ]] && exit 1
export PATH=${pkgs.nettools}/bin:$PATH # Hydra runs some variant of `hostname --fqdn`, which BusyBox doesn't support
HOME=~hydra-www exec chpst -b hydra-server -u hydra-www:hydra ${hydraCmd}
@ -444,6 +457,7 @@ in
export PATH=${makeBinPath [ hydra-package pkgs.nettools pkgs.openssh pkgs.bzip2 config.nix.package ]}:$PATH
sv -v -w 0 once hydra-init
[[ ! -e ${baseDir}/.init-hydra ]] && exit 1
export PATH=${pkgs.nettools}/bin:$PATH # Hydra runs some variant of `hostname --fqdn`, which BusyBox doesn't support
@ -461,6 +475,7 @@ in
export PATH=${with pkgs; makeBinPath [ hydra-package nettools jq ]}:$PATH
sv -v -w 0 once hydra-init
[[ ! -e ${baseDir}/.init-hydra ]] && exit 1
export PATH=${pkgs.nettools}/bin:$PATH # Hydra runs some variant of `hostname --fqdn`, which BusyBox doesn't support
HOME=~hydra exec chpst -b hydra-evaluator -u hydra:hydra ${hydra-package}/bin/hydra-evaluator
@ -491,7 +506,9 @@ in
# -- END MIT LICENSED CODE
services.postgresql.ensureDatabases = mkIf haveLocalDB [ "hydra" ];
services.postgresql.ensureExtensions = mkIf haveLocalDB {
"pg_trgm" = [ "hydra" ];
};
services.postgresql.ensureUsers = mkIf haveLocalDB [
{ name = "hydra"; ensurePermissions = {
"DATABASE \"hydra\"" = "ALL PRIVILEGES";


+ 23
- 7
modules/services/postgresql.nix View File

@ -143,6 +143,17 @@ in
'';
};
ensureExtensions = mkOption {
type = with types; attrsOf (listOf str);
default = {};
description = ''
Ensure that the specified extensions exist.
'';
example = {
"pg_trgm" = [ "hydra" ];
};
};
ensureDatabases = mkOption {
type = types.listOf types.str;
default = [];
@ -377,7 +388,7 @@ in
PSQL="chpst -u postgres:postgres ${cfg.package}/bin/psql --port=${cfg.port}"
while ! $PSQL -d postgres -c "" 2> /dev/null ; do
if ! kill -0 "$postgresql"; then echo aaaa; exit 1; fi
if ! kill -0 "$postgresql"; then exit 1; fi
sleep 0.1
done
@ -388,10 +399,9 @@ in
rm -f "${cfg.dataDir}/.first_startup"
fi
${optionalString (cfg.ensureDatabases != []) ''
${concatMapStrings (database: ''
$PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${database}'" | grep -q 1 || $PSQL -tAc 'CREATE DATABASE "${database}"'
'') cfg.ensureDatabases} ''}
${concatMapStrings (database: ''
$PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${database}'" | grep -q 1 || $PSQL -tAc 'CREATE DATABASE "${database}"'
'') cfg.ensureDatabases}
${concatMapStrings (user: ''
$PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname='${user.name}'" | grep -q 1 || $PSQL -tAc 'CREATE USER "${user.name}"'
@ -400,10 +410,16 @@ in
'') user.ensurePermissions)}
'') cfg.ensureUsers}
${concatStrings (mapAttrsToList (extension: schemas:
concatMapStrings (schema:
''
$PSQL -tAc "create extension if not exists ${extension}" ${schema}
''
) schemas
) cfg.ensureExtensions)}
wait $postgresql
'';
# '' + + ''
# -- END MIT LICENSED CODE
enabled = true;


Loading…
Cancel
Save