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