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