diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 23:15:08 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 23:15:08 +0100 |
commit | 01f21083a897b86bf148f1d2bb9c8edca4d3786a (patch) | |
tree | 784f04e9b6ef99a49e572c84e4b7ab40b5eb5fde /nixops/modules/gitolite | |
parent | bfe3c9c9df0c5112bc8806483292b55ed0f7e02d (diff) | |
download | Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.gz Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.zst Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.zip |
Rename virtual folder to nixops
Fixes https://git.immae.eu/mantisbt/view.php?id=82
Diffstat (limited to 'nixops/modules/gitolite')
-rw-r--r-- | nixops/modules/gitolite/default.nix | 75 | ||||
-rwxr-xr-x | nixops/modules/gitolite/gitolite_ldap_groups.sh | 15 |
2 files changed, 90 insertions, 0 deletions
diff --git a/nixops/modules/gitolite/default.nix b/nixops/modules/gitolite/default.nix new file mode 100644 index 0000000..21eabc4 --- /dev/null +++ b/nixops/modules/gitolite/default.nix | |||
@@ -0,0 +1,75 @@ | |||
1 | { lib, pkgs, config, myconfig, mylibs, ... }: | ||
2 | let | ||
3 | cfg = config.services.myGitolite; | ||
4 | in { | ||
5 | options.services.myGitolite = { | ||
6 | enable = lib.mkEnableOption "my gitolite service"; | ||
7 | gitoliteDir = lib.mkOption { | ||
8 | type = lib.types.string; | ||
9 | default = "/var/lib/gitolite"; | ||
10 | }; | ||
11 | }; | ||
12 | |||
13 | config = lib.mkIf cfg.enable { | ||
14 | nixpkgs.config.packageOverrides = oldpkgs: rec { | ||
15 | gitolite = oldpkgs.gitolite.overrideAttrs(old: rec { | ||
16 | name = "gitolite-${version}"; | ||
17 | version = "3.6.10"; | ||
18 | src = pkgs.fetchFromGitHub { | ||
19 | owner = "sitaramc"; | ||
20 | repo = "gitolite"; | ||
21 | rev = "v${version}"; | ||
22 | sha256 = "0p2697mn6rwm03ndlv7q137zczai82n41aplq1g006ii7f12xy8h"; | ||
23 | }; | ||
24 | }); | ||
25 | }; | ||
26 | |||
27 | networking.firewall.allowedTCPPorts = [ 9418 ]; | ||
28 | |||
29 | services.gitDaemon = { | ||
30 | enable = true; | ||
31 | user = "gitolite"; | ||
32 | group = "gitolite"; | ||
33 | basePath = "${cfg.gitoliteDir}/repositories"; | ||
34 | }; | ||
35 | |||
36 | system.activationScripts.gitolite = let | ||
37 | gitolite_ldap_groups = mylibs.wrap { | ||
38 | name = "gitolite_ldap_groups.sh"; | ||
39 | file = ./gitolite_ldap_groups.sh; | ||
40 | vars = { | ||
41 | LDAP_PASS = myconfig.env.tools.gitolite.ldap.password; | ||
42 | }; | ||
43 | paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.coreutils ]; | ||
44 | }; | ||
45 | in { | ||
46 | deps = [ "users" ]; | ||
47 | text = '' | ||
48 | if [ -d ${cfg.gitoliteDir} ]; then | ||
49 | ln -sf ${gitolite_ldap_groups} ${cfg.gitoliteDir}/gitolite_ldap_groups.sh | ||
50 | chmod g+rx ${cfg.gitoliteDir} | ||
51 | fi | ||
52 | if [ -f ${cfg.gitoliteDir}/projects.list ]; then | ||
53 | chmod g+r ${cfg.gitoliteDir}/projects.list | ||
54 | fi | ||
55 | ''; | ||
56 | }; | ||
57 | |||
58 | users.users.wwwrun.extraGroups = [ "gitolite" ]; | ||
59 | |||
60 | users.users.gitolite.packages = let | ||
61 | python-packages = python-packages: with python-packages; [ | ||
62 | simplejson | ||
63 | urllib3 | ||
64 | ]; | ||
65 | in | ||
66 | [ | ||
67 | (pkgs.python3.withPackages python-packages) | ||
68 | ]; | ||
69 | # Installation: https://git.immae.eu/mantisbt/view.php?id=93 | ||
70 | services.gitolite = { | ||
71 | enable = true; | ||
72 | adminPubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXqRbiHw7QoHADNIEuo4nUT9fSOIEBMdJZH0bkQAxXyJFyCM1IMz0pxsHV0wu9tdkkr36bPEUj2aV5bkYLBN6nxcV2Y49X8bjOSCPfx3n6Own1h+NeZVBj4ZByrFmqCbTxUJIZ2bZKcWOFncML39VmWdsVhNjg0X4NBBehqXRIKr2gt3E/ESAxTYJFm0BnU0baciw9cN0bsRGqvFgf5h2P48CIAfwhVcGmPQnnAwabnosYQzRWxR0OygH5Kd8mePh6FheIRIigfXsDO8f/jdxwut8buvNIf3m5EBr3tUbTsvM+eV3M5vKGt7sk8T64DVtepTSdOOWtp+47ktsnHOMh immae@immae.eu"; | ||
73 | }; | ||
74 | }; | ||
75 | } | ||
diff --git a/nixops/modules/gitolite/gitolite_ldap_groups.sh b/nixops/modules/gitolite/gitolite_ldap_groups.sh new file mode 100755 index 0000000..5f7ef6d --- /dev/null +++ b/nixops/modules/gitolite/gitolite_ldap_groups.sh | |||
@@ -0,0 +1,15 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | uid_param="$1" | ||
4 | ldap_host="ldap.immae.eu" | ||
5 | ldap_binddn="cn=gitolite,ou=services,dc=immae,dc=eu" | ||
6 | ldap_bindpw="$LDAP_PASS" | ||
7 | ldap_searchbase="dc=immae,dc=eu" | ||
8 | ldap_scope="subtree" | ||
9 | |||
10 | ldap_options="-h ${ldap_host} -x -D ${ldap_binddn} -w ${ldap_bindpw} -b ${ldap_searchbase} -s ${ldap_scope}" | ||
11 | |||
12 | ldap_filter="(&(memberOf=cn=groups,cn=gitolite,ou=services,dc=immae,dc=eu)(|(member=uid=${uid_param},ou=users,dc=immae,dc=eu)(member=uid=${uid_param},ou=group_users,dc=immae,dc=eu)))" | ||
13 | ldap_result=$(ldapsearch ${ldap_options} -LLL "${ldap_filter}" cn | grep 'cn:' | cut -d' ' -f2) | ||
14 | |||
15 | echo "$ldap_result" | ||