diff options
Diffstat (limited to 'modules/services/nixos/cgit')
| -rw-r--r-- | modules/services/nixos/cgit/default.nix | 82 | ||||
| -rw-r--r-- | modules/services/nixos/cgit/gitShellCommands.nix | 43 |
2 files changed, 64 insertions, 61 deletions
diff --git a/modules/services/nixos/cgit/default.nix b/modules/services/nixos/cgit/default.nix index 0f81958..b35a631 100644 --- a/modules/services/nixos/cgit/default.nix +++ b/modules/services/nixos/cgit/default.nix @@ -5,9 +5,26 @@ ... }: let cfg = config.collinux.services.cgit; + + custom_cgit = pkgs.stdenv.mkDerivation { + name = "custom-cgit-assets"; + src = pkgs.cgit; + installPhase = '' + mkdir -p $out + cp -pPR ./cgit/* $out/ + + rm -f $out/cgit.png $out/favicon.ico $out/cgit.css + cp -f ${./favicon.svg} $out/favicon.svg + cp -f ${./cgit.css} $out/cgit.css + ''; + }; in { + imports = [ + (import ../mkCaddyCfg.nix cfg) + ./gitShellCommands.nix + ]; + config = lib.mkIf cfg.enable { - environment.shells = ["${pkgs.git}/bin/git-shell"]; users.groups."git" = {}; users.users."git" = { isSystemUser = true; @@ -20,47 +37,6 @@ in { openssh.authorizedKeys.keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC3SjzIs3YI8PWJaNrAuaEeRcTcvIVHOKyCh2VwHTHEF"]; }; - hjem.users."git".files = { - "git-shell-commands/set-description" = { - executable = true; - text = '' - #!/usr/bin/env bash - set -euo pipefail - repo="$1" - desc="$2" - base="/var/lib/cgit" - repo_path="$base/$repo" - - test -d "$repo_path" || { echo "Repository does not exist"; exit 1; } - - # Prevent path traversal - real=$(realpath "$repo_path") - if [[ "$real" != "$base/"* ]]; then - echo "Invalid path" - exit 1 - fi - - echo "$desc" | head -n 1 > "$repo_path/description" - - echo "Description updated for '$repo'" - ''; - }; - "git-shell-commands/create-repo" = { - executable = true; - text = '' - #!/usr/bin/env bash - set -euo pipefail - repo="$1" - base="/var/lib/cgit" - repo_path="$base/$repo" - - test -d "$repo_path" && { echo "Repository already exists."; exit 1; } - - git init --bare "$repo_path" - echo "Repository '$repo' created" - ''; - }; - }; services.openssh.extraConfig = lib.mkAfter '' Match User git @@ -84,8 +60,8 @@ in { root-desc=Git repos associated with Ganymede readme=:README.md - about-filter=${pkgs.cgit}/lib/cgit/filters/html-converters/md2html - source-filter=${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py + about-filter=${custom_cgit}/lib/cgit/filters/html-converters/md2html + source-filter=${custom_cgit}/lib/cgit/filters/syntax-highlighting.py footer= virtual-root=/ @@ -106,23 +82,7 @@ in { }; }; - networking.extraHosts = "127.0.0.1 git.ganymede"; - services.caddy.virtualHosts."git.ganymede".extraConfig = let - custom_cgit = pkgs.stdenv.mkDerivation { - name = "custom-cgit-assets"; - src = pkgs.cgit; - installPhase = '' - mkdir -p $out - cp -pPR ./cgit/* $out/ - - rm -f $out/cgit.png $out/favicon.ico $out/cgit.css - cp -f ${./favicon.svg} $out/favicon.svg - cp -f ${./cgit.css} $out/cgit.css - ''; - }; - in '' - tls internal - + collinux.services.cgit.manualCaddyConfig = '' @assets path /cgit.css /cgit.js /favicon.svg /robots.txt handle @assets { root * ${custom_cgit} diff --git a/modules/services/nixos/cgit/gitShellCommands.nix b/modules/services/nixos/cgit/gitShellCommands.nix new file mode 100644 index 0000000..e99f9f2 --- /dev/null +++ b/modules/services/nixos/cgit/gitShellCommands.nix @@ -0,0 +1,43 @@ +{ + hjem.users."git".files = { + "git-shell-commands/set-description" = { + executable = true; + text = '' + #!/usr/bin/env bash + set -euo pipefail + repo="$1" + desc="$2" + base="/var/lib/cgit" + repo_path="$base/$repo" + + test -d "$repo_path" || { echo "Repository does not exist"; exit 1; } + + # Prevent path traversal + real=$(realpath "$repo_path") + if [[ "$real" != "$base/"* ]]; then + echo "Invalid path" + exit 1 + fi + + echo "$desc" | head -n 1 > "$repo_path/description" + + echo "Description updated for '$repo'" + ''; + }; + "git-shell-commands/create-repo" = { + executable = true; + text = '' + #!/usr/bin/env bash + set -euo pipefail + repo="$1" + base="/var/lib/cgit" + repo_path="$base/$repo" + + test -d "$repo_path" && { echo "Repository already exists."; exit 1; } + + git init --bare "$repo_path" + echo "Repository '$repo' created" + ''; + }; + }; +} |
