1
0
Fork 0
nix-configuration/modules/services/forgejo.nix

106 lines
3.5 KiB
Nix
Raw Normal View History

{
pkgs,
config,
lib,
...
}:
let
cfg = config.host.services.forgejo;
cli-cfg = config.services.forgejo;
forgejo-cli = pkgs.writeScriptBin "forgejo-cli" ''
#!${pkgs.runtimeShell}
cd ${cli-cfg.stateDir}
sudo=exec
if [[ "$USER" != forgejo ]]; then
sudo='exec /run/wrappers/bin/sudo -u ${cli-cfg.user} -g ${cli-cfg.group} --preserve-env=GITEA_WORK_DIR --preserve-env=GITEA_CUSTOM'
fi
# Note that these variable names will change
export GITEA_WORK_DIR=${cli-cfg.stateDir}
export GITEA_CUSTOM=${cli-cfg.customDir}
$sudo ${lib.getExe cli-cfg.package} "$@"
'';
in
{
options = {
host.services.forgejo = {
2024-05-21 00:52:57 +00:00
autostart = lib.mkEnableOption (lib.mdDoc "Automatically starts Forgejo at boot.");
enable = lib.mkEnableOption (lib.mdDoc "Enables Forgejo Git hosting service.");
home = lib.mkOption {
default = "";
type = lib.types.str;
2024-05-21 00:52:57 +00:00
description = "Where to store Forgejo's files";
};
};
};
config = lib.mkIf cfg.enable {
2024-05-27 16:32:24 +00:00
environment.systemPackages = [
forgejo-cli
pkgs.podman-tui
];
services = {
nginx.virtualHosts."${config.secrets.services.forgejo.url}" = {
useACMEHost = config.secrets.networking.primaryDomain;
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:3000";
proxyWebsockets = true;
extraConfig = "proxy_ssl_server_name on;"; # required when the target is also TLS server with multiple hosts
};
};
forgejo = {
enable = true;
lfs.enable = true;
settings.server = {
DOMAIN = "${config.secrets.networking.primaryDomain}";
ROOT_URL = "https://code.${config.secrets.networking.primaryDomain}/";
HTTP_PORT = 3000;
};
useWizard = true;
} // lib.optionalAttrs (cfg.home != null) { stateDir = cfg.home; };
2024-05-27 16:32:24 +00:00
# Enable runner for CI actions
gitea-actions-runner = {
package = pkgs.forgejo-actions-runner;
instances.default = {
enable = true;
name = config.networking.hostName;
2024-05-27 16:44:50 +00:00
url = "https://${config.secrets.services.forgejo.url}";
2024-05-27 16:32:24 +00:00
token = config.secrets.services.forgejo.runner-token;
labels = [
2024-05-27 17:11:16 +00:00
"nix:docker://nixos/nix" # Shoutout to Icewind 1991 for this syntax: https://icewind.nl/entry/gitea-actions-nix/
2024-05-27 17:07:35 +00:00
"debian:docker://node:20-bullseye"
"ubuntu-latest:docker://ubuntu:latest"
2024-05-27 16:32:24 +00:00
];
2024-05-27 17:30:16 +00:00
settings = {
# For an example of configuring in Nix: https://git.clan.lol/clan/clan-infra/src/branch/main/modules/web01/gitea/actions-runner.nix
# For an example of the different options available: https://gitea.com/gitea/act_runner/src/branch/main/internal/pkg/config/config.example.yaml
2024-05-28 18:00:05 +00:00
container.options = "-v /nix:/nix";
2024-05-28 17:48:44 +00:00
container.validVolumes = [ "/nix" ];
2024-05-27 17:30:16 +00:00
};
2024-05-27 16:32:24 +00:00
};
};
};
# Enable Podman for running...uh, runners.
virtualisation = {
containers.enable = true;
podman = {
enable = true;
# Create a `docker` alias for podman, to use it as a drop-in replacement
dockerCompat = true;
# Required for containers under podman-compose to be able to talk to each other.
defaultNetwork.settings.dns_enabled = true;
};
};
systemd.services = {
nginx.wants = [ config.systemd.services.forgejo.name ];
2024-05-21 00:52:57 +00:00
} // lib.optionalAttrs (!cfg.autostart) { forgejo.wantedBy = lib.mkForce [ ]; };
};
}