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