From 2f281b354afb8d28228870460237f6ee37c499d4 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 30 Sep 2026 14:40:26 -0400 Subject: [PATCH] gitea container --- bin/ABOUTME.md | 3 +- bin/lib/cmds.nu | 25 ++ bin/lib/helpers.nu | 15 + bin/lib/types.nu | 8 + hosts/hl-minipc1/services/gitea-container.nix | 14 +- hosts/hl-minipc1/services/gitea-home.tmpl | 371 ++++++++++++++++++ 6 files changed, 433 insertions(+), 3 deletions(-) create mode 100644 hosts/hl-minipc1/services/gitea-home.tmpl diff --git a/bin/ABOUTME.md b/bin/ABOUTME.md index 536ea2c..7a1025c 100644 --- a/bin/ABOUTME.md +++ b/bin/ABOUTME.md @@ -14,7 +14,7 @@ bin/ ├── cmds.nu # All subcommand implementations (NuShell — source of truth); commands only ├── helpers.nu # Shared helpers: REPO_ROOT const + internal functions used by commands ├── profile.nu # Profile helpers and tab-completion data - └── types.nu # Type definitions + └── types.nu # Type definitions + tab-completion data ``` ## Key Commands @@ -40,6 +40,7 @@ bin/ | `skyg compare-secret ` | Diff the working copy against the stored secret | | `skyg ca init` | Generate the lab root CA: key → `secrets/lab-ca-key.age`, cert → `configs/pki/lab-ca.crt` (see `configs/pki/ABOUTME.md`) | | `skyg ca issue --for ` | Mint a TLS leaf cert signed by the lab CA: cert → `configs/pki/.crt`, key → `secrets/-tls-key.age`. Auto-registers missing `secrets.nix` entries. | +| `skyg render html-tpl ` | Render a Gitea `.tmpl` (swaps `base/head`/`base/footer` for a minimal shell, strips `{{ … }}`) and serve it on `127.0.0.1` for preview. Foreground — Ctrl+C to stop. `` tab-completes from `**/*.tmpl`. | ## Agent Note diff --git a/bin/lib/cmds.nu b/bin/lib/cmds.nu index 8e057b7..0899a55 100644 --- a/bin/lib/cmds.nu +++ b/bin/lib/cmds.nu @@ -607,3 +607,28 @@ export def "skyg pkgs update" [ git --no-pager diff pkgs/ | print } } + +# Render a Gitea HTML template and serve it locally for preview. +# Runs in the foreground — Ctrl+C to stop. Wrap it in nohup yourself to detach. +export def "skyg render html-tpl" [ + file: string@html-tpl-files # Template to render (e.g. hosts/hl-minipc1/services/gitea-home.tmpl) + --port: int = 8787 # Port for the local preview server +] { + cd $REPO_ROOT + let src = ($file | path expand) + if not ($src | path exists) { + error make {msg: $"Template not found: ($file)"} + } + + let out_dir = ".tmp/render-html-tpl" + mkdir $out_dir + let name = ($src | path basename | str replace -r '\.tmpl$' '') + let out = $"($out_dir)/($name).html" + render-html-tpl $src $out + + print $"Rendered ($file) -> ($out)" + print $"Preview: http://127.0.0.1:($port)/($name).html" + print "Press Ctrl+C to stop." + + ^python3 -m http.server $port --bind 127.0.0.1 --directory $out_dir +} diff --git a/bin/lib/helpers.nu b/bin/lib/helpers.nu index 1015f9e..963e937 100644 --- a/bin/lib/helpers.nu +++ b/bin/lib/helpers.nu @@ -19,3 +19,18 @@ export def ensure-secret-entry [secret_path: string, recipients: list] { ($new_lines | str join "\n") + "\n" | save -f $file print $"📝 Registered ($secret_path) in secrets.nix — review with git diff" } + +# Render a Gitea-style Go template to a standalone HTML file for local preview. +# Swaps the base/head + base/footer includes for a minimal shell and drops any +# remaining {{ ... }} directives so the page opens in a plain browser. +export def render-html-tpl [src: string, out: string] { + let head = ' +Template preview' + let foot = '' + # Read via external cat — `open` is aliased to xdg-open in some Nu configs. + ^cat $src + | str replace -a '{{template "base/head" .}}' $head + | str replace -a '{{template "base/footer" .}}' $foot + | str replace -a -r '\{\{[^}]*\}\}' '' + | save -f $out +} diff --git a/bin/lib/types.nu b/bin/lib/types.nu index 2d26c8c..cc983b6 100644 --- a/bin/lib/types.nu +++ b/bin/lib/types.nu @@ -29,3 +29,11 @@ export def updatable-pkgs [] { glob "pkgs/*/update.sh" | each {|f| $f | path dirname | path basename } } + +# Gitea HTML templates, for `skyg render html-tpl` tab-completion. +export def html-tpl-files [] { + cd $REPO_ROOT + glob "**/*.tmpl" + | each {|f| $f | path relative-to $REPO_ROOT } + | sort +} diff --git a/hosts/hl-minipc1/services/gitea-container.nix b/hosts/hl-minipc1/services/gitea-container.nix index 08f61d3..dabd270 100644 --- a/hosts/hl-minipc1/services/gitea-container.nix +++ b/hosts/hl-minipc1/services/gitea-container.nix @@ -4,6 +4,7 @@ let user = "gitea"; group = "gitea"; stateDir = "/var/lib/sosnovsky/gitea"; + sshDir = "/var/lib/sosnovsky/gitea-ssh"; httpPort = 3000; sshPort = 22; }; @@ -37,6 +38,11 @@ in systemd.tmpfiles.rules = lib.mkIf containerMode [ "d ${gitea.stateDir} 0750 ${gitea.user} ${gitea.group} -" + "d ${gitea.sshDir} 0750 ${gitea.user} ${gitea.group} -" + # Pre-created so the read-only template mount lands in gitea-owned dirs + # instead of root-owned ones docker would create on demand. + "d ${gitea.stateDir}/custom 0755 ${gitea.user} ${gitea.group} -" + "d ${gitea.stateDir}/custom/templates 0755 ${gitea.user} ${gitea.group} -" ]; skyg.nixos.common.container-services.gitea = { @@ -54,8 +60,9 @@ in # The image renames its `git` user to $USER, so this makes RUN_USER, # sshd AllowUsers and the container's runtime user all `gitea`. USER = gitea.user; + HOME = "/data/git"; GITEA__server__APP_DATA_PATH = "${gitea.stateDir}/data"; - GITEA__server__SSH_ROOT_PATH = "${gitea.stateDir}/.ssh"; + GITEA__server__SSH_ROOT_PATH = "/data/git/.ssh"; GITEA__repository__ROOT = "${gitea.stateDir}/repositories"; GITEA__database__PATH = "${gitea.stateDir}/data/gitea.db"; GITEA__log__ROOT_PATH = "${gitea.stateDir}/log"; @@ -69,8 +76,11 @@ in }; volumes = [ "${gitea.stateDir}:${gitea.stateDir}" - "${gitea.stateDir}/.ssh:/data/git/.ssh" + "${gitea.sshDir}:/data" ]; + # Custom landing page, mounted read-only over GITEA_CUSTOM/templates. + files."${gitea.stateDir}/custom/templates/home.tmpl" = + builtins.readFile ./gitea-home.tmpl; }; }; } diff --git a/hosts/hl-minipc1/services/gitea-home.tmpl b/hosts/hl-minipc1/services/gitea-home.tmpl new file mode 100644 index 0000000..bc7f0ff --- /dev/null +++ b/hosts/hl-minipc1/services/gitea-home.tmpl @@ -0,0 +1,371 @@ +{{template "base/head" .}} +
+
+ +
+

Sosnovsky Gitea

+

Ariel's Sosnovsky personal project hub

+
+ + + + + +
+
+{{template "base/footer" .}}