krebs.git.cgit: make cache-root configurable

... along with all the other stuff :)
This commit is contained in:
tv 2016-06-07 03:14:21 +02:00
parent 6fcc35afb0
commit 4a34b27c1c
9 changed files with 200 additions and 120 deletions

View File

@ -25,6 +25,11 @@ let
type = types.submodule { type = types.submodule {
options = { options = {
enable = mkEnableOption "krebs.git.cgit" // { default = true; }; enable = mkEnableOption "krebs.git.cgit" // { default = true; };
settings = mkOption {
apply = flip removeAttrs ["_module"];
default = {};
type = subtypes.cgit-settings;
};
}; };
}; };
default = {}; default = {};
@ -66,22 +71,6 @@ let
Repositories. Repositories.
''; '';
}; };
root-desc = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Text printed below the heading on the repository index page.
Default value: "a fast webinterface for the git dscm".
'';
};
root-title = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Text printed as heading on the repository index page.
Default value: "Git Repository Browser".
'';
};
rules = mkOption { rules = mkOption {
type = types.listOf subtypes.rule; type = types.listOf subtypes.rule;
default = []; default = [];
@ -102,8 +91,101 @@ let
# TODO put into krebs/4lib/types.nix? # TODO put into krebs/4lib/types.nix?
subtypes = { subtypes = {
repo = types.submodule ({ cgit-settings = types.submodule {
# A setting's value of `null` means cgit's default should be used.
options = { options = {
cache-root = mkOption {
type = types.absolute-pathname;
default = "/tmp/cgit";
};
cache-size = mkOption {
type = types.uint;
default = 1000;
};
css = mkOption {
type = types.absolute-pathname;
default = "/static/cgit.css";
};
enable-commit-graph = mkOption {
type = types.bool;
default = true;
};
enable-index-links = mkOption {
type = types.bool;
default = true;
};
enable-index-owner = mkOption {
type = types.bool;
default = false;
};
enable-log-filecount = mkOption {
type = types.bool;
default = true;
};
enable-log-linecount = mkOption {
type = types.bool;
default = true;
};
enable-remote-branches = mkOption {
type = types.bool;
default = true;
};
logo = mkOption {
type = types.absolute-pathname;
default = "/static/cgit.png";
};
max-stats = mkOption {
type =
types.nullOr (types.enum ["week" "month" "quarter" "year"]);
default = "year";
};
robots = mkOption {
type = types.nullOr (types.listOf types.str);
default = ["nofollow" "noindex"];
};
root-desc = mkOption {
type = types.nullOr types.str;
default = null;
};
root-title = mkOption {
type = types.nullOr types.str;
default = null;
};
};
};
repo = types.submodule ({ config, ... }: {
options = {
cgit = {
desc = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Repository description.
'';
};
path = mkOption {
type = types.str;
default = "${cfg.dataDir}/${config.name}";
description = ''
An absolute path to the repository directory. For non-bare
repositories this is the .git-directory.
'';
};
section = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Repository section.
'';
};
url = mkOption {
type = types.str;
default = config.name;
description = ''
The relative url used to access the repository.
'';
};
};
collaborators = mkOption { collaborators = mkOption {
type = types.listOf types.user; type = types.listOf types.user;
default = []; default = [];
@ -115,20 +197,6 @@ let
an example. an example.
''; '';
}; };
desc = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Repository description.
'';
};
section = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Repository section.
'';
};
name = mkOption { name = mkOption {
type = types.str; type = types.str;
description = '' description = ''
@ -266,43 +334,34 @@ let
# socketType = "unix" (default) # socketType = "unix" (default)
}; };
environment.etc."cgitrc".text = '' environment.etc."cgitrc".text = let
css=/static/cgit.css repo-to-cgitrc = _: repo:
logo=/static/cgit.png optionals (isPublicRepo repo) (concatLists [
[""] # empty line
[(kv-to-cgitrc "repo.url" repo.cgit.url)]
(mapAttrsToList kv-to-cgitrc
(mapAttrs' (k: nameValuePair "repo.${k}")
(removeAttrs repo.cgit ["url"])))
]);
# if you do not want that webcrawler (like google) index your site kv-to-cgitrc = k: v: getAttr (typeOf v) {
robots=noindex, nofollow bool = kv-to-cgitrc k (if v then 1 else 0);
null = []; # This will be removed by `flatten`.
virtual-root=/ list = "${k}=${concatStringsSep ", " v}";
int = "${k}=${toString v}";
# TODO make this nicer (and/or somewhere else) string = "${k}=${v}";
cache-root=/tmp/cgit };
in
cache-size=1000 concatStringsSep "\n"
enable-commit-graph=1 (flatten (
enable-index-links=1 mapAttrsToList kv-to-cgitrc cfg.cgit.settings
enable-index-owner=0 ++
enable-log-filecount=1 mapAttrsToList repo-to-cgitrc cfg.repos
enable-log-linecount=1 ));
enable-remote-branches=1
${optionalString (cfg.root-title != null) "root-title=${cfg.root-title}"}
${optionalString (cfg.root-desc != null) "root-desc=${cfg.root-desc}"}
snapshots=0
max-stats=year
${concatMapStringsSep "\n" (repo: ''
repo.url=${repo.name}
repo.path=${cfg.dataDir}/${repo.name}
${optionalString (repo.section != null) "repo.section=${repo.section}"}
${optionalString (repo.desc != null) "repo.desc=${repo.desc}"}
'') (filter isPublicRepo (attrValues cfg.repos))}
'';
system.activationScripts.cgit = '' system.activationScripts.cgit = ''
mkdir -m 0700 -p /tmp/cgit mkdir -m 0700 -p ${cfg.cgit.settings.cache-root}
chown ${toString fcgitwrap-user.uid}:${toString fcgitwrap-group.gid} /tmp/cgit chown ${toString fcgitwrap-user.uid}:${toString fcgitwrap-group.gid} ${cfg.cgit.settings.cache-root}
''; '';
krebs.nginx = { krebs.nginx = {

View File

@ -41,7 +41,6 @@ let out = rec {
mapAttrs (name: _: path + "/${name}") mapAttrs (name: _: path + "/${name}")
(filterAttrs (_: eq "directory") (readDir path)); (filterAttrs (_: eq "directory") (readDir path));
mapAttrValues = f: mapAttrs (_: f);
setAttr = name: value: set: set // { ${name} = value; }; setAttr = name: value: set: set // { ${name} = value; };
optionalTrace = c: msg: x: if c then trace msg x else x; optionalTrace = c: msg: x: if c then trace msg x else x;

View File

@ -7,8 +7,12 @@ let
out = { out = {
krebs.git = { krebs.git = {
enable = true; enable = true;
root-title = "public repositories at ${config.krebs.build.host.name}"; cgit = {
root-desc = "keep calm and engage"; settings = {
root-title = "public repositories at ${config.krebs.build.host.name}";
root-desc = "keep calm and engage";
};
};
repos = mapAttrs (_: s: removeAttrs s ["collaborators"]) repos; repos = mapAttrs (_: s: removeAttrs s ["collaborators"]) repos;
rules = rules; rules = rules;
}; };
@ -27,7 +31,7 @@ let
public-repos = mapAttrs make-public-repo { public-repos = mapAttrs make-public-repo {
painload = {}; painload = {};
stockholm = { stockholm = {
desc = "take all the computers hostage, they'll love you!"; cgit.desc = "take all the computers hostage, they'll love you!";
}; };
wai-middleware-time = {}; wai-middleware-time = {};
web-routes-wai-custom = {}; web-routes-wai-custom = {};
@ -52,8 +56,8 @@ let
import <secrets/repos.nix> { inherit config lib pkgs; } import <secrets/repos.nix> { inherit config lib pkgs; }
); );
make-public-repo = name: { desc ? null, ... }: { make-public-repo = name: { cgit ? {}, ... }: {
inherit name desc; inherit cgit name;
public = true; public = true;
hooks = { hooks = {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {
@ -66,13 +70,13 @@ let
}; };
}; };
make-public-repo-silent = name: { desc ? null, ... }: { make-public-repo-silent = name: { cgit ? {}, ... }: {
inherit name desc; inherit cgit name;
public = true; public = true;
}; };
make-restricted-repo = name: { collaborators ? [], desc ? null, ... }: { make-restricted-repo = name: { collaborators ? [], ... }: {
inherit name collaborators desc; inherit collaborators name;
public = false; public = false;
}; };

View File

@ -7,9 +7,7 @@ let
rules = concatMap krebs-rules (attrValues krebs-repos) ++ concatMap priv-rules (attrValues priv-repos); rules = concatMap krebs-rules (attrValues krebs-repos) ++ concatMap priv-rules (attrValues priv-repos);
krebs-repos = mapAttrs make-krebs-repo { krebs-repos = mapAttrs make-krebs-repo {
brain = { brain = { };
desc = "braiiiins";
};
}; };
priv-repos = mapAttrs make-priv-repo { priv-repos = mapAttrs make-priv-repo {
@ -18,13 +16,13 @@ let
}; };
# TODO move users to separate module # TODO move users to separate module
make-priv-repo = name: { desc ? null, ... }: { make-priv-repo = name: { ... }: {
inherit name desc; inherit name;
public = false; public = false;
}; };
make-krebs-repo = with git; name: { desc ? null, ... }: { make-krebs-repo = with git; name: { ... }: {
inherit name desc; inherit name;
public = false; public = false;
hooks = { hooks = {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {
@ -63,7 +61,7 @@ in {
imports = [ ]; imports = [ ];
krebs.git = { krebs.git = {
enable = true; enable = true;
cgit = false; cgit.enable = false;
inherit repos rules; inherit repos rules;
}; };
} }

View File

@ -10,17 +10,17 @@ let
krebs-repos = mapAttrs make-krebs-repo { krebs-repos = mapAttrs make-krebs-repo {
stockholm = { stockholm = {
desc = "Make all the systems into 1systems!"; cgit.desc = "Make all the systems into 1systems!";
}; };
tinc_graphs = { tinc_graphs = {
desc = "Tinc Advanced Graph Generation"; cgit.desc = "Tinc Advanced Graph Generation";
}; };
stockholm-init = { stockholm-init = {
desc = "Build new Stockholm hosts"; cgit.desc = "Build new Stockholm hosts";
}; };
cac-api = { }; cac-api = { };
init-stockholm = { init-stockholm = {
desc = "Init stuff for stockholm"; cgit.desc = "Init stuff for stockholm";
}; };
}; };
@ -32,19 +32,19 @@ let
connector = { }; connector = { };
minikrebs = { }; minikrebs = { };
mattermost = { mattermost = {
desc = "Mattermost Docker files"; cgit.desc = "Mattermost Docker files";
}; };
}; };
# TODO move users to separate module # TODO move users to separate module
make-priv-repo = name: { desc ? null, ... }: { make-priv-repo = name: { ... }: {
inherit name desc; inherit name;
public = false; public = false;
}; };
make-krebs-repo = with git; name: { desc ? null, ... }: { make-krebs-repo = with git; name: { cgit ? {}, ... }: {
inherit name desc; inherit cgit name;
public = true; public = true;
hooks = { hooks = {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {
@ -88,8 +88,12 @@ let
in { in {
krebs.git = { krebs.git = {
enable = true; enable = true;
root-title = "public repositories"; cgit = {
root-desc = "keep on krebsing"; settings = {
root-title = "public repositories";
root-desc = "keep on krebsing";
};
};
inherit repos rules; inherit repos rules;
}; };
} }

View File

@ -7,8 +7,12 @@ let
out = { out = {
krebs.git = { krebs.git = {
enable = true; enable = true;
root-title = "public repositories at ${config.krebs.build.host.name}"; cgit = {
root-desc = "keep calm and engage"; settings = {
root-title = "public repositories at ${config.krebs.build.host.name}";
root-desc = "keep calm and engage";
};
};
repos = mapAttrs (_: s: removeAttrs s ["collaborators"]) repos; repos = mapAttrs (_: s: removeAttrs s ["collaborators"]) repos;
rules = rules; rules = rules;
}; };
@ -27,7 +31,7 @@ let
public-repos = mapAttrs make-public-repo { public-repos = mapAttrs make-public-repo {
painload = {}; painload = {};
stockholm = { stockholm = {
desc = "take all the computers hostage, they'll love you!"; cgit.desc = "take all the computers hostage, they'll love you!";
}; };
#wai-middleware-time = {}; #wai-middleware-time = {};
#web-routes-wai-custom = {}; #web-routes-wai-custom = {};
@ -46,8 +50,8 @@ let
import <secrets/repos.nix> { inherit config lib pkgs; } import <secrets/repos.nix> { inherit config lib pkgs; }
); );
make-public-repo = name: { desc ? null, ... }: { make-public-repo = name: { cgit ? {}, ... }: {
inherit name desc; inherit cgit name;
public = true; public = true;
hooks = { hooks = {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {
@ -60,8 +64,8 @@ let
}; };
}; };
make-restricted-repo = name: { collaborators ? [], desc ? null, ... }: { make-restricted-repo = name: { collaborators ? [], ... }: {
inherit name collaborators desc; inherit collaborators name;
public = false; public = false;
}; };

View File

@ -7,8 +7,12 @@ let
out = { out = {
krebs.git = { krebs.git = {
enable = true; enable = true;
root-title = "public repositories at ${config.krebs.build.host.name}"; cgit = {
root-desc = "Hmhmh, im Moment nicht."; settings = {
root-title = "public repositories at ${config.krebs.build.host.name}";
root-desc = "Hmhmh, im Moment nicht.";
};
};
repos = mapAttrs (_: s: removeAttrs s ["collaborators"]) repos; repos = mapAttrs (_: s: removeAttrs s ["collaborators"]) repos;
rules = rules; rules = rules;
}; };
@ -22,8 +26,8 @@ let
stockholm = {}; stockholm = {};
}; };
make-public-repo = name: { desc ? null, section ? null, ... }: { make-public-repo = name: { cgit ? {}, ... }: {
inherit name desc section; inherit cgit name;
public = true; public = true;
hooks = { hooks = {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {

View File

@ -11,7 +11,7 @@ let
stockholm-mirror = { stockholm-mirror = {
public = true; public = true;
name = "stockholm-mirror"; name = "stockholm-mirror";
desc = "mirror for all stockholm branches"; cgit.desc = "mirror for all stockholm branches";
hooks = { hooks = {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {
nick = config.networking.hostName; nick = config.networking.hostName;
@ -33,8 +33,12 @@ in {
krebs.users.wolf-repo-sync = wolf-repo-sync; krebs.users.wolf-repo-sync = wolf-repo-sync;
krebs.git = { krebs.git = {
enable = true; enable = true;
root-title = "Shared Repos"; cgit = {
root-desc = "keep on krebsing"; settings = {
root-title = "Shared Repos";
root-desc = "keep on krebsing";
};
};
inherit rules; inherit rules;
repos.stockholm-mirror = stockholm-mirror; repos.stockholm-mirror = stockholm-mirror;
}; };

View File

@ -7,8 +7,12 @@ let
out = { out = {
krebs.git = { krebs.git = {
enable = true; enable = true;
root-title = "repositories at ${config.krebs.build.host.name}"; cgit = {
root-desc = "mostly krebs"; settings = {
root-title = "repositories at ${config.krebs.build.host.name}";
root-desc = "mostly krebs";
};
};
repos = repos; repos = repos;
rules = rules; rules = rules;
}; };
@ -21,9 +25,9 @@ let
rules = concatMap make-rules (attrValues repos); rules = concatMap make-rules (attrValues repos);
public-repos = mapAttrs make-public-repo ({ public-repos = mapAttrs make-public-repo ({
} // mapAttrValues (setAttr "section" "1. miscellaneous") { } // mapAttrs (_: recursiveUpdate { cgit.section = "1. miscellaneous"; }) {
cac-api = { cac-api = {
desc = "CloudAtCost API command line interface"; cgit.desc = "CloudAtCost API command line interface";
}; };
get = {}; get = {};
hack = {}; hack = {};
@ -35,13 +39,13 @@ let
push = {}; push = {};
regfish = {}; regfish = {};
soundcloud = { soundcloud = {
desc = "SoundCloud command line interface"; cgit.desc = "SoundCloud command line interface";
}; };
stockholm = { stockholm = {
desc = "NixOS configuration"; cgit.desc = "NixOS configuration";
}; };
with-tmpdir = {}; with-tmpdir = {};
} // mapAttrValues (setAttr "section" "2. Haskell libraries") { } // mapAttrs (_: recursiveUpdate { cgit.section = "2. Haskell libraries"; }) {
blessings = {}; blessings = {};
mime = {}; mime = {};
quipper = {}; quipper = {};
@ -50,7 +54,7 @@ let
web-routes-wai-custom = {}; web-routes-wai-custom = {};
xintmap = {}; xintmap = {};
xmonad-stockholm = {}; xmonad-stockholm = {};
} // mapAttrValues (setAttr "section" "3. museum") { } // mapAttrs (_: recursiveUpdate { cgit.section = "3. museum"; }) {
cgserver = {}; cgserver = {};
crude-mail-setup = {}; crude-mail-setup = {};
dot-xmonad = {}; dot-xmonad = {};
@ -68,8 +72,8 @@ let
import <secrets/repos.nix> { inherit config lib pkgs; } import <secrets/repos.nix> { inherit config lib pkgs; }
); );
make-public-repo = name: { desc ? null, section ? null, ... }: { make-public-repo = name: { cgit ? {}, ... }: {
inherit name desc section; inherit cgit name;
public = true; public = true;
hooks = optionalAttrs (config.krebs.build.host.name == "cd") { hooks = optionalAttrs (config.krebs.build.host.name == "cd") {
post-receive = pkgs.git-hooks.irc-announce { post-receive = pkgs.git-hooks.irc-announce {
@ -82,8 +86,8 @@ let
}; };
}; };
make-restricted-repo = name: { collaborators ? [], desc ? null, ... }: { make-restricted-repo = name: { collaborators ? [], ... }: {
inherit name collaborators desc; inherit collaborators name;
public = false; public = false;
}; };