summaryrefslogtreecommitdiff
path: root/machines/xnet/gitserver
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2024-12-17 23:03:27 -0500
committerKleidi Bujari <mail@4kb.net>2024-12-17 23:03:27 -0500
commiteb13a9a552f9e50a66faba985521ba8e3483c447 (patch)
tree209193a91b0db20fb1bb30007e72e321f0293696 /machines/xnet/gitserver
parentf5ed731abbc38d765333b005b9815a5f6d3e59c2 (diff)
downloaddepot-eb13a9a552f9e50a66faba985521ba8e3483c447.tar.gz
depot-eb13a9a552f9e50a66faba985521ba8e3483c447.tar.bz2
depot-eb13a9a552f9e50a66faba985521ba8e3483c447.zip
Push configuration out of flake
Projects are not necessarily all exported by the system flake, and should freely support other derivations. The new "mod" directory will be used for most projects, and it can be imported by machine configurations. That said, the tooling around flakes is pretty good and will still be used until the dependency is lessened.
Diffstat (limited to 'machines/xnet/gitserver')
-rw-r--r--machines/xnet/gitserver/default.nix54
-rw-r--r--machines/xnet/gitserver/gitweb.nix75
2 files changed, 129 insertions, 0 deletions
diff --git a/machines/xnet/gitserver/default.nix b/machines/xnet/gitserver/default.nix
new file mode 100644
index 0000000..da83f73
--- /dev/null
+++ b/machines/xnet/gitserver/default.nix
@@ -0,0 +1,54 @@
+{ config, lib, pkgs, ... }:
+let
+ cfg = config.xnet.gitServer;
+ inherit (lib) mkOption mkIf types;
+in
+{
+ imports = [ ./gitweb.nix ];
+
+ options.xnet.gitServer = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Serve git repos over SSH.";
+ };
+
+ path = mkOption {
+ type = types.path;
+ default = "/persist/repo/git";
+ description = "Directory where repos will be stored.";
+ };
+
+ keys = mkOption {
+ type = types.listOf types.str;
+ description = "SSH public keys used for git operations.";
+ };
+ };
+
+ config = mkIf cfg.enable {
+ users.users.git = {
+ group = "git";
+ initialPassword = "";
+ isSystemUser = true;
+ home = cfg.path;
+ homeMode = "755";
+ createHome = true;
+ shell = "${pkgs.git}/bin/git-shell";
+ openssh.authorizedKeys.keys = cfg.keys;
+ };
+
+ users.groups.git = { };
+
+ programs.git = {
+ enable = true;
+ config = {
+ init = {
+ defaultBranch = "master";
+ };
+ safe = {
+ directory = "*";
+ };
+ };
+ };
+ };
+}
diff --git a/machines/xnet/gitserver/gitweb.nix b/machines/xnet/gitserver/gitweb.nix
new file mode 100644
index 0000000..bfd593d
--- /dev/null
+++ b/machines/xnet/gitserver/gitweb.nix
@@ -0,0 +1,75 @@
+{ config, lib, pkgs, ... }:
+let
+ cfg = config.xnet.gitServer.gitweb;
+ inherit (lib) mkOption mkIf types;
+in
+{
+ options.xnet.gitServer.gitweb = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Enable web interface to git repos.";
+ };
+
+ hostName = mkOption {
+ type = types.str;
+ default = "src.web.4kb.net";
+ description = "Hostname the webUI is served from.";
+ };
+ };
+
+ config = mkIf cfg.enable {
+ xnet.nginx.enable = true;
+
+ users.users.nginx.extraGroups = [ "git" ];
+ services.cgit.main = {
+ enable = true;
+ scanPath = config.xnet.gitServer.path;
+ package = pkgs.cgit-pink;
+ nginx = {
+ virtualHost = cfg.hostName;
+ location = "/";
+ };
+ extraConfig = ''
+ mimetype.gif=image/gif
+ mimetype.html=text/html
+ mimetype.jpeg=image/jpeg
+ mimetype.jpg=image/jpeg
+ mimetype.pdf=application/pdf
+ mimetype.png=image/png
+ mimetype.svg=image/svg+xml
+ readme=:readme
+ readme=:readme.md
+ readme=:readme.txt
+ readme=:README
+ readme=:README.md
+ readme=:README.txt
+ '';
+ settings = {
+ about-filter = "${pkgs.cgit-pink}/lib/cgit/filters/about-formatting.sh";
+ clone-url = "https://${cfg.hostName}/$CGIT_REPO_URL git@${cfg.hostName}:$CGIT_REPO_URL";
+ enable-commit-graph = true;
+ enable-http-clone = false;
+ enable-index-links = true;
+ enable-remote-branches = true;
+ remove-suffix = true;
+ robots = "noindex, nofollow";
+ root-desc = "What I cannot create, I do not understand";
+ root-title = cfg.hostName;
+ section-from-path = true;
+ snapshots = "tar.gz tar.bz2 zip";
+ };
+ };
+
+ # required for rendering markdown readme
+ environment.systemPackages = with pkgs; [
+ python312
+ python312Packages.markdown
+ ];
+
+ # services.nginx.virtualHosts."${cfg.gitweb.hostName}" = {
+ # useACMEHost = "4kb.net";
+ # addSSL = true;
+ # };
+ };
+}