From f80a40105a5aefd7d83bb58be4f8d0dee3f9ddda Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 27 Aug 2024 20:42:53 +0200 Subject: [PATCH] nixos/services.hydra: remove `with lib;` --- .../continuous-integration/hydra/default.nix | 121 +++++++++--------- 1 file changed, 59 insertions(+), 62 deletions(-) diff --git a/nixos/modules/services/continuous-integration/hydra/default.nix b/nixos/modules/services/continuous-integration/hydra/default.nix index ffee95fefc4b..6702cec1f4f2 100644 --- a/nixos/modules/services/continuous-integration/hydra/default.nix +++ b/nixos/modules/services/continuous-integration/hydra/default.nix @@ -1,7 +1,4 @@ { config, pkgs, lib, ... }: - -with lib; - let cfg = config.services.hydra; @@ -20,8 +17,8 @@ let { NIX_REMOTE = "daemon"; SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt"; # Remove in 16.03 PGPASSFILE = "${baseDir}/pgpass"; - NIX_REMOTE_SYSTEMS = concatStringsSep ":" cfg.buildMachinesFiles; - } // optionalAttrs (cfg.smtpHost != null) { + NIX_REMOTE_SYSTEMS = lib.concatStringsSep ":" cfg.buildMachinesFiles; + } // lib.optionalAttrs (cfg.smtpHost != null) { EMAIL_SENDER_TRANSPORT = "SMTP"; EMAIL_SENDER_TRANSPORT_host = cfg.smtpHost; } // hydraEnv // cfg.extraEnv; @@ -31,7 +28,7 @@ let XDG_CACHE_HOME = "${baseDir}/www/.cache"; COLUMNS = "80"; 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;"; @@ -39,7 +36,7 @@ let hydra-package = 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 { name = "hydra-env"; nativeBuildInputs = [ pkgs.makeWrapper ]; @@ -51,7 +48,7 @@ let fi mkdir -p "$out/bin" - for path in ${concatStringsSep " " paths}; do + for path in ${lib.concatStringsSep " " paths}; do if [ -d "$path/bin" ]; then cd "$path/bin" for prg in *; do @@ -75,16 +72,16 @@ in services.hydra = { - enable = mkOption { - type = types.bool; + enable = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to run Hydra services. ''; }; - dbi = mkOption { - type = types.str; + dbi = lib.mkOption { + type = lib.types.str; default = localDB; example = "dbi:Pg:dbname=hydra;host=postgres.example.org;user=foo;"; description = '' @@ -97,17 +94,17 @@ in ''; }; - package = mkPackageOption pkgs "hydra" { }; + package = lib.mkPackageOption pkgs "hydra" { }; - hydraURL = mkOption { - type = types.str; + hydraURL = lib.mkOption { + type = lib.types.str; description = '' The base URL for the Hydra webserver instance. Used for links in emails. ''; }; - listenHost = mkOption { - type = types.str; + listenHost = lib.mkOption { + type = lib.types.str; default = "*"; example = "localhost"; description = '' @@ -116,39 +113,39 @@ in ''; }; - port = mkOption { - type = types.port; + port = lib.mkOption { + type = lib.types.port; default = 3000; description = '' TCP port the web server should listen to. ''; }; - minimumDiskFree = mkOption { - type = types.int; + minimumDiskFree = lib.mkOption { + type = lib.types.int; default = 0; description = '' Threshold of minimum disk space (GiB) to determine if the queue runner should run or not. ''; }; - minimumDiskFreeEvaluator = mkOption { - type = types.int; + minimumDiskFreeEvaluator = lib.mkOption { + type = lib.types.int; default = 0; description = '' Threshold of minimum disk space (GiB) to determine if the evaluator should run or not. ''; }; - notificationSender = mkOption { - type = types.str; + notificationSender = lib.mkOption { + type = lib.types.str; description = '' Sender email address used for email notifications. ''; }; - smtpHost = mkOption { - type = types.nullOr types.str; + smtpHost = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = null; example = "localhost"; description = '' @@ -156,73 +153,73 @@ in ''; }; - tracker = mkOption { - type = types.str; + tracker = lib.mkOption { + type = lib.types.str; default = ""; description = '' Piece of HTML that is included on all pages. ''; }; - logo = mkOption { - type = types.nullOr types.path; + logo = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; description = '' Path to a file containing the logo of your Hydra instance. ''; }; - debugServer = mkOption { - type = types.bool; + debugServer = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether to run the server in debug mode."; }; - maxServers = mkOption { - type = types.int; + maxServers = lib.mkOption { + type = lib.types.int; default = 25; description = "Maximum number of starman workers to spawn."; }; - minSpareServers = mkOption { - type = types.int; + minSpareServers = lib.mkOption { + type = lib.types.int; default = 4; description = "Minimum number of spare starman workers to keep."; }; - maxSpareServers = mkOption { - type = types.int; + maxSpareServers = lib.mkOption { + type = lib.types.int; default = 5; description = "Maximum number of spare starman workers to keep."; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; description = "Extra lines for the Hydra configuration."; }; - extraEnv = mkOption { - type = types.attrsOf types.str; + extraEnv = lib.mkOption { + type = lib.types.attrsOf lib.types.str; default = {}; description = "Extra environment variables for Hydra."; }; - gcRootsDir = mkOption { - type = types.path; + gcRootsDir = lib.mkOption { + type = lib.types.path; default = "/nix/var/nix/gcroots/hydra"; description = "Directory that holds Hydra garbage collector roots."; }; - buildMachinesFiles = mkOption { - type = types.listOf types.path; - default = optional (config.nix.buildMachines != []) "/etc/nix/machines"; - defaultText = literalExpression ''optional (config.nix.buildMachines != []) "/etc/nix/machines"''; + buildMachinesFiles = lib.mkOption { + type = lib.types.listOf lib.types.path; + default = lib.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" ]; description = "List of files containing build machines."; }; - useSubstitutes = mkOption { - type = types.bool; + useSubstitutes = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to use binary caches for downloading store paths. Note that @@ -241,7 +238,7 @@ in ###### implementation - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ { assertion = cfg.maxServers != 0 && cfg.maxSpareServers != 0 && cfg.minSpareServers != 0; @@ -287,7 +284,7 @@ in base_uri = ${cfg.hydraURL} notification_sender = ${cfg.notificationSender} max_servers = ${toString cfg.maxServers} - ${optionalString (cfg.logo != null) '' + ${lib.optionalString (cfg.logo != null) '' hydra_logo = ${cfg.logo} ''} gc_roots_dir = ${cfg.gcRootsDir} @@ -298,14 +295,14 @@ in environment.variables = hydraEnv; - nix.settings = mkMerge [ + nix.settings = lib.mkMerge [ { keep-outputs = true; keep-derivations = true; 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 # has so many GC roots. @@ -316,8 +313,8 @@ in systemd.services.hydra-init = { wantedBy = [ "multi-user.target" ]; - requires = optional haveLocalDB "postgresql.service"; - after = optional haveLocalDB "postgresql.service"; + requires = lib.optional haveLocalDB "postgresql.service"; + after = lib.optional haveLocalDB "postgresql.service"; environment = env // { HYDRA_DBI = "${env.HYDRA_DBI};application_name=hydra-init"; }; @@ -340,7 +337,7 @@ in ${baseDir}/build-logs \ ${baseDir}/runcommand-logs - ${optionalString haveLocalDB '' + ${lib.optionalString haveLocalDB '' 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/createdb -- -O hydra hydra @@ -388,7 +385,7 @@ in { ExecStart = "@${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} " - + "--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"; PermissionsStartOnly = true; Restart = "always"; @@ -514,9 +511,9 @@ in 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-queue-runner hydra @@ -526,7 +523,7 @@ in hydra-users postgres postgres ''; - services.postgresql.authentication = optionalString haveLocalDB + services.postgresql.authentication = lib.optionalString haveLocalDB '' local hydra all ident map=hydra-users '';