]> gitweb.ps.run Git - flake_server/blob - configuration.nix
update config
[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 = "pschdev"; # Define your hostname.
35
36   networking.firewall = {
37     enable = true;
38     allowedTCPPorts = [ 80 443 7777 9418 ];
39   };
40
41   # Set your time zone.
42   time.timeZone = "Europe/Amsterdam";
43
44   # Configure network proxy if necessary
45   # networking.proxy.default = "http://user:password@proxy:port/";
46   # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
47
48   # Select internationalisation properties.
49   i18n.defaultLocale = "de_DE.UTF-8";
50   console = {
51     font = "Lat2-Terminus16";
52     keyMap = "de-latin1-nodeadkeys";
53     # useXkbConfig = true; # use xkb.options in tty.
54   };
55
56   # Define a user account. Don't forget to set a password with ‘passwd’.
57   users.users.ps = {
58     isNormalUser = true;
59     extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
60     packages = with pkgs; [
61     ];
62   };
63
64   users.users.live = {
65     isSystemUser = true;
66     group = "live";
67     home = "/srv/live";
68     createHome = true;
69     useDefaultShell = true;
70   };
71   users.groups.live = {};
72
73   security = {
74     polkit.enable = true;
75     sudo.wheelNeedsPassword = false;
76   };
77
78   nixpkgs.config.allowUnfree = true;
79
80   nixpkgs.overlays = [
81     (inputs.psch-flakes.overlays.cgit)
82   ];
83
84   # List packages installed in system profile. To search, run:
85   # $ nix search wget
86   environment.systemPackages = with pkgs; [
87     vim wget file git fzf bat
88     helix
89     gitui
90     bintools
91     btop htop
92     systemctl-tui
93     tmux
94     md4c
95     highlight
96     python312Packages.pygments
97
98     pkg-config
99   ];
100
101   environment.shellAliases = {
102     snrs = "sudo nixos-rebuild switch --flake /etc/nixos#default";
103     snrt = "sudo nixos-rebuild test --flake /etc/nixos#default";
104     snrb = "sudo nixos-rebuild boot --flake /etc/nixos#default";
105     senc = "sudo ${pkgs.helix}/bin/hx /etc/nixos/configuration.nix";
106   };
107
108   # git-hooks
109   system.activationScripts.githook =
110     let
111       githooksRepo = pkgs.fetchgit {
112         url = "git://psch.dev/git-hooks";
113         rev = "1a40e097c8854d5a0e65c070addaa7e3337635c0";
114         hash = "sha256-KNKnP/3hhQQlildzRF+skYHtV+7Xg1MQMPi2DDEHGAI=";
115       };
116     in
117     {
118     text = ''
119       PATH=$PATH:${lib.makeBinPath [ pkgs.git pkgs.sudo pkgs.python3 ]} sudo -u git ${githooksRepo}/git-hooks/post-receive
120     '';
121   };
122
123   # git
124   users.users.git = {
125     isSystemUser = true;
126     group = "git";
127     home = "/srv/git";
128     createHome = true;
129     homeMode = "750";
130     shell = "${pkgs.git}/bin/git-shell";
131     packages = with pkgs; [
132       python3 # for blog git-hook
133     ];
134   };
135   users.groups.git = {};
136
137   programs.git = {
138     enable = true;
139     config = {
140       init.defaultBranch = "main";
141       user.name = "Patrick";
142       user.email = "patrick.schoenberger@posteo.de";
143     };
144   };
145
146   services.gitDaemon = {
147     enable = true;
148     basePath = "/srv/git";
149     repositories = [ "/srv/git" ];
150     exportAll = true;
151     port = 9418;
152   };
153
154   # Enable the OpenSSH daemon.
155   services.openssh = {
156     enable = true;
157     extraConfig = ''
158       Match user git
159         AllowTcpForwarding no
160         AllowAgentForwarding no
161         PasswordAuthentication no
162         PermitTTY no
163         X11Forwarding no
164     '';
165   };
166   services.qemuGuest.enable = true;
167   # virtualisation.qemu.guestAgent.enable = true;
168   programs.mosh.enable = true;
169
170   services.caddy = {
171     enable = true;
172
173     virtualHosts."tnx.sh".extraConfig = ''
174       respond "The Website is under Construction."
175     '';
176     virtualHosts."psch.dev".extraConfig = ''
177       basic_auth /julius_cam/* { test $2a$14$iKv0GlwavCunG0zQbaf2fOl4r4/8k8gDKUVUouu9Q3o.MfSDkp6Te }
178       root * /srv/www
179       file_server
180     '';
181     virtualHosts."chirp.psch.dev".extraConfig = ''
182       reverse_proxy http://localhost:8080 {
183         request_buffers 8192
184       }
185     '';
186     virtualHosts."mail.psch.dev".extraConfig = ''
187       respond mail
188     '';
189   };
190   services.caddy.virtualHosts."git.psch.dev".extraConfig = ''
191     encode gzip zstd
192
193     @assets path /cgit.css /cgit.png /favicon.ico /robots.txt
194     handle /cgithub/* {
195       file_server {
196         root /srv/cgithub
197       }
198     }
199     handle @assets {
200       file_server {
201         root ${pkgs.cgit}/cgit
202       }
203     }
204     handle {
205       reverse_proxy unix//run/fcgiwrap-git.sock {
206         transport fastcgi {
207           env CGIT_CONFIG ${pkgs.writeText "cgitrc" ''
208             snapshots=tar tar.gz zip
209             enable-git-config=1
210             enable-index-owner=0
211             enable-log-filecount=1
212             enable-log-linecount=1
213             section-from-path=1
214             virtual-root=/
215             module-link=/%s/commit/?id=%s
216             clone-url=https://git.psch.dev/$CGIT_REPO_URL git://psch.dev/$CGIT_REPO_URL ssh://git@psch.dev/~/$CGIT_REPO_URL
217             noplainemail=1
218             side-by-side-diffs=1
219             repository-sort=age
220             about-filter=${pkgs.writeShellScript "markdown-filter" ''
221               echo '<div class="markdown-body">'
222               ${pkgs.md4c}/bin/md2html --github --ftables
223               echo '</div>'
224             ''}
225             # source-filter=${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
226             head-include=/srv/cgithub/head-include.html
227             footer=/srv/cgithub/footer.html
228             readme=:readme.md
229             readme=:Readme.md
230             readme=:ReadMe.md
231             readme=:README.md
232             scan-path=/srv/git
233           ''}
234           env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
235         }
236       }
237     }
238   '';
239   # virtualHosts."git.psch.dev".extraConfig = ''
240   #   reverse_proxy unix//run/anubis/anubis-cgit.sock
241   # '';
242   services.caddy.virtualHosts."gitweb.psch.dev".extraConfig = ''
243     handle /static/* {
244       file_server {
245         root ${pkgs.gitweb}
246       }
247     }
248     handle {
249       reverse_proxy unix//run/fcgiwrap-git.sock {
250         transport fastcgi {
251           env GITWEB_CONFIG ${pkgs.writeText "gitweb.conf" ''
252             $projectroot = "/srv/git";
253             $base_url = "/";
254             $feature{'pathinfo'}{'default'} = [1];
255             $default_projects_order = "age";
256             $omit_owner = true;
257             $site_html_head_string = "<meta xmlns=\"http://www.w3.org/1999/xhtml\" name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />";
258           ''}
259           env SCRIPT_FILENAME ${pkgs.gitweb}/gitweb.cgi
260         }
261       }
262     }
263   '';
264   # virtualHosts."gitweb.psch.dev".extraConfig = ''
265   #   reverse_proxy unix//run/anubis/anubis-gitweb.sock
266   # '';
267
268   services.anubis = {
269     defaultOptions = {
270       user = "caddy";
271       group = "caddy";
272     };
273     
274     # instances.cgit.settings.TARGET = "http://localhost:8082/cgit";
275     # instances.gitweb.settings.TARGET = "http://localhost:8082";
276   };
277
278   services.fcgiwrap.instances."git" = {
279     process.user = "git";
280     process.group = "git";
281     socket.user = "caddy";
282     socket.group = "caddy";
283   };
284
285   users.users.chirp = {
286     isSystemUser = true;
287     group = "chirp";
288     home = "/var/lib/chirp";
289     createHome = true;
290   };
291   users.groups.chirp = {};
292   
293   systemd.services.chirp = {
294     description = "Chirp SystemD Service";
295     wantedBy = ["multi-user.target"];
296     after = ["network.target"];
297     serviceConfig = {
298       WorkingDirectory = "/var/lib/chirp";
299       ExecStart = "${args.inputs.chirp.packages.${pkgs.system}.default}/bin/chirp";
300       Restart = "always";
301       Type = "simple";
302       User = "chirp";
303       Group = "chirp";
304     };
305   };
306
307   # Mail Server
308   mailserver = {
309     enable = true;
310     # stateVersion = 1;
311     fqdn = "mail.psch.dev";
312     domains = [ "psch.dev" ];
313
314     # A list of all login accounts. To create the password hashes, use
315     # nix-shell -p mkpasswd --run 'mkpasswd -sm bcrypt'
316     loginAccounts = {
317       "ps@psch.dev" = {
318         hashedPassword = "$2b$05$dd65mMjWxZNc.MK4YUwLgeRMInJHvwNTazptImrw4paRqyX/p4TQG";
319         aliases = ["p@psch.dev" "patrick@psch.dev"];
320       };
321     };
322
323     certificateScheme = "manual";
324     certificateFile = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.psch.dev/mail.psch.dev.crt";
325     keyFile = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mail.psch.dev/mail.psch.dev.key";
326   };
327   # security.acme.acceptTerms = true;
328   # security.acme.defaults.email = "patrick.schoenberger@posteo.de";
329
330   # Copy the NixOS configuration file and link it from the resulting system
331   # (/run/current-system/configuration.nix). This is useful in case you
332   # accidentally delete configuration.nix.
333   # system.copySystemConfiguration = true;
334
335   # This option defines the first version of NixOS you have installed on this particular machine,
336   # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
337   #
338   # Most users should NEVER change this value after the initial install, for any reason,
339   # even if you've upgraded your system to a new NixOS release.
340   #
341   # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
342   # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
343   # to actually do that.
344   #
345   # This value being lower than the current NixOS release does NOT mean your system is
346   # out of date, out of support, or vulnerable.
347   #
348   # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
349   # and migrated your data accordingly.
350   #
351   # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
352   system.stateVersion = "24.05"; # Did you read the comment?
353
354 }
355