summary refs log tree commit diff
path: root/fleet/modules/declarative-git.nix
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/modules/declarative-git.nix
parentdb7c54f92f386a94db8af7a12626d2657b4dd640 (diff)
fleet: init
Co-authored-by: edef <edef@unfathomable.blue>
Change-Id: I36d2c4cca542ed91630b1b832f3c7a7b97b33c65
Diffstat (limited to 'fleet/modules/declarative-git.nix')
-rw-r--r--fleet/modules/declarative-git.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/fleet/modules/declarative-git.nix b/fleet/modules/declarative-git.nix
new file mode 100644
index 0000000..ac4bd15
--- /dev/null
+++ b/fleet/modules/declarative-git.nix
@@ -0,0 +1,59 @@
+# SPDX-FileCopyrightText: V <v@unfathomable.blue>
+# SPDX-License-Identifier: OSL-3.0
+
+# TODO(V): Make the option descriptions not be terrible.
+
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.declarative.git;
+
+  repoOpts = { name, config, ... }: {
+    options = {
+      description = mkOption {
+        description = "Description of the repository.";
+        type = types.str;
+        # Git defaults to "Unnamed repository; edit this file 'description' to name the repository."
+        # CGit defaults to "[no description]"
+        default = "Unnamed repository; edit this file 'description' to name the repository.";
+      };
+
+      config = mkOption {
+        description = "Git configuration for the repository.";
+        type = types.attrs;  # TODO(V): be more precise
+        default = {};
+      };
+
+      hooks = mkOption {
+        description = "Git hooks for the repository.";
+        type = with types; attrsOf (listOf path);
+        default = {};
+      };
+    };
+  };
+in {
+  options.declarative.git = {
+    repositories = mkOption {
+      description = "Repositories to manage declaratively.";
+      type = types.attrsOf (types.submodule repoOpts);
+      default = {};
+    };
+
+    hooks = mkOption {
+      description = "Git hooks to apply to all declarative repositories.";
+      type = with types; attrsOf (listOf path);
+      default = {};
+    };
+  };
+
+  config.systemd.tmpfiles.packages = mapAttrsToList (name: config:
+    pkgs.declarative-git-repository {
+      path = "/var/lib/git/${name}";
+      inherit (config) description config;
+      hooks = zipAttrsWith (_: concatLists) [ cfg.hooks config.hooks ];
+      user = "git";
+      group = "git";
+    }) cfg.repositories;
+}