flake

Francesco Saccone's Nix flake.
git clone git://git.francescosaccone.com/flake
Log | Files | Refs | README | LICENSE

commit eb931fbd708935e236ee10576f042876b3084ef9
parent a5357197d8e7836d81afafbd54fe3572c0056338
Author: Francesco Saccone <francesco@francescosaccone.com>
Date:   Thu, 27 Mar 2025 18:16:29 +0100

refactor: make destDir and reposDir arguments of stagit scripts

This makes the scripts more configurable, without hardcoding any
paths such as /var/tmp/stagit.

Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>

Diffstat:
Mhosts/git-server/default.nix | 7+++++++
Mhosts/git-server/scripts.nix | 87++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 67 insertions(+), 27 deletions(-)

diff --git a/hosts/git-server/default.nix b/hosts/git-server/default.nix @@ -11,6 +11,11 @@ let gitDomain = "git.${rootDomain}"; scripts = import ./scripts.nix { inherit config pkgs inputs; }; + + stagit = { + destDir = "/var/tmp/stagit"; + reposDir = config.modules.git.directory; + }; in { imports = [ @@ -28,6 +33,7 @@ in preStart = { scripts = [ (scripts.stagitCreate { + inherit (stagit) destDir reposDir; httpBaseUrl = "https://${gitDomain}"; }) ]; @@ -92,6 +98,7 @@ in url = "git://${gitDomain}/${name}"; }; hooks.postReceive = scripts.stagitPostReceive { + inherit (stagit) destDir reposDir; inherit name; httpBaseUrl = "https://${gitDomain}"; }; diff --git a/hosts/git-server/scripts.nix b/hosts/git-server/scripts.nix @@ -4,33 +4,37 @@ inputs, }: let - stagit = rec { - destDir = "/var/tmp/stagit"; - reposDir = config.modules.git.directory; - - createIndex = '' - ${pkgs.sbase}/bin/mkdir -p ${destDir} + stagit = { + createIndex = + { destDir, reposDir }: + '' + ${pkgs.sbase}/bin/mkdir -p ${destDir} - ${pkgs.stagit}/bin/stagit-index ${reposDir}/*/ > ${destDir}/index.html + ${pkgs.stagit}/bin/stagit-index ${reposDir}/*/ > ${destDir}/index.html - # Symlink favicon.png, logo.png and stagit.css from site - ${pkgs.sbase}/bin/ln -sf \ - ${inputs.site}/public/icon/256.png \ - ${destDir}/favicon.png + # Symlink favicon.png, logo.png and stagit.css from site + ${pkgs.sbase}/bin/ln -sf \ + ${inputs.site}/public/icon/256.png \ + ${destDir}/favicon.png - ${pkgs.sbase}/bin/ln -sf \ - ${inputs.site}/public/icon/32.png \ - ${destDir}/logo.png + ${pkgs.sbase}/bin/ln -sf \ + ${inputs.site}/public/icon/32.png \ + ${destDir}/logo.png - ${pkgs.sbase}/bin/ln -sf \ - ${inputs.site}/public/stagit.css \ - ${destDir}/style.css + ${pkgs.sbase}/bin/ln -sf \ + ${inputs.site}/public/stagit.css \ + ${destDir}/style.css - ${pkgs.sbase}/bin/echo "Stagit index generated: ${destDir}/index.html". - ''; + ${pkgs.sbase}/bin/echo "Stagit index generated: ${destDir}/index.html". + ''; createRepository = - { name, httpBaseUrl }: + { + destDir, + reposDir, + name, + httpBaseUrl, + }: '' ${pkgs.sbase}/bin/mkdir -p ${destDir}/${name} cd ${destDir}/${name} @@ -65,29 +69,58 @@ let in { stagitCreate = - { httpBaseUrl }: + { + destDir, + reposDir, + httpBaseUrl, + }: let + createIndex = stagit.createIndex { + inherit destDir reposDir; + }; createRepositories = config.modules.git.repositories |> builtins.attrNames |> builtins.map ( name: stagit.createRepository { - inherit name httpBaseUrl; + inherit + destDir + reposDir + name + httpBaseUrl + ; } ) |> builtins.concatStringsSep "\n"; script = pkgs.writeShellScriptBin "stagit-create" '' - ${stagit.createIndex} + ${createIndex} ${createRepositories} ''; in "${script}/bin/stagit-create"; stagitPostReceive = - { name, httpBaseUrl }: + { + destDir, + reposDir, + name, + httpBaseUrl, + }: let + createIndex = stagit.createIndex { + inherit destDir reposDir; + }; + createRepositories = stagit.createRepository { + inherit + destDir + reposDir + name + httpBaseUrl + ; + }; + script = pkgs.writeShellScriptBin "stagit" '' # Define is_force=1 if 'git push -f' was used null_ref="0000000000000000000000000000000000000000" @@ -107,11 +140,11 @@ in # If is_force = 1, delete commits if ${pkgs.sbase}/bin/test $is_force = "1"; then - ${pkgs.sbase}/bin/rm -rf ${stagit.reposDir}/${name}/commit + ${pkgs.sbase}/bin/rm -rf ${reposDir}/${name}/commit fi - ${stagit.createIndex} - ${stagit.createRepository { inherit name httpBaseUrl; }} + ${createIndex} + ${createRepositories} ''; in "${script}/bin/stagit";