]> gitweb.ps.run Git - flake_server/blob - configuration.nix
update
[flake_server] / configuration.nix
1 # Edit this configuration file to define what should be installed on
2 # your system. Help is available in the configuration.nix(5) man page, on
3 # https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
4
5 { config, lib, pkgs, inputs, ... } @ args:
6
7 {
8   imports =
9     [ # Include the results of the hardware scan.
10       ./hardware-configuration.nix
11     ];
12
13   # Use the GRUB 2 boot loader.
14   boot.loader.systemd-boot.enable = true;
15   # boot.loader.grub.efiSupport = true;
16   # boot.loader.grub.efiInstallAsRemovable = true;
17   # boot.loader.efi.efiSysMountPoint = "/boot/efi";
18   # Define on which hard drive you want to install Grub.
19   # boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only
20
21   nix.settings.experimental-features = [ "nix-command" "flakes" ];
22   nix.settings.download-buffer-size = 500000000;
23
24   nix.gc = {
25     automatic = true;
26     options = "--delete-older-than 30d";
27   };
28   nix.optimise.automatic = true;
29   system.autoUpgrade = {
30     enable = true;
31     allowReboot = true;
32     flake = inputs.self.outPath;
33     flags = [ "-L" ];
34     dates = "02:00";
35     randomizedDelaySec = "45min";
36   };
37
38   networking.hostName = "netcup"; # Define your hostname.
39
40   networking.firewall = {
41     enable = true;
42     allowedTCPPorts = [
43       80 443 # http(s)
44       7777   # terraria
45       9418   # syncthing (?)
46       25565  # minecraft
47     ];
48   };
49
50   # Set your time zone.
51   time.timeZone = "Europe/Amsterdam";
52
53   # Configure network proxy if necessary
54   # networking.proxy.default = "http://user:password@proxy:port/";
55   # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
56
57   # Select internationalisation properties.
58   i18n.defaultLocale = "de_DE.UTF-8";
59   console = {
60     font = "Lat2-Terminus16";
61     keyMap = "de-latin1-nodeadkeys";
62     # useXkbConfig = true; # use xkb.options in tty.
63   };
64
65   # Define a user account. Don't forget to set a password with ‘passwd’.
66   users.users.ps = {
67     isNormalUser = true;
68     extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
69     packages = with pkgs; [
70     ];
71   };
72
73   users.users.live = {
74     isSystemUser = true;
75     group = "live";
76     home = "/srv/live";
77     createHome = true;
78     useDefaultShell = true;
79   };
80   users.groups.live = {};
81
82   security = {
83     polkit.enable = true;
84     sudo.wheelNeedsPassword = false;
85   };
86
87   nixpkgs.config.allowUnfree = true;
88
89   nixpkgs.overlays = [
90     (inputs.ps-flakes.overlays.cgit)
91     (inputs.ps-flakes.overlays.gitweb)
92     (inputs.nix-minecraft.overlay)
93   ];
94
95   # List packages installed in system profile. To search, run:
96   # $ nix search wget
97   environment.systemPackages = with pkgs; [
98     vim wget file git fzf bat
99     openssh
100     helix
101     gitui
102     bintools
103     btop htop
104     systemctl-tui
105     tmux
106     md4c
107     highlight
108     multimarkdown
109     python312Packages.pygments
110
111     pkg-config
112   ];
113
114   environment.shellAliases = {
115     snrs = "sudo nixos-rebuild switch --flake /etc/nixos#default";
116     snrt = "sudo nixos-rebuild test --flake /etc/nixos#default";
117     snrb = "sudo nixos-rebuild boot --flake /etc/nixos#default";
118     senc = "sudo ${pkgs.helix}/bin/hx /etc/nixos/configuration.nix";
119   };
120
121   # git-hooks
122   system.activationScripts.githook =
123     let
124       githooksRepo = pkgs.fetchgit {
125         url = "git://psch.dev/git-hooks";
126         rev = "1a40e097c8854d5a0e65c070addaa7e3337635c0";
127         hash = "sha256-KNKnP/3hhQQlildzRF+skYHtV+7Xg1MQMPi2DDEHGAI=";
128       };
129     in
130     {
131     text = ''
132       PATH=$PATH:${lib.makeBinPath [ pkgs.git pkgs.sudo pkgs.python3 ]} sudo -u git ${githooksRepo}/git-hooks/post-receive
133     '';
134   };
135
136   # git
137   users.users.git = {
138     isSystemUser = true;
139     group = "git";
140     home = "/srv/git";
141     createHome = true;
142     homeMode = "750";
143     shell = "${pkgs.git}/bin/git-shell";
144     packages = with pkgs; [
145       python3 # for blog git-hook
146     ];
147   };
148   users.groups.git = {};
149
150   programs.git = {
151     enable = true;
152     config = {
153       init.defaultBranch = "main";
154       user.name = "Patrick";
155       user.email = "patrick.schoenberger@posteo.de";
156     };
157   };
158
159   services.gitDaemon = {
160     enable = true;
161     basePath = "/srv/git";
162     repositories = [ "/srv/git" ];
163     exportAll = true;
164     port = 9418;
165   };
166
167   # Enable the OpenSSH daemon.
168   services.openssh = {
169     enable = true;
170     extraConfig = ''
171       Match user git
172         AllowTcpForwarding no
173         AllowAgentForwarding no
174         PasswordAuthentication no
175         PermitTTY no
176         X11Forwarding no
177     '';
178   };
179   services.qemuGuest.enable = true;
180   # virtualisation.qemu.guestAgent.enable = true;
181   programs.mosh.enable = true;
182
183   services.minecraft-servers = {
184     enable = true;
185     eula = true;
186     servers.fabric = {
187       enable = true;
188
189       serverProperties = {
190         difficulty = 2;
191         motd = "A Place on Earth";
192         white-list = true;
193       };
194       
195       package = pkgs.fabricServers.fabric-1_20_1;
196       # .override {
197       #   loaderVersion = "";
198       # }
199       symlinks = {
200         mods = pkgs.linkFarmFromDrvs "mods" (
201           builtins.attrValues {
202             Fabric-API = pkgs.fetchurl {
203               url = "https://cdn.modrinth.com/data/P7dR8mSH/versions/UapVHwiP/fabric-api-0.92.6%2B1.20.1.jar";
204               sha256 = "sha256-Ds5QR22jaSERqwS3WUXFRY5w2YzQae78BEqz5Xl33us=";
205             };
206             GlitchCore = pkgs.fetchurl {
207               url = "https://cdn.modrinth.com/data/s3dmwKy5/versions/25HLOiOl/GlitchCore-fabric-1.20.1-0.0.1.1.jar";
208               sha256 = "sha256-+359QjXKv4OVR4vEKu9rv9u++JUd3x9w9zcZ4LJMmcw=";
209             };
210             TerraBlender = pkgs.fetchurl {
211               url = "https://cdn.modrinth.com/data/kkmrDlKT/versions/J1S3aA8i/TerraBlender-fabric-1.20.1-3.0.1.10.jar";
212               sha256 = "sha256-0C2aoszwkSZLD87wdkQSi4I7NCGgK/xAORoBqhzNCiQ=";
213             };
214             BiomesOPlenty = pkgs.fetchurl {
215               url = "https://cdn.modrinth.com/data/HXF82T3G/versions/eZaag2ca/BiomesOPlenty-fabric-1.20.1-19.0.0.96.jar";
216               sha256 = "sha256-A4Kp4TNMtzbE8Nhs8NACEG1qmEU6cJlQ678Ok5gx6nI=";
217             };
218           }
219         );
220       };
221     };
222   };
223
224   services.caddy = {
225     enable = true;
226
227     extraConfig = ''
228     psch.dev ps.run pasch.cc {
229       rewrite /src /src/
230       handle_path /src/* {
231         reverse_proxy http://localhost:3000
232       }
233       rewrite /git /git/
234       handle_path /git/* {
235         encode gzip zstd
236
237         @assets path /cgit.css /cgit.png /favicon.ico /robots.txt
238         handle /cgithub/* {
239           file_server {
240             root /srv/cgithub
241           }
242         }
243         handle @assets {
244           file_server {
245             root ${pkgs.cgit}/cgit
246           }
247         }
248         handle {
249           reverse_proxy unix//run/fcgiwrap-git.sock {
250             transport fastcgi {
251               env CGIT_CONFIG ${pkgs.writeText "cgitrc" ''
252                 snapshots=tar tar.gz zip
253                 enable-git-config=1
254                 enable-index-owner=0
255                 enable-log-filecount=1
256                 enable-log-linecount=1
257                 section-from-path=1
258                 virtual-root=/git
259                 css=/git/cgit.css
260                 logo=/git/cgit.png
261                 favicon=/git/favicon.ico
262                 module-link=/%s/commit/?id=%s
263                 clone-url=https://$HTTP_HOST/git/$CGIT_REPO_URL git://$HTTP_HOST/$CGIT_REPO_URL git@$HTTP_HOST:$CGIT_REPO_URL
264                 noplainemail=1
265                 repository-sort=age
266                 about-filter=${pkgs.writeShellScript "markdown-filter" ''
267                   echo '<div class="markdown-body">'
268                   ${pkgs.md4c}/bin/md2html --github --ftables
269                   echo '</div>'
270                 ''}
271                 # source-filter=${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
272                 head-include=/srv/cgithub/head-include.html
273                 footer=/srv/cgithub/footer.html
274                 readme=:readme.md
275                 readme=:Readme.md
276                 readme=:ReadMe.md
277                 readme=:README.md
278                 scan-path=/srv/git
279               ''}
280               env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
281             }
282           }
283         }
284       }
285
286       basic_auth /julius_cam/* { test $2a$14$iKv0GlwavCunG0zQbaf2fOl4r4/8k8gDKUVUouu9Q3o.MfSDkp6Te }
287       root * /srv/www
288       file_server
289     }
290     tnx.sh {
291       respond "The Website is under Construction."
292     }
293     chirp.ps.run {
294       reverse_proxy http://localhost:8080 {
295         request_buffers 8192
296       }
297     }
298     mail.psch.dev {
299       respond mail
300     }
301     '';
302   };
303   # virtualHosts."git.psch.dev".extraConfig = ''
304   #   reverse_proxy unix//run/anubis/anubis-cgit.sock
305   # '';
306   services.caddy.virtualHosts."gitweb.ps.run".extraConfig = ''
307     handle /static/* {
308       file_server {
309         root ${pkgs.gitweb}
310       }
311     }
312     handle {
313       reverse_proxy unix//run/fcgiwrap-git.sock {
314         transport fastcgi {
315           env GITWEB_CONFIG ${pkgs.writeText "gitweb.conf" ''
316             $projectroot = "/srv/git";
317             $base_url = "/";
318             $feature{'pathinfo'}{'default'} = [1];
319             $default_projects_order = "age";
320             $omit_owner = true;
321             $site_html_head_string = "<meta xmlns=\"http://www.w3.org/1999/xhtml\" name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />";
322           ''}
323           env SCRIPT_FILENAME ${pkgs.gitweb}/gitweb.cgi
324         }
325       }
326     }
327   '';
328   # virtualHosts."gitweb.psch.dev".extraConfig = ''
329   #   reverse_proxy unix//run/anubis/anubis-gitweb.sock
330   # '';
331
332   services.anubis = {
333     defaultOptions = {
334       user = "caddy";
335       group = "caddy";
336     };
337     
338     # instances.cgit.settings.TARGET = "http://localhost:8082/cgit";
339     # instances.gitweb.settings.TARGET = "http://localhost:8082";
340   };
341
342   services.fcgiwrap.instances."git" = {
343     process.user = "git";
344     process.group = "git";
345     socket.user = "caddy";
346     socket.group = "caddy";
347   };
348
349   services.forgejo = {
350     enable = true;
351     repositoryRoot = "/srv/git2";
352     settings = {
353       server = {
354         DOMAIN = "ps.run";
355         ROOT_URL = "https://ps.run/src";
356       };
357       repository = {
358         REQUIRE_SIGNIN_VIEW = false; 
359       };
360       service = {
361         REQUIRE_SIGNIN_VIEW = false; 
362         DISABLE_REGISTRATION = true;
363       };
364     };
365   };
366   users.users.forgejo.extraGroups = [ "git" ];
367
368   users.users.chirp = {
369     isSystemUser = true;
370     group = "chirp";
371     home = "/var/lib/chirp";
372     createHome = true;
373   };
374   users.groups.chirp = {};
375
376   systemd.services.poster-splitter =
377     let
378       poster-splitter-src = "/var/lib/postersplitter/repo";
379     in
380     {
381       description = "Poster Splitter";
382       wantedBy = [ "multi-user.target" ];
383       after = [ "network.target" ];
384
385       serviceConfig = {
386         Type = "simple";
387         User = "poster";
388         Group = "poster";
389         WorkingDirectory = "${poster-splitter-src}";
390       
391         ExecStart = "${pkgs.bash}/bin/bash -c 'PATH=$PATH:${lib.makeBinPath [ pkgs.bash pkgs.python3 ]} LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/ /var/lib/postersplitter/run.sh'";
392         Restart = "on-failure";
393       };
394     };
395   services.webhook = {
396     enable = true;
397     port = 8102;
398     user = "root";
399     group = "root";
400     hooks = {
401       "deploy-poster-splitter" = {
402         id = "deploy-poster-splitter";
403         response-message = "Deployed Poster Splitter";
404         execute-command = "/var/lib/postersplitter/deploy.sh";
405         command-working-directory = "/var/lib/postersplitter";
406         pass-environment-to-command = [
407           { source = "string"; envname = "PATH"; name = "${lib.makeBinPath [ pkgs.coreutils pkgs.sudo pkgs.systemd pkgs.openssh pkgs.git pkgs.bash pkgs.python3 pkgs.git ]}"; }
408         ];
409         trigger-rule = {
410           match = {
411             type = "payload-hmac-sha1";
412             secret = "mysecret";
413             parameter = {
414               source = "header";
415               name = "X-Hub-Signature";
416             };
417           };
418         };
419       };
420     };
421   };
422   services.caddy.virtualHosts."postersplitter.de".extraConfig = ''
423     # Route 1: Der Webhook
424     # Leitet Anfragen an /hooks/ an den Webhook-Dienst
425     @webhook path /hooks/*
426     handle @webhook {
427       reverse_proxy 127.0.0.1:8102
428     }
429
430     # Route 2: Die Flask App (alles andere)
431     # Muss NACH der Webhook-Route kommen
432     @all not path /hooks/*
433     handle @all {
434       reverse_proxy 127.0.0.1:8101
435     }
436   '';
437   users.users.poster = {
438     isSystemUser = true;
439     group = "poster";
440     home = "/var/lib/postersplitter";
441     createHome = true;
442     useDefaultShell = true;
443     packages = with pkgs; [
444       python314
445     ];
446   };
447   users.groups.poster = {};
448   
449   systemd.services.chirp = {
450     description = "Chirp SystemD Service";
451     wantedBy = ["multi-user.target"];
452     after = ["network.target"];
453     serviceConfig = {
454       WorkingDirectory = "/var/lib/chirp";
455       ExecStart = "${args.inputs.chirp.packages.${pkgs.system}.default}/bin/chirp";
456       Restart = "always";
457       Type = "simple";
458       User = "chirp";
459       Group = "chirp";
460     };
461   };
462
463   # Mail Server
464   mailserver = {
465     enable = true;
466     # stateVersion = 1;
467     fqdn = "mail.psch.dev";
468     domains = [ "psch.dev" ];
469
470     # A list of all login accounts. To create the password hashes, use
471     # nix-shell -p mkpasswd --run 'mkpasswd -sm bcrypt'
472     loginAccounts = {
473       "ps@psch.dev" = {
474         hashedPassword = "$2b$05$dd65mMjWxZNc.MK4YUwLgeRMInJHvwNTazptImrw4paRqyX/p4TQG";
475         aliases = ["p@psch.dev" "patrick@psch.dev"];
476       };
477     };
478
479     certificateScheme = "manual";
480     certificateFile = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.psch.dev/mail.psch.dev.crt";
481     keyFile = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.psch.dev/mail.psch.dev.key";
482   };
483   # security.acme.acceptTerms = true;
484   # security.acme.defaults.email = "patrick.schoenberger@posteo.de";
485
486   # Copy the NixOS configuration file and link it from the resulting system
487   # (/run/current-system/configuration.nix). This is useful in case you
488   # accidentally delete configuration.nix.
489   # system.copySystemConfiguration = true;
490
491   # This option defines the first version of NixOS you have installed on this particular machine,
492   # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
493   #
494   # Most users should NEVER change this value after the initial install, for any reason,
495   # even if you've upgraded your system to a new NixOS release.
496   #
497   # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
498   # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
499   # to actually do that.
500   #
501   # This value being lower than the current NixOS release does NOT mean your system is
502   # out of date, out of support, or vulnerable.
503   #
504   # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
505   # and migrated your data accordingly.
506   #
507   # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
508   system.stateVersion = "24.05"; # Did you read the comment?
509
510 }
511