blob: f3bb01421acec2aae5b0c148765c8c3b293364c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# SPDX-FileCopyrightText: V <v@unfathomable.blue>
# SPDX-License-Identifier: OSL-3.0
{ lib, writeTextDir, writeText, buildEnv, writeTextFile, bash, writeScript }:
{ path
, branch ? "trunk"
, description ? "Unnamed repository; edit this file 'description' to name the repository."
, config ? {}
, hooks ? {}
, user ? "-", group ? "-"
}:
with lib;
let
# As generated by an initial `git init --bare`
defaultConfig = {
core = {
repositoryFormatVersion = 0;
fileMode = true;
bare = true;
};
};
hooksDir = buildEnv {
name = "git-repository-hooks";
paths = mapAttrsToList (hook: scripts: writeTextFile {
name = hook;
text = ''
#! ${bash}/bin/bash -e
'' + concatMapStrings (script: ''
${script} "$@"
'') scripts;
destination = "/${hook}";
executable = true;
}) hooks;
};
in writeTextDir "lib/tmpfiles.d/git-repository${replaceStrings [ "/" ] [ "-" ] path}.conf" ''
# Root directory needs the correct permissions
d ${path} - ${user} ${group}
# This is the smallest set of paths that Git will still recognise as a valid repository.
# Everything else will be automatically filled out after a push or pull.
f+ ${path}/HEAD - ${user} ${group} - ref: refs/heads/${branch}
d ${path}/objects - ${user} ${group}
d ${path}/refs - ${user} ${group}
# Extra stuff we want to use
L+ ${path}/config - - - - ${writeText "git-repository-config" (generators.toGitINI (recursiveUpdate defaultConfig config))}
L+ ${path}/description - - - - ${builtins.toFile "git-repository-description" description}
L+ ${path}/hooks - - - - ${hooksDir}
''
|