From b4a8fe58a6e78d436f33a20d15f878e40c1edab2 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Tue, 17 Feb 2026 21:11:49 +0100 Subject: [PATCH] enable git server on vps --- README.md | 6 +++--- hosts/nixos/vps/proxy.nix | 19 +++++++++++++++++++ hosts/nixos/vps/system.nix | 7 +++++++ modules/git/server.nix | 8 +++++++- modules/ssh.nix | 5 +++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a8cffcd..36a2816 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ nix flake update ### New Host Installation ```bash # For NixOS and disko -sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko --flake github:Logan-Lin/nix-config# +sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko --flake git+https://git.yanlincs.com/yanlin/nix# sudo nixos-install --flake .# # For nix-darwin xcode-select --install -sudo nix --extra-experimental-features "nix-command flakes" run nix-darwin -- switch --flake github:Logan-Lin/nix-config# -nix --extra-experimental-features "nix-command flakes" run home-manager/master -- switch --flake github:Logan-Lin/nix-config#@ +sudo nix --extra-experimental-features "nix-command flakes" run nix-darwin -- switch --flake git+https://git.yanlincs.com/yanlin/nix# +nix --extra-experimental-features "nix-command flakes" run home-manager/master -- switch --flake git+https://git.yanlincs.com/yanlin/nix#@ ``` ### Occasional Commands diff --git a/hosts/nixos/vps/proxy.nix b/hosts/nixos/vps/proxy.nix index d4d85ad..1743577 100644 --- a/hosts/nixos/vps/proxy.nix +++ b/hosts/nixos/vps/proxy.nix @@ -38,6 +38,17 @@ }; }; + git = { + rule = "Host(`git.yanlincs.com`)"; + service = "git"; + tls = { + certResolver = "cloudflare"; + domains = [{ + main = "*.yanlincs.com"; + }]; + }; + }; + }; services = { @@ -59,6 +70,14 @@ }; }; + git = { + loadBalancer = { + servers = [{ + url = "http://127.0.0.1:3000"; + }]; + }; + }; + }; }; diff --git a/hosts/nixos/vps/system.nix b/hosts/nixos/vps/system.nix index bf64008..0094da4 100644 --- a/hosts/nixos/vps/system.nix +++ b/hosts/nixos/vps/system.nix @@ -10,6 +10,7 @@ ../../../modules/podman.nix ../../../modules/traefik.nix ../../../modules/borg/client.nix + ../../../modules/git/server.nix ]; # GRUB bootloader with UEFI support @@ -72,12 +73,18 @@ services.tailscale-custom.exitNode = true; + services.git-server-custom = { + enable = true; + domain = "git.yanlincs.com"; + }; + # Borg backup configuration services.borg-client-custom = { enable = true; repositoryUrl = "ssh://helsinki-box/./vps"; backupPaths = [ "/var/lib/mongodb" + "/var/lib/forgejo" ]; backupFrequency = "*-*-* 03:00:00"; retention = { diff --git a/modules/git/server.nix b/modules/git/server.nix index 365e2ac..62f09af 100644 --- a/modules/git/server.nix +++ b/modules/git/server.nix @@ -1,4 +1,7 @@ -{ config, lib, ... }: +# NOTE: After install, use the following command to create admin account. +# sudo -u forgejo forgejo --config /var/lib/forgejo/custom/conf/app.ini admin user create --admin --username --password --email + +{ config, lib, pkgs, ... }: let cfg = config.services.git-server-custom; @@ -24,6 +27,8 @@ in }; config = lib.mkIf cfg.enable { + environment.systemPackages = [ config.services.forgejo.package ]; + services.forgejo = { enable = true; lfs.enable = true; @@ -35,6 +40,7 @@ in HTTP_ADDR = "127.0.0.1"; HTTP_PORT = cfg.httpPort; SSH_PORT = cfg.sshPort; + LANDING_PAGE = "/yanlin"; }; service.DISABLE_REGISTRATION = true; }; diff --git a/modules/ssh.nix b/modules/ssh.nix index c773b11..9ed224b 100644 --- a/modules/ssh.nix +++ b/modules/ssh.nix @@ -51,6 +51,11 @@ in identityFile = "${keyDir}/hetzner"; }; + "git.yanlincs.com" = { + user = "forgejo"; + identityFile = "${keyDir}/hetzner"; + }; + "borg-box" = { hostname = "u518619.your-storagebox.de"; user = "u518619";