about summary refs log tree commit diff
path: root/nix/hosts/corrino/www/git/cgit.nix
blob: 68304dbbb58f3591bbbc1a6b3f425aac070c4159 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
{
  config,
  lib,
  pkgs,
  ...
}:

let
  repodirs = builtins.concatStringsSep "\n" (
    map (x: "directory = ${x}") (
      lib.lists.flatten (
        map (x: lib.attrValues (lib.getAttrs [ "path" ] x)) (
          lib.mapAttrsToList (name: value: value) config.services.cgit.main.repos
        )
      )
    )
  );
in
{
  environment.systemPackages = with pkgs; [
    md4c # used to get md2html for rendering the READMEs within cgit-pink
  ];

  # set all the repos as safe
  environment.etc = {
    gitconfig = {
      text = ''
        [http]
        	sslCAinfo = /etc/ssl/certs/ca-certificates.crt
        [safe]
        	${repodirs}
      '';
    };
  };

  # add the cgit user to the git group allowing them to read the git repos
  users.groups."git".members = [ "cgit" ];

  services = {
    nginx.virtualHosts."git.emile.space" = {
      forceSSL = true;
      enableACME = true;
    };

    cgit.main = {
      enable = true;
      package = pkgs.cgit-pink;

      user = "cgit";
      group = "cgit";

      nginx.virtualHost = "git.emile.space";
      nginx.location = "/";

      repos = {

        # ops
        hefe = {
          desc = "Yet another monorepo (the big nix config)";
          path = "/var/lib/git/repositories/hefe.git";
          section = "Infra";
          owner = "emile";
        };
        vokobe = {
          desc = "A custom static site generator written in rust";
          path = "/var/lib/git/repositories/vokobe.git";
          section = "Infra";
          owner = "emile";
        };
        massscan-docker = {
          desc = "A Dockerfile for massscan";
          path = "/var/lib/git/repositories/massscan-docker.git";
          section = "Infra";
          owner = "emile";
        };
        metrics-bundler = {
          desc = "A super basic metrics bundler";
          path = "/var/lib/git/repositories/metrics-bundler.git";
          section = "Infra";
          owner = "emile";
        };

        # matrix
        matrix-sdk = {
          desc = "A simpler matrix sdk";
          path = "/var/lib/git/repositories/matrix-sdk.git";
          section = "Matrix";
          owner = "emile";
        };
        matrix-weather-bot = {
          desc = "A basic weather bot using matrix-sdk";
          path = "/var/lib/git/repositories/matrix-weather-bot.git";
          section = "Matrix";
          owner = "emile";
        };

        # radare2
        radare2-GoReSym = {
          desc = "A script to load goresym symbols into radare2";
          path = "/var/lib/git/repositories/radare2-GoReSym.git";
          section = "Radare2";
          owner = "emile";
        };
        r2wars = {
          desc = "A golang implementation of radare2";
          path = "/var/lib/git/repositories/r2wars.git";
          section = "Radare2";
          owner = "emile";
        };
        r2wars-web = {
          desc = "The software behind https://r2wa.rs";
          path = "/var/lib/git/repositories/r2wars-web.git";
          section = "Radare2";
          owner = "emile";
        };
        r2wars-rs = {
          desc = "A rust implementation of radare2";
          path = "/var/lib/git/repositories/r2wars-rs.git";
          section = "Radare2";
          owner = "emile";
        };

        # ctf
        ctf_clusters = {
          desc = "visualizing CTF clusters at DEFCON CTF Finals 2022";
          path = "/var/lib/git/repositories/ctf_clusters.git";
          section = "CTF";
          owner = "emile";
        };
        lambda = {
          desc = "hacktm ctf 2023 / misc / know your lambda calculus";
          path = "/var/lib/git/repositories/lambda.git";
          section = "CTF";
          owner = "emile";
        };
        ctfdget = {
          desc = "Simply fetch all challenges from a CTF from CTFd.";
          path = "/var/lib/git/repositories/ctfdget.git";
          section = "CTF";
          owner = "emile";
        };

        # keyboard
        zmk-config = {
          desc = "ferris sweep zmk config";
          path = "/var/lib/git/repositories/zmk-config.git";
          section = "Keyboard";
          owner = "emile";
        };

        # chaosdorf
        map = {
          desc = "A map of the chaosdorf hackspace";
          path = "/var/lib/git/repositories/map.git";
          section = "Chaosdorf";
          owner = "emile";
        };
        freitagsfoo = {
          desc = "A service to submit talks for freitagsfoo";
          path = "/var/lib/git/repositories/freitagsfoo.git";
          section = "Chaosdorf";
          owner = "emile";
        };
        inventory = {
          desc = "A common-lisp mapping and inventory system";
          path = "/var/lib/git/repositories/inventory.git";
          section = "Chaosdorf";
          owner = "emile";
        };

        # jugend forscht
        SatelliteComputation = {
          desc = "Estimating possible Satellite collisions";
          path = "/var/lib/git/repositories/SatelliteComputation.git";
          section = "Jugend Forscht 2017";
          owner = "emile";
        };
        GalaxyGeneration = {
          desc = "Generating Galaxies";
          path = "/var/lib/git/repositories/GalaxyGeneration.git";
          section = "Jugend Forscht 2018";
          owner = "emile";
        };

        brute-force = {
          desc = "A simple benchmark showing how slow this can be";
          path = "/var/lib/git/repositories/galaxy-sim-brute-force.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        generatePointcloud = {
          desc = "Generate pointclouds using the NFW profile";
          path = "/var/lib/git/repositories/generatePointcloud.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        quadtree = {
          desc = "Simple quadtree implementation";
          path = "/var/lib/git/repositories/quadtree.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        viewer = {
          desc = "A viewer for galaxies stored in trees";
          path = "/var/lib/git/repositories/viewer.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        structs = {
          desc = "All of the structures used in the GalaxySimulator";
          path = "/var/lib/git/repositories/structs.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        simulator-container-rewrite = {
          desc = "Clean rewrite of the simulator-container";
          path = "/var/lib/git/repositories/simulator-container-rewrite.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        simulator-container = {
          desc = "Simulating the new position of a galaxye";
          path = "/var/lib/git/repositories/simulator-container.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        pres = {
          desc = "Presentation material";
          path = "/var/lib/git/repositories/pres.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        manager-container = {
          desc = "The overall manager";
          path = "/var/lib/git/repositories/manager-container.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        generator-container = {
          desc = "Generates point clouds using the NFW profile";
          path = "/var/lib/git/repositories/generator-container.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        frontpage = {
          desc = "Web page showing people what the project is about";
          path = "/var/lib/git/repositories/frontpage.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        distributor = {
          desc = "Distributing tasks";
          path = "/var/lib/git/repositories/distributor-container.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        db-controller = {
          desc = "Interaction with the Database";
          path = "/var/lib/git/repositories/db-controller.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        db-container = {
          desc = "The main database";
          path = "/var/lib/git/repositories/db-container.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        db-actions = {
          desc = "Actions to be performed on the batabase";
          path = "/var/lib/git/repositories/db-actions.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        Writeup = {
          desc = "Writeups using LaTeX";
          path = "/var/lib/git/repositories/Writeup.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        Source = {
          desc = "Code from the beginning";
          path = "/var/lib/git/repositories/Source.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };
        NFW-container = {
          desc = "A container purely for generating galaxies";
          path = "/var/lib/git/repositories/NFW-container.git";
          section = "Jugend Forscht 2019";
          owner = "emile";
        };

        # games
        "0h-gamejam-game" = {
          desc = "Created a game in 0 hours";
          path = "/var/lib/git/repositories/0hour-gamejam-game.git";
          section = "Games";
          owner = "emile";
        };

        # 3D
        "3D" = {
          desc = "3D models";
          path = "/var/lib/git/repositories/3D.git";
          section = "3D";
          owner = "emile";
        };

        # http
        faila = {
          desc = "The caddy fileserver look, but int pure golang";
          path = "/var/lib/git/repositories/faila.git";
          section = "HTTP";
          owner = "emile";
        };
        faila2 = {
          desc = "faila, but simpler";
          path = "/var/lib/git/repositories/faila2.git";
          section = "HTTP";
          owner = "emile";
        };
        gofuzz = {
          desc = "wfuzz, but in go. Didn't know ffuf at the time";
          path = "/var/lib/git/repositories/gofuzz.git";
          section = "HTTP";
          owner = "emile";
        };
        graphClicker = {
          desc = "A metrics bundler, but with a simple web interface";
          path = "/var/lib/git/repositories/graphClicker.git";
          section = "HTTP";
          owner = "emile";
        };
        randomHttp = {
          desc = "A simple HTTP server returning random HTTP codes";
          path = "/var/lib/git/repositories/randomHTTP.git";
          section = "HTTP";
          owner = "emile";
        };
        redir = {
          desc = "A webserver with the soul purpose of redirecting.";
          path = "/var/lib/git/repositories/redir.git";
          section = "HTTP";
          owner = "emile";
        };
        reqlog = {
          desc = "A simple request logger";
          path = "/var/lib/git/repositories/reqlog.git";
          section = "HTTP";
          owner = "emile";
        };

        # honeypot
        ssh-catch-test = {
          desc = "A simple honeypot emulating an ssh server.";
          path = "/var/lib/git/repositories/ssh-catch-test.git";
          section = "Honeypot";
          owner = "emile";
        };
        honeypot-monitoring = {
          desc = "Grafana + Prometheus monitoring";
          path = "/var/lib/git/repositories/honeypot-monitoring.git";
          section = "Honeypot";
          owner = "emile";
        };
        ftp-grab-password = {
          desc = "Grab ftp creds (made by twink0r)";
          path = "/var/lib/git/repositories/ftp-grab-password.git";
          section = "Honeypot";
          owner = "emile";
        };
        log-analyzer = {
          desc = "Analyse the logs";
          path = "/var/lib/git/repositories/honeypot-log-analyzer.git";
          section = "Honeypot";
          owner = "emile";
        };
        http-grab-basicauth = {
          desc = "Grab basicauth creds (made by maride)";
          path = "/var/lib/git/repositories/http-grab-basicauth.git";
          section = "Honeypot";
          owner = "emile";
        };
        http-grab-url = {
          desc = "Grab urls (made by twink0r)";
          path = "/var/lib/git/repositories/http-grab-url.git";
          section = "Honeypot";
          owner = "emile";
        };
        ssh-grab-keypass = {
          desc = "Grab keys from ssh logins (made by maride)";
          path = "/var/lib/git/repositories/ssh-grab-keypass.git";
          section = "Honeypot";
          owner = "emile";
        };
        ssh-grab-passwords = {
          desc = "Grab passwords from ssh logins (made by maride)";
          path = "/var/lib/git/repositories/ssh-grab-passwords.git";
          section = "Honeypot";
          owner = "emile";
        };
        ssh-grab-passwords-map = {
          desc = "A nice visual map of the login attempts";
          path = "/var/lib/git/repositories/ssh-grab-passwords-map.git";
          section = "Honeypot";
          owner = "emile";
        };

        # fuzzing
        stdin-to-tcp = {
          desc = "Bending stdin to tcp";
          path = "/var/lib/git/repositories/stdin-to-tcp.git";
          section = "Fuzzing";
          owner = "emile";
        };

        # firmware
        firmware = {
          desc = "Gathering firmware via nix";
          path = "/var/lib/git/repositories/firmware.git";
          section = "Firmware";
          owner = "emile";
        };

        # crypto
        Substitution-Cracker = {
          desc = "Some code for cracking substitution ciphers";
          path = "/var/lib/git/repositories/Substitution-Cracker.git";
          section = "Crypto";
          owner = "emile";
        };

        # fun
        giff = {
          desc = "A party service: give it gifs and it'll play them";
          path = "/var/lib/git/repositories/giff.git";
          section = "Fun";
          owner = "emile";
        };
        pixeltsunami = {
          desc = "The obligatory pixelflut client";
          path = "/var/lib/git/repositories/pixeltsunami.git";
          section = "Fun";
          owner = "emile";
        };
        aoc = {
          desc = "Advent of code";
          path = "/var/lib/git/repositories/aoc.git";
          section = "Fun";
          owner = "emile";
        };

        # circus
        companion = {
          desc = "The companion spawned for one user.";
          path = "/var/lib/git/repositories/companion.git";
          section = "Circus";
          owner = "emile";
        };
        compose = {
          desc = "The docker-compose foo";
          path = "/var/lib/git/repositories/compose.git";
          section = "Circus";
          owner = "emile";
        };
        container-manager = {
          desc = "The meta container managemer";
          path = "/var/lib/git/repositories/container-manager.git";
          section = "Circus";
          owner = "emile";
        };
        landingpage = {
          desc = "The landing page";
          path = "/var/lib/git/repositories/landingpage.git";
          section = "Circus";
          owner = "emile";
        };
        manager = {
          desc = "The manager";
          path = "/var/lib/git/repositories/manager.git";
          section = "Circus";
          owner = "emile";
        };
        register = {
          desc = "The registration";
          path = "/var/lib/git/repositories/register.git";
          section = "Circus";
          owner = "emile";
        };
        scoreboard = {
          desc = "The scoreboard";
          path = "/var/lib/git/repositories/scoreboard.git";
          section = "Circus";
          owner = "emile";
        };
        static = {
          desc = "Some static files";
          path = "/var/lib/git/repositories/static.git";
          section = "Circus";
          owner = "emile";
        };
        vpn = {
          desc = "The VPN stuff";
          path = "/var/lib/git/repositories/vpn.git";
          section = "Circus";
          owner = "emile";
        };

        # articles
        barnes-hut = {
          desc = "A one pager compressing the JuFo19 project";
          path = "/var/lib/git/repositories/barnes-hut.git";
          section = "Articles";
          owner = "emile";
        };

        # satellite
        tle = {
          desc = "golang tle lib";
          path = "/var/lib/git/repositories/tle.git";
          section = "Satellite";
          owner = "emile";
        };
        tle2json = {
          desc = "golang tle to json";
          path = "/var/lib/git/repositories/tle2json.git";
          section = "Satellite";
          owner = "emile";
        };

        # milliways
        remarvin = {
          desc = "A small marvin bot";
          path = "/var/lib/git/repositories/remarvin.git";
          section = "milliways";
          owner = "emile";
        };
      };
      settings = {
        css = "https://emile.space/cgit.css";
        root-title = "git.emile.space";
        root-desc = "";

        enable-index-owner = 0; # why show this? I own 'em all!
        enable-commit-graph = 1;
        max-repo-count = 5000; # like: why not?

        readme = ":README.md";
        about-filter = "${pkgs.cgit-pink}/lib/cgit/filters/about-formatting.sh";
        source-filter = "${pkgs.cgit-pink}/lib/cgit/filters/syntax-highlighting.py";

        summary-log = 50;

        # mobile friendly
        head-include = builtins.toFile "cgit_head.html" ''
          <meta name="viewport" content="width=device-width initial-scale=1.0"/>
        '';

        footer = builtins.toFile "cgit_footer.html" ''
            <div class="footer">
          		<div class="float-left">
          			generated by <a href='https://git.causal.agency/cgit-pink/'>cgit-pink ${pkgs.cgit-pink.version}</a>
          		</div>
          		<div class="float-right">
          			<a href="https://social.emile.space/@hanemile/feed.rss" target="_blank" rel="noopener" class="icon"><img class="webring" src="https://emile.space/rss.svg" alt="rss feed of @hanemile@chaos.social mastodon" height="32px"></a>
          			<a href="https://lieu.cblgh.org/" target="_blank" rel="noopener" class="icon"><img class="webring" src="https://emile.space/lieu.svg" alt="lieu webring search engine" height="32px"></a>
          			<a href="https://webring.xxiivv.com/#emile" target="_blank" rel="noopener" class="icon"><img class="webring" src="https://emile.space/webring.svg" alt="XXIIVV webring" height="32px"></a>
          			<a rel="me" href="https://social.emile.space/@hanemile" target="_blank" class="icon"><img class="webring" src="https://emile.space/activitypub.svg" alt="activitypub" height="32px"/></a>
          	</div>
        '';

      };
    };

    # access control
    gitolite = {
      enable = true;

      dataDir = "/var/lib/git";

      user = "git";
      group = "git";

      description = "emile";

      adminPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPZi43zHEsoWaQomLGaftPE5k0RqVrZyiTtGqZlpWsew emile@caladan";
      extraGitoliteRc = ''
        $RC{UMASK} = 0027;
        $RC{GIT_CONFIG_KEYS} = '.*';
      '';
    };

    # ssh:// - default port 22
    # git:// - default port 9418
    # http:// - default port 80
    # https:// - default port 443

    # exposing stuff
    gitDaemon = {
      enable = true;

      user = "git";
      group = "git";

      repositories = [ ]; # use all repos under basePath
      exportAll = true;
      basePath = "/var/lib/git/repositories";

      listenAddress = "git.emile.space";
      port = config.emile.ports.gitDaemon; # 9418

      options = "--timeout=30"; # extra Config
    };
  };

  # allow access to the port the gitDaemon is listening on
  networking.firewall.allowedTCPPorts = [ config.emile.ports.gitDaemon ];

  users.extraUsers.nginx.extraGroups = [ "git" ];

  # Have to use lib.mkForce below, as the gitolite and gitDaemon user both
  # configure the git user and group (differently)

  users.users.git = {
    isSystemUser = true;
    useDefaultShell = true;
    description = lib.mkForce "cgit-pink, gitolite and gitDaemon";
    group = "git";
    extraGroups = [ "gitea" ];
    home = "/var/lib/git";
    uid = lib.mkForce 127;
  };
  users.groups.git = {
    gid = lib.mkForce 127;
  };
}