From 45f06d9712bdd6ee8084065bbd0776d73982fd6e Mon Sep 17 00:00:00 2001 From: schnusch Date: Mon, 1 Aug 2022 11:27:29 +0200 Subject: [PATCH] nixos/cgit: add package option --- nixos/modules/services/networking/cgit.nix | 6 ++++-- nixos/tests/cgit.nix | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/networking/cgit.nix b/nixos/modules/services/networking/cgit.nix index d2db1c294e67..672b0b030eee 100644 --- a/nixos/modules/services/networking/cgit.nix +++ b/nixos/modules/services/networking/cgit.nix @@ -100,6 +100,8 @@ in options = { enable = mkEnableOption (mdDoc "cgit"); + package = mkPackageOptionMD pkgs "cgit" {}; + nginx.virtualHost = mkOption { description = mdDoc "VirtualHost to serve cgit on, defaults to the attribute name."; type = types.str; @@ -172,7 +174,7 @@ in [ "cgit.css" "cgit.png" "favicon.ico" "robots.txt" ] (name: nameValuePair "= ${stripLocation cfg}/${name}" { extraConfig = '' - alias ${pkgs.cgit}/cgit/${name}; + alias ${cfg.package}/cgit/${name}; ''; }) ) // { @@ -187,7 +189,7 @@ in }; "${stripLocation cfg}/" = { fastcgiParams = { - SCRIPT_FILENAME = "${pkgs.cgit}/cgit/cgit.cgi"; + SCRIPT_FILENAME = "${cfg.package}/cgit/cgit.cgi"; QUERY_STRING = "$args"; HTTP_HOST = "$server_name"; CGIT_CONFIG = mkCgitrc cfg; diff --git a/nixos/tests/cgit.nix b/nixos/tests/cgit.nix index 207f7d13fd84..6aed06adefdf 100644 --- a/nixos/tests/cgit.nix +++ b/nixos/tests/cgit.nix @@ -1,4 +1,10 @@ -import ./make-test-python.nix ({ pkgs, ...} : { +import ./make-test-python.nix ({ pkgs, ... }: +let + robotsTxt = pkgs.writeText "cgit-robots.txt" '' + User-agent: * + Disallow: / + ''; +in { name = "cgit"; meta = with pkgs.lib.maintainers; { maintainers = [ schnusch ]; @@ -8,6 +14,12 @@ import ./make-test-python.nix ({ pkgs, ...} : { server = { ... }: { services.cgit."localhost" = { enable = true; + package = pkgs.cgit.overrideAttrs ({ postInstall, ... }: { + postInstall = '' + ${postInstall} + cp ${robotsTxt} "$out/cgit/robots.txt" + ''; + }); nginx.location = "/(c)git/"; repos = { some-repo = { @@ -28,7 +40,9 @@ import ./make-test-python.nix ({ pkgs, ...} : { server.wait_for_unit("network.target") server.wait_for_open_port(80) - server.succeed("curl -fsS http://localhost/%28c%29git/robots.txt") + server.succeed("curl -fsS http://localhost/%28c%29git/cgit.css") + + server.succeed("curl -fsS http://localhost/%28c%29git/robots.txt | diff -u - ${robotsTxt}") server.succeed( "curl -fsS http://localhost/%28c%29git/ | grep -F 'some-repo description'"