diff options
Diffstat (limited to 'overlays/personal/declarative-git-repository/default.nix')
-rw-r--r-- | overlays/personal/declarative-git-repository/default.nix | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/overlays/personal/declarative-git-repository/default.nix b/overlays/personal/declarative-git-repository/default.nix new file mode 100644 index 000000000000..e1b2693dff4f --- /dev/null +++ b/overlays/personal/declarative-git-repository/default.nix @@ -0,0 +1,55 @@ +# SPDX-FileCopyrightText: V <v@unfathomable.blue> +# SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is> +# SPDX-License-Identifier: OSL-3.0 + +# Adapted from https://src.unfathomable.blue/nixos-config/tree/pkgs/declarative-git-repository/default.nix + +{ lib, buildEnv, runtimeShell, writeTextDir, writeText, writeTextFile +, writeScript +}: + +{ path +, branch ? "main" +, description +, config ? {} +, hooks ? {} +, owner ? "-", 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 = '' + #!${runtimeShell} + '' + concatMapStrings (script: '' + ${script} "$@" + '') scripts; + destination = "/${hook}"; + executable = true; + }) hooks; + }; +in writeTextDir "lib/tmpfiles.d/git-repository${replaceStrings [ "/" ] [ "-" ] path}.conf" '' + d ${path} 2775 ${owner} ${group} + + f+ ${path}/HEAD - root root - ref: refs/heads/${branch} + d ${path}/refs 2775 ${owner} ${group} + d ${path}/objects 2775 ${owner} ${group} + d ${path}/objects/pack 2775 ${owner} ${group} + + 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} +'' |