summary refs log tree commit diff
path: root/fleet/pkgs/declarative-git-repository
diff options
context:
space:
mode:
authorV <v@unfathomable.blue>2021-06-09 15:43:16 +0200
committerV <v@unfathomable.blue>2021-08-17 03:09:34 +0200
commitec0965e2672899d25a5a3a8c072de3ea734076a2 (patch)
treeddf53e6cc5ae47fa1a925f7a7d6414ba03718a84 /fleet/pkgs/declarative-git-repository
parentdb7c54f92f386a94db8af7a12626d2657b4dd640 (diff)
downloadunf-legacy-ec0965e2672899d25a5a3a8c072de3ea734076a2.tar.zst
fleet: init
Co-authored-by: edef <edef@unfathomable.blue>
Change-Id: I36d2c4cca542ed91630b1b832f3c7a7b97b33c65
Diffstat (limited to 'fleet/pkgs/declarative-git-repository')
-rw-r--r--fleet/pkgs/declarative-git-repository/default.nix53
1 files changed, 53 insertions, 0 deletions
diff --git a/fleet/pkgs/declarative-git-repository/default.nix b/fleet/pkgs/declarative-git-repository/default.nix
new file mode 100644
index 0000000..f3bb014
--- /dev/null
+++ b/fleet/pkgs/declarative-git-repository/default.nix
@@ -0,0 +1,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}
+''