abouttreesummaryrefslogcommitdiff
path: root/flake.nix
blob: 2c90ae22480741ad40de3db4496ab4bb08fb10c6 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
  description = "A Nix Flake for a fork of cgit";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    extra-container.url = "github:erikarvstedt/extra-container";
  };

  outputs = { self, nixpkgs, extra-container }:
    extra-container.lib.eachSupportedSystem (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
        in
        {
          packages.default = pkgs.callPackage ({ lib, fetchurl, callPackage, luajit, nixosTests }:
            # This logic was previously in package.nix
            callPackage (import ./common.nix rec {
              pname = "ps-cgit";
              version = "1.2.3";

              src = ./.;

              # cgit needs the git source code to compile.
              # Ensure this matches the version found in the Makefile of your fork.
              gitSrc = fetchurl {
                url = "mirror://kernel/software/scm/git/git-2.25.1.tar.xz";
                sha256 = "09lzwa183nblr6l8ib35g2xrjf9wm9yhk3szfvyzkwivdv69c9r2";
              };

              buildInputs = [ luajit ];

              passthru.tests = { inherit (nixosTests) cgit; };

              homepage = "https://git.zx2c4.com/cgit/about/";
              description = "Web frontend for git repositories (Custom Fork)";
              maintainers = with lib.maintainers; [  ];
            }) { }
          ) { };

          packages.container =
            let
              ps-cgit = self.packages.${system}.default;
            in
              extra-container.lib.buildContainers {
            inherit system;
            inherit nixpkgs;

            config = {
              containers.ps-cgit-rr = {

                extra = {
                  addressPrefix = "10.250.0";
                  enableWAN = true;
                  firewallAllowHost = true;
                  exposeLocalhost = true;
                };
                config = { pkgs, ... }: {
                  boot.isContainer = true;
                  nix.settings.experimental-features = [ "nix-command" "flakes" ];
                  system.stateVersion = "26.05";
                  environment.systemPackages = with pkgs; [ gdb rr file ];

                  networking.useDHCP = false;
                  networking.firewall.allowedTCPPorts = [ 22 80 1234 ];

                  services.openssh.enable = true;
                  users.users.root.openssh.authorizedKeys.keys = [ "${builtins.readFile "/home/ps/.ssh/id_ed25519.pub"}" ];

                  users.users.git = {
                    isSystemUser = true;
                    group = "git";
                    home = "/srv/git";
                    createHome = true;
                    # homeMode = "750";
                    shell = "${pkgs.git}/bin/git-shell";
                    openssh.authorizedKeys.keys = [ "${builtins.readFile "/home/ps/.ssh/id_ed25519.pub"}" ];
                    packages = [ pkgs.git ];
                  };
                  users.groups.git = {};

                  services.fcgiwrap.instances.cgit = {
                    process.user = "git";
                    process.group = "root";
                    socket.user = "caddy";
                    socket.group = "caddy";
                  };

                  services.caddy.enable = true;
                  services.caddy.extraConfig = ''
                  http://ps-cgit-rr {
                    rewrite /git /git/
                    handle_path /git/* {
                      handle_path /static/* {
                        file_server {
                          root ${ps-cgit}/cgit
                        }
                      }
                      handle {
                        reverse_proxy unix//run/fcgiwrap-cgit.sock {
                          transport fastcgi {
                            read_timeout 1h
                            env CGIT_CONFIG ${pkgs.writeText "cgitrc" ''
                              snapshots=tar tar.gz zip
                              enable-git-config=1
                              enable-index-owner=0
                              enable-log-filecount=1
                              enable-log-linecount=1
                              section-from-path=1
                              virtual-root=/git
                              css=/git/static/cgit.css
                              logo=/git/static/cgit.png
                              favicon=/git/static/favicon.ico
                              module-link=/git/%s/commit/?id=%s
                              clone-url=https://$HTTP_HOST/git/$CGIT_REPO_URL git://$HTTP_HOST/$CGIT_REPO_URL git@$HTTP_HOST:$CGIT_REPO_URL
                              noplainemail=1
                              repository-sort=age
                              about-filter=${pkgs.writeShellScript "markdown-filter" ''
                                echo '<div class="markdown-body">'
                                ${pkgs.md4c}/bin/md2html --github --ftables
                                echo '</div>'
                              ''}
                              # source-filter=${ps-cgit}/lib/cgit/filters/syntax-highlighting.py
                              head-include=${ps-cgit}/cgit/cgithub/head-include.html
                              footer=${ps-cgit}/cgit/cgithub/footer.html
                              readme=:readme.md
                              readme=:readme
                              root-readme=${pkgs.writeText "readme.md" ''
                                # my git repos
                              ''}
                              scan-path=/srv/git
                            ''}
                            env SCRIPT_FILENAME ${ps-cgit}/cgit/cgit.cgi
                          }
                        }
                      }
                    }
                  }
                  '';
                };
              };
          };

    };
        });
}