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