git.iko.soy/typeable/nixpkgs
on master help sign in
gitolite: wrap gitolite-shell

git wasn't found when used with services.fcgiwrap for http auth

commit9314dc43b3ded4e27652324724df1edad084d765 authorBruno Bigras <bigras.bruno@gmail.com> dateWed 4 Dec 2019, 18:10 (7 years ago) parent0ccde69
3 files changed+103−2
nixos/tests/all-tests.nix+1 nixos/tests/gitolite-fcgiwrap.nix+93 pkgs/applications/version-management/gitolite/default.nix+9−2
nixos/tests/all-tests.nix+1
@@ -94,6 +94,7 @@ in
9494 gitea = handleTest ./gitea.nix {};
9595 gitlab = handleTest ./gitlab.nix {};
9696 gitolite = handleTest ./gitolite.nix {};
97+ gitolite-fcgiwrap = handleTest ./gitolite-fcgiwrap.nix {};
9798 glusterfs = handleTest ./glusterfs.nix {};
9899 gnome3-xorg = handleTest ./gnome3-xorg.nix {};
99100 gnome3 = handleTest ./gnome3.nix {};
nixos/tests/gitolite-fcgiwrap.nixnew file+93
@@ -0,0 +1,93 @@
1+import ./make-test-python.nix (
2+ { pkgs, ... }:
3+
4+ let
5+ user = "gitolite-admin";
6+ password = "some_password";
7+
8+ # not used but needed to setup gitolite
9+ adminPublicKey = ''
10+ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO7urFhAA90BTpGuEHeWWTY3W/g9PBxXNxfWhfbrm4Le root@client
11+ '';
12+ in
13+ {
14+ name = "gitolite-fcgiwrap";
15+
16+ meta = with pkgs.stdenv.lib.maintainers; {
17+ maintainers = [ bbigras ];
18+ };
19+
20+ nodes = {
21+
22+ server =
23+ { ... }:
24+ {
25+ networking.firewall.allowedTCPPorts = [ 80 ];
26+
27+ services.fcgiwrap.enable = true;
28+ services.gitolite = {
29+ enable = true;
30+ adminPubkey = adminPublicKey;
31+ };
32+
33+ services.nginx = {
34+ enable = true;
35+ recommendedProxySettings = true;
36+ virtualHosts."server".locations."/git".extraConfig = ''
37+ # turn off gzip as git objects are already well compressed
38+ gzip off;
39+
40+ # use file based basic authentication
41+ auth_basic "Git Repository Authentication";
42+ auth_basic_user_file /etc/gitolite/htpasswd;
43+
44+ # common FastCGI parameters are required
45+ include ${pkgs.nginx}/conf/fastcgi_params;
46+
47+ # strip the CGI program prefix
48+ fastcgi_split_path_info ^(/git)(.*)$;
49+ fastcgi_param PATH_INFO $fastcgi_path_info;
50+
51+ # pass authenticated user login(mandatory) to Gitolite
52+ fastcgi_param REMOTE_USER $remote_user;
53+
54+ # pass git repository root directory and hosting user directory
55+ # these env variables can be set in a wrapper script
56+ fastcgi_param GIT_HTTP_EXPORT_ALL "";
57+ fastcgi_param GIT_PROJECT_ROOT /var/lib/gitolite/repositories;
58+ fastcgi_param GITOLITE_HTTP_HOME /var/lib/gitolite;
59+ fastcgi_param SCRIPT_FILENAME ${pkgs.gitolite}/bin/gitolite-shell;
60+
61+ # use Unix domain socket or inet socket
62+ fastcgi_pass unix:/run/fcgiwrap.sock;
63+ '';
64+ };
65+
66+ # WARNING: DON'T DO THIS IN PRODUCTION!
67+ # This puts unhashed secrets directly into the Nix store for ease of testing.
68+ environment.etc."gitolite/htpasswd".source = pkgs.runCommand "htpasswd" {} ''
69+ ${pkgs.apacheHttpd}/bin/htpasswd -bc "$out" ${user} ${password}
70+ '';
71+ };
72+
73+ client =
74+ { pkgs, ... }:
75+ {
76+ environment.systemPackages = [ pkgs.git ];
77+ };
78+ };
79+
80+ testScript = ''
81+ start_all()
82+
83+ server.wait_for_unit("gitolite-init.service")
84+ server.wait_for_unit("nginx.service")
85+ server.wait_for_file("/run/fcgiwrap.sock")
86+
87+ client.wait_for_unit("multi-user.target")
88+ client.succeed(
89+ "git clone http://${user}:${password}@server/git/gitolite-admin.git"
90+ )
91+ '';
92+ }
93+)
pkgs/applications/version-management/gitolite/default.nix+9−2
@@ -1,4 +1,4 @@
1−{ stdenv, fetchFromGitHub, git, nettools, perl }:
1+{ stdenv, fetchFromGitHub, git, lib, makeWrapper, nettools, perl }:
22
33stdenv.mkDerivation rec {
44 pname = "gitolite";
@@ -11,7 +11,9 @@ stdenv.mkDerivation rec {
1111 sha256 = "1rkj7gknwjlc5ij9w39zf5mr647bm45la57yjczydmvrb8c56yrh";
1212 };
1313
14− buildInputs = [ git nettools perl ];
14+ buildInputs = [ nettools perl ];
15+ nativeBuildInputs = [ makeWrapper ];
16+ propagatedBuildInputs = [ git ];
1517
1618 dontBuild = true;
1719
@@ -25,6 +27,11 @@ stdenv.mkDerivation rec {
2527 --replace hostname "${nettools}/bin/hostname"
2628 '';
2729
30+ postFixup = ''
31+ wrapProgram $out/bin/gitolite-shell \
32+ --prefix PATH : "${git}/bin"
33+ '';
34+
2835 installPhase = ''
2936 mkdir -p $out/bin
3037 perl ./install -to $out/bin