# SPDX-FileCopyrightText: V # SPDX-FileCopyrightText: 2022 Alyssa Ross # 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} ''