[nidaros] Add Forgejo and Podman

This commit is contained in:
2025-10-14 19:32:03 +00:00
parent 07fc2acecc
commit 6ff59b7c22
3 changed files with 98 additions and 0 deletions

View File

@@ -4,8 +4,10 @@
imports = with lib.custom; [ imports = with lib.custom; [
(relativeToBase "modules") (relativeToBase "modules")
./boot.nix ./boot.nix
./forgejo.nix
./hardware.nix ./hardware.nix
./keycloak.nix ./keycloak.nix
./podman.nix
./postgres.nix ./postgres.nix
./security ./security
]; ];

73
hosts/nidaros/forgejo.nix Normal file
View File

@@ -0,0 +1,73 @@
{
config,
pkgs,
lib,
common,
...
}:
let
domain = "beta.code.${common.domain}";
passwordKey = "forgejo/admin-pass";
runnerTokenKey = "forgejo/runner-token";
in
{
services = {
forgejo = {
enable = true;
database.type = "postgres";
# Enable support for Git Large File Storage
lfs.enable = true;
settings = {
server = {
DOMAIN = domain;
# You need to specify this to remove the port from URLs in the web UI.
ROOT_URL = "https://${domain}/";
HTTP_PORT = 8002;
};
# You can temporarily allow registration to create an admin user.
service.DISABLE_REGISTRATION = true;
# Add support for actions, based on act: https://github.com/nektos/act
actions = {
ENABLED = true;
DEFAULT_ACTIONS_URL = "github";
};
# TODO set up mailer
};
};
gitea-actions-runner = {
package = pkgs.forgejo-actions-runner;
instances.default = {
enable = true;
name = "monolith";
url = "https://${domain}";
# Obtaining the path to the runner token file may differ
# tokenFile should be in format TOKEN=<secret>, since it's EnvironmentFile for systemd
tokenFile = config.sops.secrets.${runnerTokenKey}.path;
labels = [
"docker:docker://node:22-bullseye"
"native:host"
];
};
};
};
sops.secrets = {
${passwordKey}.owner = "forgejo";
${runnerTokenKey}.owner = "forgejo";
};
# Create a single admin user / update password if exists
systemd.services.forgejo.preStart =
let
adminCmd = "${lib.getExe config.services.forgejo.package} admin user";
pwd = config.sops.secrets.${passwordKey};
user = "martin"; # Note, Forgejo doesn't allow creation of an account named "admin"
email = "git@${common.domain}";
in
''
${adminCmd} create --admin --email "${email}" --username ${user} --password "$(tr -d '\n' < ${pwd.path})" || true
## Alter an existing user. Will prompt new password on login
# ${adminCmd} change-password --username ${user} --password "$(tr -d '\n' < ${pwd.path})" || true
'';
}

23
hosts/nidaros/podman.nix Normal file
View File

@@ -0,0 +1,23 @@
{ pkgs, ... }:
{
virtualisation = {
# Enable common container config files in /etc/containers
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;
};
};
# Useful other development tools
environment.systemPackages = with pkgs; [
podman-tui # status of containers in the terminal
podman-compose # start group of containers for dev
];
}