]> 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, ... } @ 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.package = pkgs.nixVersions.nix_2_28;
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   # List packages installed in system profile. To search, run:
81   # $ nix search wget
82   environment.systemPackages = with pkgs; [
83     vim wget file git fzf bat
84     helix
85     gitui
86     bintools
87     btop htop
88     systemctl-tui
89     tmux
90     md4c
91     highlight
92     python312Packages.pygments
93
94     pkg-config
95   ];
96
97   environment.shellAliases = {
98     snrs = "sudo nixos-rebuild switch --flake /etc/nixos#default";
99     snrt = "sudo nixos-rebuild test --flake /etc/nixos#default";
100     snrb = "sudo nixos-rebuild boot --flake /etc/nixos#default";
101     senc = "sudo ${pkgs.helix}/bin/hx /etc/nixos/configuration.nix";
102   };
103
104   # git
105   users.users.git = {
106     isSystemUser = true;
107     group = "git";
108     home = "/srv/git";
109     createHome = true;
110     homeMode = "750";
111     shell = "${pkgs.git}/bin/git-shell";
112     openssh.authorizedKeys.keys = [
113       "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICQOPefMnq0qvFjYxlrdlSmUgyCbvV85gkfRykVlTnrn ps@nixos"
114       "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB0mNZn4EWdIwXEGfqUwwJy5STaZLYWbeKqDd4MN8WIK root@nixos"
115       "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL+1sLAf+I+o3aODJeDuNvbqKD1wokQyk6oX0ZGK8su5 root@pschdev"
116       "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN6sNqiMZpmRkiwjj5Dv0QljLObzhopwIsF0WDQbr/Hg ps@nixos"
117     ];
118   };
119   users.groups.git = {};
120
121   programs.git = {
122     enable = true;
123     config = {
124       init.defaultBranch = "main";
125       user.name = "Patrick";
126       user.email = "patrick.schoenberger@posteo.de";
127     };
128   };
129
130   services.gitDaemon = {
131     enable = true;
132     basePath = "/srv/git";
133     repositories = [ "/srv/git" ];
134     exportAll = true;
135     port = 9418;
136   };
137
138   # Enable the OpenSSH daemon.
139   services.openssh = {
140     enable = true;
141     extraConfig = ''
142       Match user git
143         AllowTcpForwarding no
144         AllowAgentForwarding no
145         PasswordAuthentication no
146         PermitTTY no
147         X11Forwarding no
148     '';
149   };
150   services.qemuGuest.enable = true;
151   # virtualisation.qemu.guestAgent.enable = true;
152   programs.mosh.enable = true;
153
154
155   services.caddy = {
156     enable = true;
157     virtualHosts."psch.dev".extraConfig = ''
158       root * /srv/www
159       file_server
160     '';
161     virtualHosts."julius.psch.dev".extraConfig = ''
162       basic_auth { test $2a$14$iKv0GlwavCunG0zQbaf2fOl4r4/8k8gDKUVUouu9Q3o.MfSDkp6Te }
163       root * /srv/julius_cam
164       file_server
165     '';
166     virtualHosts."chirp.psch.dev".extraConfig = ''
167       reverse_proxy http://localhost:8080 {
168         request_buffers 8192
169       }
170     '';
171   };
172   services.caddy.virtualHosts."git.psch.dev".extraConfig = ''
173     encode gzip zstd
174
175     @assets path /cgit.css /cgit.png /favicon.ico /robots.txt
176     handle /cgithub/* {
177       file_server {
178         root /srv/cgithub
179       }
180     }
181     handle @assets {
182       file_server {
183         root ${pkgs.cgit}/cgit
184       }
185     }
186     handle {
187       reverse_proxy unix//run/fcgiwrap-git.sock {
188         transport fastcgi {
189           env CGIT_CONFIG ${pkgs.writeText "cgitrc" ''
190             snapshots=tar tar.gz zip
191             enable-git-config=1
192             enable-index-owner=0
193             section-from-path=1
194             virtual-root=/
195             module-link=/%s/commit/?id=%s
196             clone-url=https://git.psch.dev/$CGIT_REPO_URL git://psch.dev/$CGIT_REPO_URL ssh://git@psch.dev:$CGIT_REPO_URL
197             noplainemail=1
198             side-by-side-diffs=1
199             about-filter=${pkgs.writeShellScript "markdown-filter" ''
200               echo '<div class="markdown-body">'
201               ${pkgs.md4c}/bin/md2html --github --ftables
202               echo '</div>'
203             ''}
204             # source-filter=${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py
205             head-include=/srv/cgithub/head-include.html
206             footer=/srv/cgithub/footer.html
207             readme=:readme.md
208             readme=:Readme.md
209             readme=:ReadMe.md
210             readme=:README.md
211             scan-path=/srv/git
212           ''}
213           env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
214         }
215       }
216     }
217   '';
218   # virtualHosts."git.psch.dev".extraConfig = ''
219   #   reverse_proxy unix//run/anubis/anubis-cgit.sock
220   # '';
221   services.caddy.virtualHosts."gitweb.psch.dev".extraConfig = ''
222     handle /static/* {
223       file_server {
224         root ${pkgs.gitweb}
225       }
226     }
227     handle {
228       reverse_proxy unix//run/fcgiwrap-git.sock {
229         transport fastcgi {
230           env GITWEB_CONFIG ${pkgs.writeText "gitweb.conf" ''
231             $projectroot = "/srv/git";
232             $base_url = "/";
233             $feature{'pathinfo'}{'default'} = [1];
234             $default_projects_order = "age";
235             $omit_owner = true;
236             $site_html_head_string = "<meta xmlns=\"http://www.w3.org/1999/xhtml\" name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />";
237           ''}
238           env SCRIPT_FILENAME ${pkgs.gitweb}/gitweb.cgi
239         }
240       }
241     }
242   '';
243   # virtualHosts."gitweb.psch.dev".extraConfig = ''
244   #   reverse_proxy unix//run/anubis/anubis-gitweb.sock
245   # '';
246
247   services.anubis = {
248     defaultOptions = {
249       user = "caddy";
250       group = "caddy";
251     };
252     
253     # instances.cgit.settings.TARGET = "http://localhost:8082/cgit";
254     # instances.gitweb.settings.TARGET = "http://localhost:8082";
255   };
256
257   services.fcgiwrap.instances."git" = {
258     process.user = "git";
259     process.group = "git";
260     socket.user = "caddy";
261     socket.group = "caddy";
262   };
263
264   users.users.chirp = {
265     isSystemUser = true;
266     group = "chirp";
267     home = "/var/lib/chirp";
268     createHome = true;
269   };
270   users.groups.chirp = {};
271   
272   systemd.services.chirp = {
273     description = "Chirp SystemD Service";
274     wantedBy = ["multi-user.target"];
275     after = ["network.target"];
276     serviceConfig = {
277       WorkingDirectory = "/var/lib/chirp";
278       ExecStart = "${args.inputs.chirp.packages.${pkgs.system}.default}/bin/chirp";
279       Restart = "always";
280       Type = "simple";
281       User = "chirp";
282       Group = "chirp";
283     };
284   };
285
286   # Copy the NixOS configuration file and link it from the resulting system
287   # (/run/current-system/configuration.nix). This is useful in case you
288   # accidentally delete configuration.nix.
289   # system.copySystemConfiguration = true;
290
291   # This option defines the first version of NixOS you have installed on this particular machine,
292   # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
293   #
294   # Most users should NEVER change this value after the initial install, for any reason,
295   # even if you've upgraded your system to a new NixOS release.
296   #
297   # This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
298   # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
299   # to actually do that.
300   #
301   # This value being lower than the current NixOS release does NOT mean your system is
302   # out of date, out of support, or vulnerable.
303   #
304   # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
305   # and migrated your data accordingly.
306   #
307   # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
308   system.stateVersion = "24.05"; # Did you read the comment?
309
310 }
311