From 2028259b6971884e4832abe5dff644529a808dda Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Thu, 14 May 2026 08:55:21 +0300 Subject: [PATCH] nix: appview project mode and custom templates Signed-off-by: Anirudh Oppiliappan --- nix/modules/appview.nix | 46 +++++++++++++++++++++++++++++++++++++++-- nix/pkgs/appview.nix | 12 +++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/nix/modules/appview.nix b/nix/modules/appview.nix index 01f87bcc..30cba159 100644 --- a/nix/modules/appview.nix +++ b/nix/modules/appview.nix @@ -6,7 +6,12 @@ }: let cfg = config.services.tangled.appview; in - with lib; { + with lib; let + effectivePackage = + if cfg.project.templatesDir == null + then cfg.package + else cfg.package.override {customTemplatesDir = cfg.project.templatesDir;}; + in { options = { services.tangled.appview = { enable = mkOption { @@ -259,6 +264,33 @@ in }; }; + project = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable project mode: collapses URL namespace to a single user, disables signup and timeline."; + }; + + user = mkOption { + type = types.str; + default = ""; + example = "anirudh.fi"; + description = "The handle or DID of the project user. Required when project.enable is true."; + }; + + templatesDir = mkOption { + type = types.nullOr types.path; + default = null; + example = "./custom-templates"; + description = '' + Path to a directory of template overrides. Files are copied on + top of the default templates at build time, so individual + templates can be replaced without forking the whole tree. + ''; + }; + }; + + environmentFile = mkOption { type = with types; nullOr path; default = null; @@ -283,6 +315,12 @@ in }; config = mkIf cfg.enable { + assertions = [ + { + assertion = !cfg.project.enable || cfg.project.user != ""; + message = "services.tangled.appview.project.user must be set when project.enable is true"; + } + ]; services.redis.servers.appview = { enable = true; port = 6379; @@ -299,7 +337,7 @@ in serviceConfig = { Type = "simple"; - ExecStart = "${cfg.package}/bin/appview"; + ExecStart = "${effectivePackage}/bin/appview"; Restart = "always"; RestartSec = "10s"; EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; @@ -372,6 +410,10 @@ in } // optionalAttrs (cfg.ssh.enable && cfg.ssh.hostKeyPath != null) { TANGLED_SSH_HOST_KEY_PATH = cfg.ssh.hostKeyPath; + } + // optionalAttrs cfg.project.enable { + TANGLED_PROJECT_MODE = "true"; + TANGLED_PROJECT_USER = cfg.project.user; }; }; }; diff --git a/nix/pkgs/appview.nix b/nix/pkgs/appview.nix index 90e7fb1d..fe976c90 100644 --- a/nix/pkgs/appview.nix +++ b/nix/pkgs/appview.nix @@ -4,6 +4,10 @@ appview-static-files, sqlite-lib, src, + # optional path to a directory of template overrides; files here are + # copied on top of appview/pages/templates/ before the Go embed runs, + # so any template file can be replaced without forking the whole tree. + customTemplatesDir ? null, }: buildGoApplication { pname = "appview"; @@ -14,6 +18,14 @@ buildGoApplication { pushd source mkdir -p appview/pages/static cp -frv ${appview-static-files}/* appview/pages/static + ${ + if customTemplatesDir != null + then '' + echo "overlaying custom templates from ${customTemplatesDir}" + cp -rfv ${customTemplatesDir}/* appview/pages/templates/ + '' + else "" + } popd ''; -- 2.51.2