diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-02 23:03:12 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-13 22:40:07 +0200 |
commit | 37352eaede80850d403bf13b1ac254f38800dc73 (patch) | |
tree | 5e7d76c1973a4bbfa44e778ec1b470f20be7b6ab /modules/nixos | |
parent | build(tests): Add complementary scripts (diff) | |
download | nixos-server-37352eaede80850d403bf13b1ac254f38800dc73.tar.gz nixos-server-37352eaede80850d403bf13b1ac254f38800dc73.zip |
feat(nixos/git-server): Add further cgit settings
A lot of the added settings here have been tested. They will get get tests to ensure they stay working, in later commits.
Diffstat (limited to 'modules/nixos')
-rw-r--r-- | modules/nixos/vhack/git-server/css.nix | 116 | ||||
-rw-r--r-- | modules/nixos/vhack/git-server/default.nix | 86 |
2 files changed, 200 insertions, 2 deletions
diff --git a/modules/nixos/vhack/git-server/css.nix b/modules/nixos/vhack/git-server/css.nix new file mode 100644 index 0000000..3d73ea0 --- /dev/null +++ b/modules/nixos/vhack/git-server/css.nix @@ -0,0 +1,116 @@ +{cgitPkg, pkgs}: let + /* + Adapted from `https://git.qyliss.net/nixlib/sys/atuin.nix`, originally distributed under + the MIT license. + */ + cgitCss = + pkgs.runCommand "cgit-extra.css" { + licenseHeader = '' + /* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License v2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * See <https://www.gnu.org/licenses/>. + */ + + ''; + + # Adapted from + # <https://git.causal.agency/src/plain/www/git.causal.agency/custom.css>, + # distributed as a Larger Work under a Secondary License, + # as permitted by the terms of the + # Mozilla Public License Version 2.0. + extraCss = '' + * { line-height: 1.25em; } + + article { + font-family: sans-serif; + max-width: 70ch; + margin-left: auto; + margin-right: auto; + } + + div#cgit { + margin: auto; + font-family: monospace; + -moz-tab-size: 4; + tab-size: 4; + display: table; + } + + div#cgit table#header { + margin-left: auto; + margin-right: auto; + } + div#cgit table#header td.logo { + display: none; + } + div#cgit table#header td.main { + font-size: 1em; + font-weight: bold; + } + div#cgit table#header td.sub { + border-top: none; + } + div#cgit table.tabs { + margin-left: auto; + margin-right: auto; + border-bottom: none; + } + div#cgit div.content { + border-bottom: none; + min-width: 108ch; + } + div#cgit div.content div#summary { + display: table; + margin-left: auto; + margin-right: auto; + } + div#cgit div.notes { + border: none; + background: transparent; + padding: 0; + } + div#cgit table.list { + margin-left: auto; + margin-right: auto; + } + div#cgit table.list th a { + color: inherit; + } + div#cgit table.list tr:nth-child(even) { + background: inherit; + } + div#cgit table.list tr:hover { + background: inherit; + } + div#cgit table.list tr.nohover-highlight:hover:nth-child(even) { + background: inherit; + } + div#cgit div.footer { + font-size: 1em; + margin-top: 0; + } + + div#cgit table.blob td.linenumbers:nth-last-child(3) { + display: none; + } + + div#cgit table.blob td.linenumbers a:target { + color: goldenrod; + text-decoration: underline; + outline: none; + } + ''; + passAsFile = ["licenseHeader" "extraCss"]; + } '' + cat $licenseHeaderPath ${cgitPkg}/cgit/cgit.css $extraCssPath > $out + ''; +in + cgitCss diff --git a/modules/nixos/vhack/git-server/default.nix b/modules/nixos/vhack/git-server/default.nix index a700ef4..8bb1428 100644 --- a/modules/nixos/vhack/git-server/default.nix +++ b/modules/nixos/vhack/git-server/default.nix @@ -5,6 +5,13 @@ ... }: let cfg = config.vhack.git-server; + + cgitCss = import ./css.nix { + inherit pkgs; + cgitPkg = + config.services.cgit."${cfg.domain}".package; + }; + /* Until <https://github.com/NixOS/nixpkgs/pull/317293> is merged into nixpkgs, we have to do the list to string conversion ourselves: @@ -74,20 +81,95 @@ in { package = pkgs.cgit-pink; scanPath = "${config.services.gitolite.dataDir}/repositories"; settings = { + branch-sort = "age"; + # Allow users to download a repo checkout with these compression formats snapshots = toCgitRc ["tar.gz" "zip"]; # The template used to generate the clone url for https clone. clone-url = toCgitRc ["https://${cfg.domain}/$CGIT_REPO_URL" "ssh://git@${cfg.domain}/$CGIT_REPO_URL"]; enable-http-clone = true; - section-from-path = true; + + # TODO: We might want to add an logo and readme here <2024-07-31> + # logo = "<url>"; + # root-readme = "/some/readme/file" + root-desc = "The cgit instance of ${cfg.domain}!"; + root-title = "${ + lib.strings.toUpper (builtins.substring 0 1 cfg.domain) + builtins.substring 1 (builtins.stringLength cfg.domain) cfg.domain + } cgit instace"; + + # Set the default maximum statistics period. Valid values are "week", + # "month", "quarter" and "year". + max-stats = "week"; + + readme = toCgitRc [ + ":README.md" + ":readme.md" + ":README.mkd" + ":readme.mkd" + ":README.rst" + ":readme.rst" + ":README.html" + ":readme.html" + ":README.htm" + ":readme.htm" + ":README.txt" + ":readme.txt" + ":README" + ":readme" + ":INSTALL.md" + ":install.md" + ":INSTALL.mkd" + ":install.mkd" + ":INSTALL.rst" + ":install.rst" + ":INSTALL.html" + ":install.html" + ":INSTALL.htm" + ":install.htm" + ":INSTALL.txt" + ":install.txt" + ":INSTALL" + ":install" + ]; + + enable-blame = true; + enable-commit-graph = true; + enable-subject-links = true; + enable-follow-links = true; + enable-index-links = true; + enable-index-owner = true; + + # NOTE: This allows cgit to take configuration from the bare git repositories: + # eg. `cgit.section` should set the section, `cgit.homepage` the homepage, + # `gitweb.owner` the owner and `gitweb.description` the description of the repo. <2024-08-02> + enable-git-config = true; + + # Remove the `.git` suffix from scanned repositories (this must be set _before_ `scan-path`) + remove-suffix = true; + + css = "${cgitCss}"; + + # This is a number of path elements to treat as section. + # Set this to a big number to ensure all path elements are treated as sections. + section-from-path = 1000; + project-list = "${config.services.gitolite.dataDir}/projects.list"; - source-filter = "${config.services.cgit."git.vhack.eu".package}/lib/cgit/filters/syntax-highlighting.py"; + + # TODO: We might want to use the kernel.org `libravatar.lua` email-filter <2024-07-31> + source-filter = "${config.services.cgit."${cfg.domain}".package}/lib/cgit/filters/syntax-highlighting.py"; + about-filter = "${config.services.cgit."${cfg.domain}".package}/lib/cgit/filters/about-formatting.sh"; }; }; nginx.virtualHosts."${cfg.domain}" = { enableACME = true; forceSSL = true; + + # locations = { + # "= /cgit.css" = { + # alias = cgitCss.outPath; + # }; + # }; }; }; }; |