commit 8278614a402304005b3bcc51d2b1ddfd1181eaed
parent 1ca024af87c3d1f7607a84305c28f6bcecd82b37
Author: Francesco Saccone <francesco@francescosaccone.com>
Date: Thu, 27 Mar 2025 17:44:07 +0100
refactor: require 'httpBaseUrl' argument for all stagit scripts
This way, the '-u' flag value does not depend on the web server
path implementations. Its value should not containg the path to
the repository page, but the path to the index page.
Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>
Diffstat:
2 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/hosts/git-server/default.nix b/hosts/git-server/default.nix
@@ -68,7 +68,10 @@ in
owner = "Francesco Saccone";
url = "git://${gitDomain}/${name}";
};
- hooks.postReceive = scripts.stagitPostReceive { inherit name; };
+ hooks.postReceive = scripts.stagitPostReceive {
+ inherit name;
+ httpBaseUrl = "https://${gitDomain}";
+ };
}
);
daemon = {
diff --git a/hosts/git-server/scripts.nix b/hosts/git-server/scripts.nix
@@ -27,45 +27,53 @@ let
${pkgs.sbase}/bin/echo "Stagit index generated: ${destDir}/index.html".
'';
- createRepository = name: ''
- ${pkgs.sbase}/bin/mkdir -p ${destDir}/${name}
- cd ${destDir}/${name}
- ${pkgs.stagit}/bin/stagit \
- -l 100 \
- -u https://${config.networking.domain}/git/${name}/ \
- ${reposDir}/${name}
-
- # Make the log.html file the index page
- ${pkgs.sbase}/bin/ln -sf \
- ${destDir}/${name}/log.html \
- ${destDir}/${name}/index.html
-
- # Symlink favicon.png, logo.png and style.css in repos from
- # index
- ${pkgs.sbase}/bin/ln -sf \
- ${destDir}/favicon.png \
- ${destDir}/${name}/favicon.png
-
- ${pkgs.sbase}/bin/ln -sf \
- ${destDir}/logo.png \
- ${destDir}/${name}/logo.png
-
- ${pkgs.sbase}/bin/ln -sf \
- ${destDir}/style.css \
- ${destDir}/${name}/style.css
-
- ${pkgs.sbase}/bin/echo \
- "Stagit page generated for ${name}: ${destDir}/${name}".
- '';
+ createRepository =
+ { name, httpBaseUrl }:
+ ''
+ ${pkgs.sbase}/bin/mkdir -p ${destDir}/${name}
+ cd ${destDir}/${name}
+ ${pkgs.stagit}/bin/stagit \
+ -l 100 \
+ -u ${httpBaseUrl}/${name}/ \
+ ${reposDir}/${name}
+
+ # Make the log.html file the index page
+ ${pkgs.sbase}/bin/ln -sf \
+ ${destDir}/${name}/log.html \
+ ${destDir}/${name}/index.html
+
+ # Symlink favicon.png, logo.png and style.css in repos from
+ # index
+ ${pkgs.sbase}/bin/ln -sf \
+ ${destDir}/favicon.png \
+ ${destDir}/${name}/favicon.png
+
+ ${pkgs.sbase}/bin/ln -sf \
+ ${destDir}/logo.png \
+ ${destDir}/${name}/logo.png
+
+ ${pkgs.sbase}/bin/ln -sf \
+ ${destDir}/style.css \
+ ${destDir}/${name}/style.css
+
+ ${pkgs.sbase}/bin/echo \
+ "Stagit page generated for ${name}: ${destDir}/${name}".
+ '';
};
in
{
stagitCreate =
+ { httpBaseUrl }:
let
createRepositories =
config.modules.git.repositories
|> builtins.attrNames
- |> builtins.map stagit.createRepository
+ |> builtins.map (
+ name:
+ stagit.createRepository {
+ inherit name httpBaseUrl;
+ }
+ )
|> builtins.concatStringsSep "\n";
script = pkgs.writeShellScriptBin "stagit-create" ''
@@ -76,7 +84,7 @@ in
"${script}/bin/stagit-create";
stagitPostReceive =
- { name }:
+ { name, httpBaseUrl }:
let
script = pkgs.writeShellScriptBin "stagit" ''
# Define is_force=1 if 'git push -f' was used
@@ -101,7 +109,7 @@ in
fi
${stagit.createIndex}
- ${stagit.createRepository name}
+ ${stagit.createRepository { inherit name httpBaseUrl; }}
'';
in
"${script}/bin/stagit";