infrastructure

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 9cdec75ab2d0a587bd75a96027ada8e944de1245
parent 36ef9aad8df6492365e11146afee566cf1804e76
Author: Silas Brack <silasbrack@gmail.com>
Date:   Wed, 22 Apr 2026 12:12:20 +0200

feat: add Trailbase backend service for simple-web-app

- Add simple-web-app-trailbase systemd service
- Configure traildepot config copying on first start
- Set TRAILBASE_URL environment variable
- Make simple-web-app depend on trailbase service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Diffstat:
Mflake.lock | 8++++----
Mhosts/helios.nix | 2++
Mmodules/simple-web-app.nix | 50++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/flake.lock b/flake.lock @@ -192,11 +192,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1776801714, - "narHash": "sha256-Z2PZJHxljchSx2FMa3ztsw+aYYpkAD8S5zd6VXFAQiE=", + "lastModified": 1776838776, + "narHash": "sha256-0hSSUp9KqON9B09Xh2AgA8jCf428qk1Hw9NXNVG8a2E=", "ref": "refs/heads/main", - "rev": "a0d7b85a3154cf137f810b6f774e4324298b8fed", - "revCount": 41, + "rev": "60a5cecddce56036be2d0a950ae7ab819117a90c", + "revCount": 43, "type": "git", "url": "ssh://forgejo@git.fnarglebeast.com/silas/simple-web-app.git" }, diff --git a/hosts/helios.nix b/hosts/helios.nix @@ -126,6 +126,8 @@ services.simple-web-app = { enable = true; package = simple-web-app.packages.${pkgs.stdenv.hostPlatform.system}.default; + trailbasePackage = simple-web-app.packages.${pkgs.stdenv.hostPlatform.system}.trailbase; + traildepotPath = "${simple-web-app}/traildepot"; }; # Users diff --git a/modules/simple-web-app.nix b/modules/simple-web-app.nix @@ -19,6 +19,15 @@ in defaultText = lib.literalMD "`packages.default` from the simple-web-app flake"; }; + trailbasePackage = mkOption { + defaultText = lib.literalMD "`packages.trailbase` from the simple-web-app flake"; + }; + + traildepotPath = mkOption { + type = types.path; + description = "Path to the traildepot configuration directory"; + }; + port = mkOption { type = types.nullOr types.int; default = 8000; @@ -27,25 +36,58 @@ in The port to bind simple web app server to. ''; }; + + trailbasePort = mkOption { + type = types.int; + default = 4000; + description = '' + The port for Trailbase to listen on. + ''; + }; }; }; config = mkIf cfg.enable { - # Run service + # Run Trailbase backend service + systemd.services.simple-web-app-trailbase = { + wantedBy = [ "multi-user.target" ]; + description = "Trailbase backend for simple web app."; + after = [ "network.target" ]; + serviceConfig = { + Type = "simple"; + ExecStart = "${cfg.trailbasePackage}/bin/trail run --address 127.0.0.1:${builtins.toString cfg.trailbasePort}"; + WorkingDirectory = "/var/lib/simple-web-app-trailbase"; + DynamicUser = true; + StateDirectory = "simple-web-app-trailbase"; + }; + preStart = '' + # Copy traildepot config if not present + if [ ! -f /var/lib/simple-web-app-trailbase/config.textproto ]; then + cp ${cfg.traildepotPath}/config.textproto /var/lib/simple-web-app-trailbase/ + fi + # Copy migrations + if [ ! -d /var/lib/simple-web-app-trailbase/migrations ]; then + cp -r ${cfg.traildepotPath}/migrations /var/lib/simple-web-app-trailbase/ + fi + ''; + }; + + # Run simple web app service systemd.services.simple-web-app = { wantedBy = [ "multi-user.target" ]; description = "Run simple web app."; - after = [ "network.target" ]; + after = [ "network.target" "simple-web-app-trailbase.service" ]; + requires = [ "simple-web-app-trailbase.service" ]; serviceConfig = { Type = "simple"; ExecStart = "${cfg.package}/bin/simple-web-app"; DynamicUser = true; - StateDirectory = "simple-web-app"; # Ensures /var/lib/simple-web-app/ + StateDirectory = "simple-web-app"; }; environment = { PORT = builtins.toString cfg.port; DEBUG = "false"; - DATABASE_URL = "sqlite:///var/lib/simple-web-app/db.sqlite3"; + TRAILBASE_URL = "http://127.0.0.1:${builtins.toString cfg.trailbasePort}"; RUST_LOG = "info"; }; };