# SPDX-FileCopyrightText: V # SPDX-FileCopyrightText: 2022 Alyssa Ross # SPDX-License-Identifier: OSL-3.0 # Adapted from https://src.unfathomable.blue/nixos-config/tree/modules/declarative-git.nix { config, lib, pkgs, ... }: with lib; let cfg = config.declarative-git; repoOpts = { config, ... }: { options = { branch = mkOption { default = "main"; description = mdDoc "Branch to be the repository's HEAD"; type = types.str; }; description = mkOption { description = mdDoc "Description of the repository."; type = types.str; }; config = mkOption { description = mdDoc "Git configuration for the repository."; type = types.attrs; default = {}; }; hooks = mkOption { description = mdDoc "Git hooks for the repository."; type = with types; attrsOf (listOf path); default = {}; }; owner = mkOption { description = mdDoc "Name of the user to own the git repository."; type = types.str; default = "-"; }; group = mkOption { description = mdDoc "Name of the group for the git repository."; type = types.str; default = "-"; }; }; }; in { options.declarative-git = { repositories = mkOption { description = mdDoc "Repositories to manage declaratively."; type = types.attrsOf (types.submodule repoOpts); default = {}; }; hooks = mkOption { description = mdDoc "Git hooks to apply to all declarative repositories."; type = with types; attrsOf (listOf path); default = {}; }; }; config.systemd.tmpfiles.packages = mapAttrsToList (path: config: pkgs.declarative-git-repository { inherit path; inherit (config) branch config description owner group; hooks = zipAttrsWith (_: concatLists) [ cfg.hooks config.hooks ]; }) cfg.repositories; }