Reformat everything
All checks were successful
/ test (push) Successful in 32s

This commit is contained in:
Andrea Ciceri 2024-09-20 11:37:17 +02:00
parent 5f644d0ccd
commit a394b9cefd
Signed by: aciceri
SSH key fingerprint: SHA256:/AagBweyV4Hlfg9u092n8hbHwD5fcB6A3qhDiDA65Rg
167 changed files with 2795 additions and 2122 deletions

View file

@ -1,28 +1,31 @@
{
lib,
pkgs,
...
}: let
}:
let
repos-path = "/var/lib/cgit-repos";
cgit-setup-repos =
pkgs.writers.writePython3 "cgit-setup-repos" {
libraries = with pkgs.python3Packages; [PyGithub];
} ''
from github import Github
from pathlib import Path
pkgs.writers.writePython3 "cgit-setup-repos"
{
libraries = with pkgs.python3Packages; [ PyGithub ];
}
''
from github import Github
from pathlib import Path
c = Path("${repos-path}")
c.unlink(missing_ok=True)
c = Path("${repos-path}")
c.unlink(missing_ok=True)
with open(c, "w") as f:
for repo in Github().get_user("aciceri").get_repos():
f.writelines([
f"repo.url={repo.name}\n"
f"repo.path=/home/ccr/projects/aciceri/{repo.name}/.git\n"
f"repo.desc={repo.description}\n"
])
'';
in {
with open(c, "w") as f:
for repo in Github().get_user("aciceri").get_repos():
f.writelines([
f"repo.url={repo.name}\n"
f"repo.path=/home/ccr/projects/aciceri/{repo.name}/.git\n"
f"repo.desc={repo.description}\n"
])
'';
in
{
services.nginx.virtualHosts."git.aciceri.dev" = {
cgit = {
enable = true;
@ -31,10 +34,12 @@ in {
virtual-root = "/";
cache-size = 1000;
include = [
(builtins.toString (pkgs.writeText "cgit-extra" ''
source-filter=${pkgs.cgit-pink}/lib/cgit/filters/syntax-highlighting.py
about-filter=${pkgs.cgit-pink}/lib/cgit/filters/about-formatting.sh
''))
(builtins.toString (
pkgs.writeText "cgit-extra" ''
source-filter=${pkgs.cgit-pink}/lib/cgit/filters/syntax-highlighting.py
about-filter=${pkgs.cgit-pink}/lib/cgit/filters/about-formatting.sh
''
))
repos-path
];
};
@ -48,13 +53,13 @@ in {
Type = "oneshot";
RemainAfterExit = true;
};
wantedBy = ["multi-user.target"];
wantedBy = [ "multi-user.target" ];
script = builtins.toString cgit-setup-repos;
};
systemd.timers.cgit-setup-repos = {
wantedBy = ["timers.target"];
partOf = ["cgit-setup-repos.service"];
wantedBy = [ "timers.target" ];
partOf = [ "cgit-setup-repos.service" ];
timerConfig = {
OnCalendar = "*-*-* 4:00:00"; # daily at 4 AM
Unit = "cgit-setup-repos.service";

View file

@ -4,134 +4,149 @@
pkgs,
...
}:
with lib; let
with lib;
let
globalConfig = config;
settingsFormat = {
type = with lib.types; let
value =
oneOf [int str]
// {
description = "INI-like atom (int or string)";
};
values =
coercedTo value lib.singleton (listOf value)
// {
type =
with lib.types;
let
value =
oneOf [
int
str
]
// {
description = "INI-like atom (int or string)";
};
values = coercedTo value lib.singleton (listOf value) // {
description = value.description + " or a list of them for duplicate keys";
};
in
in
attrsOf values;
generate = name: values:
pkgs.writeText name (lib.generators.toKeyValue {listsAsDuplicateKeys = true;} values);
generate =
name: values:
pkgs.writeText name (lib.generators.toKeyValue { listsAsDuplicateKeys = true; } values);
};
in {
in
{
imports = [
../nginx-base
./config.nix
];
options.services.nginx.virtualHosts = mkOption {
type = types.attrsOf (types.submodule ({config, ...}: let
cfg = config.cgit;
type = types.attrsOf (
types.submodule (
{ config, ... }:
let
cfg = config.cgit;
# These are the global options for this submodule, but for nicer UX they
# are inlined into the freeform settings. Hence they MUST NOT INTERSECT
# with any settings from cgitrc!
options = {
enable = mkEnableOption "cgit";
# These are the global options for this submodule, but for nicer UX they
# are inlined into the freeform settings. Hence they MUST NOT INTERSECT
# with any settings from cgitrc!
options = {
enable = mkEnableOption "cgit";
location = mkOption {
default = "/";
type = types.str;
description = ''
Location to serve cgit on.
'';
};
};
location = mkOption {
default = "/";
type = types.str;
description = ''
Location to serve cgit on.
'';
};
};
# Remove the global options for serialization into cgitrc
settings = removeAttrs cfg (attrNames options);
in {
options.cgit = mkOption {
type = types.submodule {
freeformType = settingsFormat.type;
inherit options;
config = {
css = mkDefault "/cgit.css";
logo = mkDefault "/cgit.png";
favicon = mkDefault "/favicon.ico";
# Remove the global options for serialization into cgitrc
settings = removeAttrs cfg (attrNames options);
in
{
options.cgit = mkOption {
type = types.submodule {
freeformType = settingsFormat.type;
inherit options;
config = {
css = mkDefault "/cgit.css";
logo = mkDefault "/cgit.png";
favicon = mkDefault "/favicon.ico";
};
};
default = { };
example = literalExample ''
{
enable = true;
virtual-root = "/";
source-filter = "''${pkgs.cgit-pink}/lib/cgit/filters/syntax-highlighting.py";
about-filter = "''${pkgs.cgit-pink}/lib/cgit/filters/about-formatting.sh";
cache-size = 1000;
scan-path = "/srv/git";
include = [
(builtins.toFile "cgitrc-extra-1" '''
# Anything that has to be in a particular order
''')
(builtins.toFile "cgitrc-extra-2" '''
# Anything that has to be in a particular order
''')
];
}
'';
description = ''
Verbatim contents of the cgit runtime configuration file. Documentation
(with cgitrc example file) is available in "man cgitrc". Or online:
http://git.zx2c4.com/cgit/tree/cgitrc.5.txt
'';
};
};
default = {};
example = literalExample ''
{
enable = true;
virtual-root = "/";
source-filter = "''${pkgs.cgit-pink}/lib/cgit/filters/syntax-highlighting.py";
about-filter = "''${pkgs.cgit-pink}/lib/cgit/filters/about-formatting.sh";
cache-size = 1000;
scan-path = "/srv/git";
include = [
(builtins.toFile "cgitrc-extra-1" '''
# Anything that has to be in a particular order
''')
(builtins.toFile "cgitrc-extra-2" '''
# Anything that has to be in a particular order
''')
];
}
'';
description = ''
Verbatim contents of the cgit runtime configuration file. Documentation
(with cgitrc example file) is available in "man cgitrc". Or online:
http://git.zx2c4.com/cgit/tree/cgitrc.5.txt
'';
};
config = let
location = removeSuffix "/" cfg.location;
in
mkIf cfg.enable {
locations."${location}/" = {
root = "${pkgs.cgit-pink}/cgit/";
tryFiles = "$uri @cgit";
};
locations."~ ^${location}/(cgit.(css|png)|favicon.ico|robots.txt)$" = {
alias = "${pkgs.cgit-pink}/cgit/$1";
};
locations."~ ^${location}/custom.css$" = {
alias = ./custom.css;
};
locations."@cgit" = {
extraConfig =
''
include ${pkgs.nginx}/conf/fastcgi_params;
fastcgi_param CGIT_CONFIG ${settingsFormat.generate "cgitrc" settings};
fastcgi_param SCRIPT_FILENAME ${pkgs.cgit-pink}/cgit/cgit.cgi;
fastcgi_param QUERY_STRING $args;
fastcgi_param HTTP_HOST $server_name;
fastcgi_pass unix:${globalConfig.services.fcgiwrap.socketAddress};
''
+ (
if cfg.location == "/"
then ''
fastcgi_param PATH_INFO $uri;
''
else ''
fastcgi_split_path_info ^(${location}/)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
''
);
};
};
}));
config =
let
location = removeSuffix "/" cfg.location;
in
mkIf cfg.enable {
locations."${location}/" = {
root = "${pkgs.cgit-pink}/cgit/";
tryFiles = "$uri @cgit";
};
locations."~ ^${location}/(cgit.(css|png)|favicon.ico|robots.txt)$" = {
alias = "${pkgs.cgit-pink}/cgit/$1";
};
locations."~ ^${location}/custom.css$" = {
alias = ./custom.css;
};
locations."@cgit" = {
extraConfig =
''
include ${pkgs.nginx}/conf/fastcgi_params;
fastcgi_param CGIT_CONFIG ${settingsFormat.generate "cgitrc" settings};
fastcgi_param SCRIPT_FILENAME ${pkgs.cgit-pink}/cgit/cgit.cgi;
fastcgi_param QUERY_STRING $args;
fastcgi_param HTTP_HOST $server_name;
fastcgi_pass unix:${globalConfig.services.fcgiwrap.socketAddress};
''
+ (
if cfg.location == "/" then
''
fastcgi_param PATH_INFO $uri;
''
else
''
fastcgi_split_path_info ^(${location}/)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
''
);
};
};
}
)
);
};
config = let
vhosts = config.services.nginx.virtualHosts;
in
config =
let
vhosts = config.services.nginx.virtualHosts;
in
mkIf (any (name: vhosts.${name}.cgit.enable) (attrNames vhosts)) {
# make the cgitrc manpage available
environment.systemPackages = [pkgs.cgit-pink];
environment.systemPackages = [ pkgs.cgit-pink ];
services.fcgiwrap.enable = true;
};