Created
March 14, 2013 14:22
-
-
Save aforemny/5161719 to your computer and use it in GitHub Desktop.
Git repository management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { config, pkgs, ... }: | |
| with pkgs.lib; | |
| let | |
| mainCfg = config.services.git; | |
| repositoryOpts = { name, config, ... }: { | |
| options = { | |
| name = mkOption { | |
| type = with types; uniq string; | |
| description = ""; | |
| }; | |
| users = mkOption { | |
| type = with types; listOf string; | |
| default = []; | |
| description = ""; | |
| }; | |
| }; | |
| config = { | |
| name = mkDefault name; | |
| }; | |
| }; | |
| repositories = concatStrings (map (r: "${r.name} ") | |
| (attrValues mainCfg.repositories)); | |
| in { | |
| options.services.git = { | |
| enable = mkOption { | |
| default = false; | |
| description = ""; | |
| }; | |
| user = mkOption { | |
| default = "git"; | |
| description = ""; | |
| }; | |
| group = mkOption { | |
| default = "git"; | |
| description = ""; | |
| }; | |
| repositories = mkOption { | |
| default = {}; | |
| type = types.loaOf types.optionSet; | |
| description = ""; | |
| options = repositoryOpts; | |
| }; | |
| }; | |
| config = mkIf config.services.git.enable { | |
| environment.systemPackages = [ pkgs.git ]; | |
| users.extraUsers = optionalAttrs (mainCfg.user == "git") | |
| (singleton { name = mainCfg.user; description = "Git user"; }) | |
| ++ concatMap (r: map (u: { name = u; extraGroups = singleton "git-${r.name}"; }) r.users) | |
| (attrValues mainCfg.repositories); | |
| users.extraGroups = optionalAttrs (mainCfg.group == "git") | |
| (singleton { name = "git"; }) | |
| ++ map (r: { name = "git-${r.name}"; }) | |
| (attrValues mainCfg.repositories); | |
| jobs.git = { | |
| startOn = "started network-interfaces"; | |
| stopOn = "stopped network-interfaces"; | |
| preStart = '' | |
| mkdir -m 750 -p /var/srv/git | |
| chown ${mainCfg.user}:${mainCfg.group} /var/srv/git | |
| for fn in ${repositories}; do | |
| mkdir -m 750 -p "/var/srv/git/$fn" | |
| chown ${mainCfg.user}:${mainCfg.group} "/var/srv/git/$fn" | |
| done | |
| ''; | |
| }; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment