summaryrefslogtreecommitdiff
path: root/configuration/snorlax/git.nix
blob: a24c26a652d25ea81d3d9b267c9c58f69edbcbdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ lib, pkgs, ... }:
let
  home = "/var/lib/git";
  repos = {
    nixos = {
      path = "${home}/nixos.git";
      desc = "My NixOS Configurations";
      owner = "jras";
    };

    notes = {
      path = "${home}/notes.git";
      desc = "My notes";
      owner = "jras";
    };

    obsidian-wavez-theme = {
      path = "${home}/obsidian-wavez-theme.git";
      desc = "The bordeaux theme for Obsidian";
      owner = "jras";
    };

    astal-bar = {
      path = "${home}/astal-bar.git";
      desc = "A wayland bar in jsx";
      owner = "jras";
    };
  };

  startScript = pkgs.writeShellScript "init-git-repos" ''
  ${lib.concatMapStrings ({ path, ... }: "${pkgs.git}/bin/git init --bare --shared ${path} && cd ${path} && ${pkgs.git}/bin/git branch -m main \n") (builtins.attrValues repos)} 
  '';
in
{
  networking.firewall.allowedTCPPorts = [ 80 ];

  services.cgit.snorlax = {
    enable = true;
    group = "git";
    repos = repos;
  };

  systemd.services.init-repos = {
    description = "Initialize git repositories";
    wantedBy = [ "multi-user.target" ];
    restartTriggers = [ startScript ];

    serviceConfig = {
      Type = "oneshot";
      User = "git";
      Group = "git";
      ExecStart = startScript;
    };
  };

  users.groups.git = {};
  users.users.git = {
    isNormalUser = true;
    home = "${home}";
    homeMode = "0750";
    createHome = true;
    shell = pkgs.zsh;
    group = "git";
    openssh.authorizedKeys.keyFiles = [
      ../../keys/id_tarrel.pub
      ../../keys/id_work.pub
    ];
    packages = with pkgs; [ git ];
  };
  services.openssh.settings.AllowUsers = [ "git" ];
}