dotfiles/modules/nixos/services/hydra/default.nix

109 lines
2.7 KiB
Nix
Raw Normal View History

2024-03-02 18:06:18 +00:00
{
config,
lib,
...
2024-06-01 07:44:46 +00:00
}: let
2024-03-02 18:06:18 +00:00
cfg = config.aa.services.hydra;
in {
2024-06-01 07:44:46 +00:00
options.aa.services.hydra = with lib; {
2024-03-02 18:06:18 +00:00
enable = mkEnableOption "hydra";
2024-03-06 04:03:34 +00:00
hostname = mkOption {
2024-06-01 07:44:46 +00:00
type = types.str;
2024-03-06 04:03:34 +00:00
default = "hydra.kilonull.com";
description = ''
The hostname for the hydra instance
'';
};
acmeCertName = mkOption {
2024-06-01 07:44:46 +00:00
type = types.str;
2024-03-06 04:03:34 +00:00
default = "";
description = ''
If set to a non-empty string, forces SSL with the supplied acme
certificate.
'';
};
2024-03-10 21:28:44 +00:00
secretKeyPath = mkOption {
2024-06-01 07:44:46 +00:00
type = types.str;
2024-03-10 21:28:44 +00:00
description = ''
The secret key used to sign builds uploaded to s3.
'';
};
s3Bucket = mkOption {
2024-06-01 07:44:46 +00:00
type = types.str;
2024-03-10 21:28:44 +00:00
description = ''
The s3 bucket name where build artifacts will be uploaded.
'';
};
s3Scheme = mkOption {
2024-06-01 07:44:46 +00:00
type = types.str;
2024-03-10 21:28:44 +00:00
default = "https";
description = ''
The scheme to use when connecting to s3.
'';
};
s3Endpoint = mkOption {
2024-06-01 07:44:46 +00:00
type = types.str;
2024-03-10 21:28:44 +00:00
description = ''
The s3 server endpoint.
Should use `amazonaws.com` if using amazon AWS.
'';
};
2024-03-02 18:06:18 +00:00
};
2024-06-01 07:44:46 +00:00
config = lib.mkIf cfg.enable {
2024-03-10 21:28:44 +00:00
age.secrets = {
hydra-aws-creds.file = ../../../../secrets/hydra-aws-creds.age;
};
2024-03-02 18:06:18 +00:00
# NOTE: Need to create user to allow web configuration
# sudo -u hydra hydra-create-user alice \
# --full-name 'Alice Q. User' \
# --email-address 'alice@example.org' \
# --password-prompt \
# --role admin
services.hydra = {
enable = true;
2024-03-06 04:03:34 +00:00
hydraURL = "https://${cfg.hostname}";
2024-03-02 18:06:18 +00:00
notificationSender = "hydra@localhost";
buildMachinesFiles = [];
useSubstitutes = true;
2024-03-10 21:28:44 +00:00
extraConfig = ''
store_uri = s3://${cfg.s3Bucket}?compression=zstd&parallel-compression=true&write-nar-listing=1&ls-compression=br&log-compression=br&scheme=${cfg.s3Scheme}&endpoint=${cfg.s3Endpoint}&secret-key=${cfg.secretKeyPath}
'';
};
systemd.services."hydra-queue-runner".serviceConfig = {
EnvironmentFile = config.age.secrets.hydra-aws-creds.path;
2024-03-02 18:06:18 +00:00
};
2024-03-06 04:03:34 +00:00
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts."hydra.kilonull.com" =
{
locations."/" = {
proxyPass = "http://127.0.0.1:${toString config.services.hydra.port}";
};
}
// lib.optionalAttrs (cfg.acmeCertName != "") {
forceSSL = true;
useACMEHost = cfg.acmeCertName;
};
};
2024-03-02 18:06:18 +00:00
nix.settings = {
2024-03-03 02:40:24 +00:00
allowed-users = [
"hydra"
"hydra-www"
];
2024-06-01 07:44:46 +00:00
allowed-uris = ["github:" "https://github.com/"];
2024-03-02 18:06:18 +00:00
};
};
}