diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2021-02-07 11:15:46 +0100 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2021-02-07 11:15:46 +0100 |
commit | ff0dbde23fedf57102d335e77d0722a228cdd154 (patch) | |
tree | b47fe0a1d0de94ef05d3c94be1fd41a5a18c2df9 /machines | |
parent | e41fc6f599e6e9fcf2958901a7f3f5d68404d2c2 (diff) | |
parent | f79dd737204370494e910b01cacb93cd10c13eeb (diff) | |
download | dots-ff0dbde23fedf57102d335e77d0722a228cdd154.tar.gz dots-ff0dbde23fedf57102d335e77d0722a228cdd154.zip |
Merge branch 'master' of ssh://github.com/pniedzwiedzinski/dots
Diffstat (limited to 'machines')
-rw-r--r-- | machines/srv1/cgit.nix | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/machines/srv1/cgit.nix b/machines/srv1/cgit.nix new file mode 100644 index 0000000..5c0749c --- /dev/null +++ b/machines/srv1/cgit.nix @@ -0,0 +1,99 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.lighttpd.pn-cgit; + pathPrefix = if stringLength cfg.subdir == 0 then "" else "/" + cfg.subdir; + configFile = pkgs.writeText "cgitrc" + '' + # default paths to static assets + css=${pathPrefix}/cgit.css + logo=${pathPrefix}/cgit.png + favicon=${pathPrefix}/favicon.ico + # user configuration + ${cfg.configText} + ''; +in +{ + + options.services.lighttpd.pn-cgit = { + + enable = mkOption { + default = false; + type = types.bool; + description = '' + If true, enable cgit (fast web interface for git repositories) as a + sub-service in lighttpd. + ''; + }; + + subdir = mkOption { + default = "cgit"; + example = ""; + type = types.str; + description = '' + The subdirectory in which to serve cgit. The web application will be + accessible at http://yourserver/''${subdir} + ''; + }; + + logo = mkOption { + default = "${pkgs.cgit}/cgit/cgit.png"; + example = ""; + type = types.str; + description = '' + Logo for your cgit server + ''; + }; + + configText = mkOption { + default = ""; + example = '' + source-filter=''${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py + about-filter=''${pkgs.cgit}/lib/cgit/filters/about-formatting.sh + cache-size=1000 + scan-path=/srv/git + ''; + type = types.lines; + 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 = mkIf cfg.enable { + + # make the cgitrc manpage available + environment.systemPackages = [ pkgs.cgit ]; + + # declare module dependencies + services.lighttpd.enableModules = [ "mod_cgi" "mod_alias" "mod_setenv" ]; + + services.lighttpd.extraConfig = '' + $HTTP["url"] =~ "^/${cfg.subdir}" { + cgi.assign = ( + "cgit.cgi" => "${pkgs.cgit}/cgit/cgit.cgi" + ) + alias.url = ( + "${pathPrefix}/cgit.css" => "${pkgs.cgit}/cgit/cgit.css", + "${pathPrefix}/cgit.png" => "${cfg.logo}", + "${pathPrefix}" => "${pkgs.cgit}/cgit/cgit.cgi" + ) + setenv.add-environment = ( + "CGIT_CONFIG" => "${configFile}" + ) + } + ''; + + systemd.services.lighttpd.preStart = '' + mkdir -p /var/cache/cgit + chown lighttpd:lighttpd /var/cache/cgit + ''; + + }; + +} |