0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/services.hydra: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-27 20:42:53 +02:00
parent 3e0f69b8c9
commit f80a40105a

View file

@ -1,7 +1,4 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
with lib;
let let
cfg = config.services.hydra; cfg = config.services.hydra;
@ -20,8 +17,8 @@ let
{ NIX_REMOTE = "daemon"; { NIX_REMOTE = "daemon";
SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt"; # Remove in 16.03 SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt"; # Remove in 16.03
PGPASSFILE = "${baseDir}/pgpass"; PGPASSFILE = "${baseDir}/pgpass";
NIX_REMOTE_SYSTEMS = concatStringsSep ":" cfg.buildMachinesFiles; NIX_REMOTE_SYSTEMS = lib.concatStringsSep ":" cfg.buildMachinesFiles;
} // optionalAttrs (cfg.smtpHost != null) { } // lib.optionalAttrs (cfg.smtpHost != null) {
EMAIL_SENDER_TRANSPORT = "SMTP"; EMAIL_SENDER_TRANSPORT = "SMTP";
EMAIL_SENDER_TRANSPORT_host = cfg.smtpHost; EMAIL_SENDER_TRANSPORT_host = cfg.smtpHost;
} // hydraEnv // cfg.extraEnv; } // hydraEnv // cfg.extraEnv;
@ -31,7 +28,7 @@ let
XDG_CACHE_HOME = "${baseDir}/www/.cache"; XDG_CACHE_HOME = "${baseDir}/www/.cache";
COLUMNS = "80"; COLUMNS = "80";
PGPASSFILE = "${baseDir}/pgpass-www"; # grrr PGPASSFILE = "${baseDir}/pgpass-www"; # grrr
} // (optionalAttrs cfg.debugServer { DBIC_TRACE = "1"; }); } // (lib.optionalAttrs cfg.debugServer { DBIC_TRACE = "1"; });
localDB = "dbi:Pg:dbname=hydra;user=hydra;"; localDB = "dbi:Pg:dbname=hydra;user=hydra;";
@ -39,7 +36,7 @@ let
hydra-package = hydra-package =
let let
makeWrapperArgs = concatStringsSep " " (mapAttrsToList (key: value: "--set-default \"${key}\" \"${value}\"") hydraEnv); makeWrapperArgs = lib.concatStringsSep " " (lib.mapAttrsToList (key: value: "--set-default \"${key}\" \"${value}\"") hydraEnv);
in pkgs.buildEnv rec { in pkgs.buildEnv rec {
name = "hydra-env"; name = "hydra-env";
nativeBuildInputs = [ pkgs.makeWrapper ]; nativeBuildInputs = [ pkgs.makeWrapper ];
@ -51,7 +48,7 @@ let
fi fi
mkdir -p "$out/bin" mkdir -p "$out/bin"
for path in ${concatStringsSep " " paths}; do for path in ${lib.concatStringsSep " " paths}; do
if [ -d "$path/bin" ]; then if [ -d "$path/bin" ]; then
cd "$path/bin" cd "$path/bin"
for prg in *; do for prg in *; do
@ -75,16 +72,16 @@ in
services.hydra = { services.hydra = {
enable = mkOption { enable = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to run Hydra services. Whether to run Hydra services.
''; '';
}; };
dbi = mkOption { dbi = lib.mkOption {
type = types.str; type = lib.types.str;
default = localDB; default = localDB;
example = "dbi:Pg:dbname=hydra;host=postgres.example.org;user=foo;"; example = "dbi:Pg:dbname=hydra;host=postgres.example.org;user=foo;";
description = '' description = ''
@ -97,17 +94,17 @@ in
''; '';
}; };
package = mkPackageOption pkgs "hydra" { }; package = lib.mkPackageOption pkgs "hydra" { };
hydraURL = mkOption { hydraURL = lib.mkOption {
type = types.str; type = lib.types.str;
description = '' description = ''
The base URL for the Hydra webserver instance. Used for links in emails. The base URL for the Hydra webserver instance. Used for links in emails.
''; '';
}; };
listenHost = mkOption { listenHost = lib.mkOption {
type = types.str; type = lib.types.str;
default = "*"; default = "*";
example = "localhost"; example = "localhost";
description = '' description = ''
@ -116,39 +113,39 @@ in
''; '';
}; };
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 3000; default = 3000;
description = '' description = ''
TCP port the web server should listen to. TCP port the web server should listen to.
''; '';
}; };
minimumDiskFree = mkOption { minimumDiskFree = lib.mkOption {
type = types.int; type = lib.types.int;
default = 0; default = 0;
description = '' description = ''
Threshold of minimum disk space (GiB) to determine if the queue runner should run or not. Threshold of minimum disk space (GiB) to determine if the queue runner should run or not.
''; '';
}; };
minimumDiskFreeEvaluator = mkOption { minimumDiskFreeEvaluator = lib.mkOption {
type = types.int; type = lib.types.int;
default = 0; default = 0;
description = '' description = ''
Threshold of minimum disk space (GiB) to determine if the evaluator should run or not. Threshold of minimum disk space (GiB) to determine if the evaluator should run or not.
''; '';
}; };
notificationSender = mkOption { notificationSender = lib.mkOption {
type = types.str; type = lib.types.str;
description = '' description = ''
Sender email address used for email notifications. Sender email address used for email notifications.
''; '';
}; };
smtpHost = mkOption { smtpHost = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "localhost"; example = "localhost";
description = '' description = ''
@ -156,73 +153,73 @@ in
''; '';
}; };
tracker = mkOption { tracker = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
description = '' description = ''
Piece of HTML that is included on all pages. Piece of HTML that is included on all pages.
''; '';
}; };
logo = mkOption { logo = lib.mkOption {
type = types.nullOr types.path; type = lib.types.nullOr lib.types.path;
default = null; default = null;
description = '' description = ''
Path to a file containing the logo of your Hydra instance. Path to a file containing the logo of your Hydra instance.
''; '';
}; };
debugServer = mkOption { debugServer = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Whether to run the server in debug mode."; description = "Whether to run the server in debug mode.";
}; };
maxServers = mkOption { maxServers = lib.mkOption {
type = types.int; type = lib.types.int;
default = 25; default = 25;
description = "Maximum number of starman workers to spawn."; description = "Maximum number of starman workers to spawn.";
}; };
minSpareServers = mkOption { minSpareServers = lib.mkOption {
type = types.int; type = lib.types.int;
default = 4; default = 4;
description = "Minimum number of spare starman workers to keep."; description = "Minimum number of spare starman workers to keep.";
}; };
maxSpareServers = mkOption { maxSpareServers = lib.mkOption {
type = types.int; type = lib.types.int;
default = 5; default = 5;
description = "Maximum number of spare starman workers to keep."; description = "Maximum number of spare starman workers to keep.";
}; };
extraConfig = mkOption { extraConfig = lib.mkOption {
type = types.lines; type = lib.types.lines;
description = "Extra lines for the Hydra configuration."; description = "Extra lines for the Hydra configuration.";
}; };
extraEnv = mkOption { extraEnv = lib.mkOption {
type = types.attrsOf types.str; type = lib.types.attrsOf lib.types.str;
default = {}; default = {};
description = "Extra environment variables for Hydra."; description = "Extra environment variables for Hydra.";
}; };
gcRootsDir = mkOption { gcRootsDir = lib.mkOption {
type = types.path; type = lib.types.path;
default = "/nix/var/nix/gcroots/hydra"; default = "/nix/var/nix/gcroots/hydra";
description = "Directory that holds Hydra garbage collector roots."; description = "Directory that holds Hydra garbage collector roots.";
}; };
buildMachinesFiles = mkOption { buildMachinesFiles = lib.mkOption {
type = types.listOf types.path; type = lib.types.listOf lib.types.path;
default = optional (config.nix.buildMachines != []) "/etc/nix/machines"; default = lib.optional (config.nix.buildMachines != []) "/etc/nix/machines";
defaultText = literalExpression ''optional (config.nix.buildMachines != []) "/etc/nix/machines"''; defaultText = lib.literalExpression ''lib.optional (config.nix.buildMachines != []) "/etc/nix/machines"'';
example = [ "/etc/nix/machines" "/var/lib/hydra/provisioner/machines" ]; example = [ "/etc/nix/machines" "/var/lib/hydra/provisioner/machines" ];
description = "List of files containing build machines."; description = "List of files containing build machines.";
}; };
useSubstitutes = mkOption { useSubstitutes = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Whether to use binary caches for downloading store paths. Note that Whether to use binary caches for downloading store paths. Note that
@ -241,7 +238,7 @@ in
###### implementation ###### implementation
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = cfg.maxServers != 0 && cfg.maxSpareServers != 0 && cfg.minSpareServers != 0; assertion = cfg.maxServers != 0 && cfg.maxSpareServers != 0 && cfg.minSpareServers != 0;
@ -287,7 +284,7 @@ in
base_uri = ${cfg.hydraURL} base_uri = ${cfg.hydraURL}
notification_sender = ${cfg.notificationSender} notification_sender = ${cfg.notificationSender}
max_servers = ${toString cfg.maxServers} max_servers = ${toString cfg.maxServers}
${optionalString (cfg.logo != null) '' ${lib.optionalString (cfg.logo != null) ''
hydra_logo = ${cfg.logo} hydra_logo = ${cfg.logo}
''} ''}
gc_roots_dir = ${cfg.gcRootsDir} gc_roots_dir = ${cfg.gcRootsDir}
@ -298,14 +295,14 @@ in
environment.variables = hydraEnv; environment.variables = hydraEnv;
nix.settings = mkMerge [ nix.settings = lib.mkMerge [
{ {
keep-outputs = true; keep-outputs = true;
keep-derivations = true; keep-derivations = true;
trusted-users = [ "hydra-queue-runner" ]; trusted-users = [ "hydra-queue-runner" ];
} }
(mkIf (versionOlder (getVersion config.nix.package.out) "2.4pre") (lib.mkIf (lib.versionOlder (lib.getVersion config.nix.package.out) "2.4pre")
{ {
# The default (`true') slows Nix down a lot since the build farm # The default (`true') slows Nix down a lot since the build farm
# has so many GC roots. # has so many GC roots.
@ -316,8 +313,8 @@ in
systemd.services.hydra-init = systemd.services.hydra-init =
{ wantedBy = [ "multi-user.target" ]; { wantedBy = [ "multi-user.target" ];
requires = optional haveLocalDB "postgresql.service"; requires = lib.optional haveLocalDB "postgresql.service";
after = optional haveLocalDB "postgresql.service"; after = lib.optional haveLocalDB "postgresql.service";
environment = env // { environment = env // {
HYDRA_DBI = "${env.HYDRA_DBI};application_name=hydra-init"; HYDRA_DBI = "${env.HYDRA_DBI};application_name=hydra-init";
}; };
@ -340,7 +337,7 @@ in
${baseDir}/build-logs \ ${baseDir}/build-logs \
${baseDir}/runcommand-logs ${baseDir}/runcommand-logs
${optionalString haveLocalDB '' ${lib.optionalString haveLocalDB ''
if ! [ -e ${baseDir}/.db-created ]; then if ! [ -e ${baseDir}/.db-created ]; then
runuser -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createuser hydra runuser -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createuser hydra
runuser -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -- -O hydra hydra runuser -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -- -O hydra hydra
@ -388,7 +385,7 @@ in
{ ExecStart = { ExecStart =
"@${hydra-package}/bin/hydra-server hydra-server -f -h '${cfg.listenHost}' " "@${hydra-package}/bin/hydra-server hydra-server -f -h '${cfg.listenHost}' "
+ "-p ${toString cfg.port} --min_spare_servers ${toString cfg.minSpareServers} --max_spare_servers ${toString cfg.maxSpareServers} " + "-p ${toString cfg.port} --min_spare_servers ${toString cfg.minSpareServers} --max_spare_servers ${toString cfg.maxSpareServers} "
+ "--max_servers ${toString cfg.maxServers} --max_requests 100 ${optionalString cfg.debugServer "-d"}"; + "--max_servers ${toString cfg.maxServers} --max_requests 100 ${lib.optionalString cfg.debugServer "-d"}";
User = "hydra-www"; User = "hydra-www";
PermissionsStartOnly = true; PermissionsStartOnly = true;
Restart = "always"; Restart = "always";
@ -514,9 +511,9 @@ in
startAt = "Sun 01:45"; startAt = "Sun 01:45";
}; };
services.postgresql.enable = mkIf haveLocalDB true; services.postgresql.enable = lib.mkIf haveLocalDB true;
services.postgresql.identMap = optionalString haveLocalDB services.postgresql.identMap = lib.optionalString haveLocalDB
'' ''
hydra-users hydra hydra hydra-users hydra hydra
hydra-users hydra-queue-runner hydra hydra-users hydra-queue-runner hydra
@ -526,7 +523,7 @@ in
hydra-users postgres postgres hydra-users postgres postgres
''; '';
services.postgresql.authentication = optionalString haveLocalDB services.postgresql.authentication = lib.optionalString haveLocalDB
'' ''
local hydra all ident map=hydra-users local hydra all ident map=hydra-users
''; '';