2014-06-26 05:32:45 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gitolite;
|
2017-09-12 10:44:21 +02:00
|
|
|
# Use writeTextDir to not leak Nix store hash into file name
|
|
|
|
pubkeyFile = (pkgs.writeTextDir "gitolite-admin.pub" cfg.adminPubkey) + "/gitolite-admin.pub";
|
2014-09-16 08:33:29 +02:00
|
|
|
hooks = lib.concatMapStrings (hook: "${hook} ") cfg.commonHooks;
|
2014-06-26 05:32:45 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.gitolite = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable gitolite management under the
|
2014-11-02 00:24:41 +01:00
|
|
|
<literal>gitolite</literal> user. After
|
2014-06-26 05:32:45 +02:00
|
|
|
switching to a configuration with Gitolite enabled, you can
|
|
|
|
then run <literal>git clone
|
2014-06-26 05:55:43 +02:00
|
|
|
gitolite@host:gitolite-admin.git</literal> to manage it further.
|
2014-06-26 05:32:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-02 00:24:41 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/gitolite";
|
|
|
|
description = ''
|
2020-07-12 14:47:09 +02:00
|
|
|
The gitolite home directory used to store all repositories. If left as the default value
|
|
|
|
this directory will automatically be created before the gitolite server starts, otherwise
|
|
|
|
the sysadmin is responsible for ensuring the directory exists with appropriate ownership
|
|
|
|
and permissions.
|
2014-11-02 00:24:41 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-06-26 05:32:45 +02:00
|
|
|
adminPubkey = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Initial administrative public key for Gitolite. This should
|
|
|
|
be an SSH Public Key. Note that this key will only be used
|
|
|
|
once, upon the first initialization of the Gitolite user.
|
2015-01-13 06:49:33 +01:00
|
|
|
The key string cannot have any line breaks in it.
|
2014-06-26 05:32:45 +02:00
|
|
|
'';
|
|
|
|
};
|
2014-09-16 08:33:29 +02:00
|
|
|
|
2017-09-23 09:56:26 +02:00
|
|
|
enableGitAnnex = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable git-annex support. Uses the <literal>extraGitoliteRc</literal> option
|
|
|
|
to apply the necessary configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-09-16 08:33:29 +02:00
|
|
|
commonHooks = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
A list of custom git hooks that get copied to <literal>~/.gitolite/hooks/common</literal>.
|
|
|
|
'';
|
|
|
|
};
|
2014-11-14 16:07:17 +01:00
|
|
|
|
2017-09-22 04:16:36 +02:00
|
|
|
extraGitoliteRc = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = literalExample ''
|
|
|
|
$RC{UMASK} = 0027;
|
|
|
|
$RC{SITE_INFO} = 'This is our private repository host';
|
|
|
|
push( @{$RC{ENABLE}}, 'Kindergarten' ); # enable the command/feature
|
|
|
|
@{$RC{ENABLE}} = grep { $_ ne 'desc' } @{$RC{ENABLE}}; # disable the command/feature
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra configuration to append to the default <literal>~/.gitolite.rc</literal>.
|
|
|
|
|
|
|
|
This should be Perl code that modifies the <literal>%RC</literal>
|
|
|
|
configuration variable. The default <literal>~/.gitolite.rc</literal>
|
|
|
|
content is generated by invoking <literal>gitolite print-default-rc</literal>,
|
|
|
|
and extra configuration from this option is appended to it. The result
|
|
|
|
is placed to Nix store, and the <literal>~/.gitolite.rc</literal> file
|
|
|
|
becomes a symlink to it.
|
|
|
|
|
|
|
|
If you already have a customized (or otherwise changed)
|
|
|
|
<literal>~/.gitolite.rc</literal> file, NixOS will refuse to replace
|
|
|
|
it with a symlink, and the `gitolite-init` initialization service
|
|
|
|
will fail. In this situation, in order to use this option, you
|
|
|
|
will need to take any customizations you may have in
|
|
|
|
<literal>~/.gitolite.rc</literal>, convert them to appropriate Perl
|
|
|
|
statements, add them to this option, and remove the file.
|
2017-09-23 09:56:26 +02:00
|
|
|
|
|
|
|
See also the <literal>enableGitAnnex</literal> option.
|
2017-09-22 04:16:36 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-14 16:07:17 +01:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitolite";
|
|
|
|
description = ''
|
|
|
|
Gitolite user account. This is the username of the gitolite endpoint.
|
|
|
|
'';
|
|
|
|
};
|
2017-09-12 11:31:29 +02:00
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitolite";
|
|
|
|
description = ''
|
|
|
|
Primary group of the Gitolite user account.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-26 05:32:45 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-22 04:16:36 +02:00
|
|
|
config = mkIf cfg.enable (
|
|
|
|
let
|
|
|
|
manageGitoliteRc = cfg.extraGitoliteRc != "";
|
2018-11-08 11:59:03 +01:00
|
|
|
rcDir = pkgs.runCommand "gitolite-rc" { preferLocalBuild = true; } rcDirScript;
|
2017-09-22 04:16:36 +02:00
|
|
|
rcDirScript =
|
|
|
|
''
|
|
|
|
mkdir "$out"
|
|
|
|
export HOME=temp-home
|
|
|
|
mkdir -p "$HOME/.gitolite/logs" # gitolite can't run without it
|
|
|
|
'${pkgs.gitolite}'/bin/gitolite print-default-rc >>"$out/gitolite.rc.default"
|
|
|
|
cat <<END >>"$out/gitolite.rc"
|
|
|
|
# This file is managed by NixOS.
|
|
|
|
# Use services.gitolite options to control it.
|
|
|
|
|
|
|
|
END
|
|
|
|
cat "$out/gitolite.rc.default" >>"$out/gitolite.rc"
|
|
|
|
'' +
|
|
|
|
optionalString (cfg.extraGitoliteRc != "") ''
|
|
|
|
echo -n ${escapeShellArg ''
|
|
|
|
|
|
|
|
# Added by NixOS:
|
|
|
|
${removeSuffix "\n" cfg.extraGitoliteRc}
|
|
|
|
|
|
|
|
# per perl rules, this should be the last line in such a file:
|
|
|
|
1;
|
|
|
|
''} >>"$out/gitolite.rc"
|
|
|
|
'';
|
|
|
|
in {
|
2017-09-23 09:56:26 +02:00
|
|
|
services.gitolite.extraGitoliteRc = optionalString cfg.enableGitAnnex ''
|
|
|
|
# Enable git-annex support:
|
|
|
|
push( @{$RC{ENABLE}}, 'git-annex-shell ua');
|
|
|
|
'';
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.${cfg.user} = {
|
2014-06-26 05:32:45 +02:00
|
|
|
description = "Gitolite user";
|
2014-11-02 00:24:41 +01:00
|
|
|
home = cfg.dataDir;
|
2014-06-26 05:32:45 +02:00
|
|
|
uid = config.ids.uids.gitolite;
|
2017-09-12 11:31:29 +02:00
|
|
|
group = cfg.group;
|
2014-06-26 05:32:45 +02:00
|
|
|
useDefaultShell = true;
|
|
|
|
};
|
2019-08-13 23:52:01 +02:00
|
|
|
users.groups.${cfg.group}.gid = config.ids.gids.gitolite;
|
2014-06-26 05:32:45 +02:00
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
systemd.services.gitolite-init = {
|
2014-06-26 05:32:45 +02:00
|
|
|
description = "Gitolite initialization";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2017-09-11 21:03:51 +02:00
|
|
|
unitConfig.RequiresMountsFor = cfg.dataDir;
|
2014-06-26 05:32:45 +02:00
|
|
|
|
2019-06-22 19:18:51 +02:00
|
|
|
environment = {
|
|
|
|
GITOLITE_RC = ".gitolite.rc";
|
|
|
|
GITOLITE_RC_DEFAULT = "${rcDir}/gitolite.rc.default";
|
|
|
|
};
|
|
|
|
|
2020-07-12 14:47:09 +02:00
|
|
|
serviceConfig = mkMerge [
|
|
|
|
(mkIf (cfg.dataDir == "/var/lib/gitolite") {
|
|
|
|
StateDirectory = "gitolite gitolite/.gitolite gitolite/.gitolite/logs";
|
|
|
|
StateDirectoryMode = "0750";
|
|
|
|
})
|
|
|
|
{
|
|
|
|
Type = "oneshot";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
WorkingDirectory = "~";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
}
|
|
|
|
];
|
2014-06-26 05:32:45 +02:00
|
|
|
|
2017-09-22 04:16:36 +02:00
|
|
|
path = [ pkgs.gitolite pkgs.git pkgs.perl pkgs.bash pkgs.diffutils config.programs.ssh.package ];
|
|
|
|
script =
|
|
|
|
let
|
|
|
|
rcSetupScriptIfCustomFile =
|
|
|
|
if manageGitoliteRc then ''
|
|
|
|
cat <<END
|
|
|
|
<3>ERROR: NixOS can't apply declarative configuration
|
|
|
|
<3>to your .gitolite.rc file, because it seems to be
|
|
|
|
<3>already customized manually.
|
|
|
|
<3>See the services.gitolite.extraGitoliteRc option
|
|
|
|
<3>in "man configuration.nix" for more information.
|
|
|
|
END
|
|
|
|
# Not sure if the line below addresses the issue directly or just
|
|
|
|
# adds a delay, but without it our error message often doesn't
|
|
|
|
# show up in `systemctl status gitolite-init`.
|
|
|
|
journalctl --flush
|
|
|
|
exit 1
|
|
|
|
'' else ''
|
|
|
|
:
|
|
|
|
'';
|
|
|
|
rcSetupScriptIfDefaultFileOrStoreSymlink =
|
|
|
|
if manageGitoliteRc then ''
|
|
|
|
ln -sf "${rcDir}/gitolite.rc" "$GITOLITE_RC"
|
|
|
|
'' else ''
|
|
|
|
[[ -L "$GITOLITE_RC" ]] && rm -f "$GITOLITE_RC"
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
''
|
|
|
|
if ( [[ ! -e "$GITOLITE_RC" ]] && [[ ! -L "$GITOLITE_RC" ]] ) ||
|
|
|
|
( [[ -f "$GITOLITE_RC" ]] && diff -q "$GITOLITE_RC" "$GITOLITE_RC_DEFAULT" >/dev/null ) ||
|
|
|
|
( [[ -L "$GITOLITE_RC" ]] && [[ "$(readlink "$GITOLITE_RC")" =~ ^/nix/store/ ]] )
|
|
|
|
then
|
|
|
|
'' + rcSetupScriptIfDefaultFileOrStoreSymlink +
|
|
|
|
''
|
|
|
|
else
|
|
|
|
'' + rcSetupScriptIfCustomFile +
|
|
|
|
''
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d repositories ]; then
|
|
|
|
gitolite setup -pk ${pubkeyFile}
|
|
|
|
fi
|
|
|
|
if [ -n "${hooks}" ]; then
|
2017-12-19 17:06:26 +01:00
|
|
|
cp -f ${hooks} .gitolite/hooks/common/
|
2017-09-22 04:16:36 +02:00
|
|
|
chmod +x .gitolite/hooks/common/*
|
|
|
|
fi
|
|
|
|
gitolite setup # Upgrade if needed
|
|
|
|
'';
|
2014-06-26 05:32:45 +02:00
|
|
|
};
|
|
|
|
|
2017-09-23 09:56:26 +02:00
|
|
|
environment.systemPackages = [ pkgs.gitolite pkgs.git ]
|
gitAndTools: move everything to the top level
The comment at the top of git-and-tools/default.nix said:
/* All git-relates tools live here, in a separate attribute set so that users
* can get a fast overview over what's available.
but unfortunately that hasn't actually held up in practice.
Git-related packages have continued to be added to the top level, or
into gitAndTools, or sometimes both, basically at random, so having
gitAndTools is just confusing. In fact, until I looked as part of
working on getting rid of gitAndTools, one program (ydiff) was
packaged twice independently, once in gitAndTools and once at the top
level (I fixed this in 98c34901969).
So I think it's for the best if we move away from gitAndTools, and
just put all the packages it previously contained at the top level.
I've implemented this here by just making gitAndTools an alias for the
top level -- this saves having loads of lines in aliases.nix. This
means that people can keep referring to gitAndTools in their
configuration, but it won't be allowed to be used within Nixpkgs, and
it won't be presented to new users by e.g. nix search.
The only other change here that I'm aware of is that
appendToName "minimal" is not longer called on the default git
package, because doing that would have necessitated having a private
gitBase variable like before. I think it makes more sense not to do
that anyway, and reserve the "minimal" suffix only for gitMinimal.
2021-01-14 18:49:32 +01:00
|
|
|
++ optional cfg.enableGitAnnex pkgs.git-annex;
|
2017-09-22 04:16:36 +02:00
|
|
|
});
|
2014-06-26 05:32:45 +02:00
|
|
|
}
|