From ec0965e2672899d25a5a3a8c072de3ea734076a2 Mon Sep 17 00:00:00 2001 From: V Date: Wed, 9 Jun 2021 15:43:16 +0200 Subject: fleet: init Co-authored-by: edef Change-Id: I36d2c4cca542ed91630b1b832f3c7a7b97b33c65 --- fleet/pkgs/declarative-git-repository/default.nix | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 fleet/pkgs/declarative-git-repository/default.nix (limited to 'fleet/pkgs/declarative-git-repository') 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 +# 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} +'' -- cgit 1.4.1