]> gitweb.ps.run Git - flake_thinkpad/blob - configuration.nix
(no commit message)
[flake_thinkpad] / 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
3 # and in the NixOS manual (accessible by running ‘nixos-help’).
4
5 { config, pkgs, inputs, lib, ... } @ args:
6
7
8 let
9   # tuigreet = "${pkgs.greetd.tuigreet}/bin/tuigreet";
10   # session = "${pkgs.sway}/bin/sway";
11   # username = "ps";
12   wallpaper = pkgs.fetchurl {
13     url = "https://w.wallhaven.cc/full/ex/wallhaven-exrqrr.jpg";
14     sha256 = "sha256-RYN8KwJPDMfxrcosbpmjON0Y+I58IhB1Ke36LdohsxA=";
15   };
16 in
17
18 {
19   imports =
20     [ # Include the results of the hardware scan.
21       ./hardware-configuration.nix
22       inputs.home-manager.nixosModules.default
23       inputs.extra-container.nixosModules.default
24       inputs.microvm.nixosModules.host
25     ];
26
27   # Bootloader.
28   boot.tmp.cleanOnBoot = true;
29   boot.loader.systemd-boot.enable = true;
30   boot.loader.efi.canTouchEfiVariables = true;
31   boot.plymouth.enable = true;
32   boot.plymouth.theme = "bgrt";
33   boot.initrd.verbose = false;
34   boot.initrd.systemd.enable = true;
35   boot.initrd.kernelModules = [ "amdgpu" ];
36   boot.consoleLogLevel = 0;
37   boot.kernelPackages = pkgs.linuxPackages_latest;
38   boot.kernelParams = [ "quiet" "udev.log_level=0" "amdgpu.runpm=0" ];
39
40   # incus admin init --minimal
41   # incus image list images:
42   # incus launch images:ubuntu/noble <name>
43   # incus exec <name> -- /bin/bash
44   # incus exec <name> -- adduser --shell /bin/bash --ingroup sudo ps
45   # incus exec <name> -- su - ps -c 'tmux new-session -A -s main'
46   virtualisation.incus.enable = true;
47   virtualisation.incus.ui.enable = true;
48   networking.nftables.enable = true;
49   networking.firewall.trustedInterfaces = [ "incusbr0" ];
50
51   networking.hostName = "thinkpad"; # Define your hostname.
52   # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
53
54   nix.settings.experimental-features = [ "nix-command" "flakes" ];
55   nix.settings.download-buffer-size = 500000000;
56   nix.settings.trusted-users = ["root" "ps"];
57
58   # Configure network proxy if necessary
59   # networking.proxy.default = "http://user:password@proxy:port/";
60   # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
61
62   # Enable networking
63   networking.networkmanager.enable = true;
64
65   # Set your time zone.
66   time.timeZone = "Europe/Berlin";
67
68   # Select internationalisation properties.
69   i18n.defaultLocale = "de_DE.UTF-8";
70
71   i18n.extraLocaleSettings = {
72     LC_ADDRESS = "de_DE.UTF-8";
73     LC_IDENTIFICATION = "de_DE.UTF-8";
74     LC_MEASUREMENT = "de_DE.UTF-8";
75     LC_MONETARY = "de_DE.UTF-8";
76     LC_NAME = "de_DE.UTF-8";
77     LC_NUMERIC = "de_DE.UTF-8";
78     LC_PAPER = "de_DE.UTF-8";
79     LC_TELEPHONE = "de_DE.UTF-8";
80     LC_TIME = "de_DE.UTF-8";
81   };
82
83   programs.dconf.enable = true;
84   programs.steam.enable = true;
85
86   # Containers
87   containers = {
88     im = {
89       ephemeral = true;
90       # privateNetwork = true;
91       localAddress = "10.23.45.2";
92       hostAddress = "10.23.45.1";
93
94       bindMounts."/per".hostPath = "/var/lib/nixos-containers/im";
95       bindMounts."/per".isReadOnly = false;
96
97       extraFlags = [
98         "--property='MemoryMax=60M'"
99         "--property='MemoryHigh=50M'"
100         "--property='CPUQuota=4%'"
101       ];
102
103       config = { config, pkgs, ... }: {
104         imports = [ inputs.impermanence.nixosModules.impermanence ];
105
106         environment.persistence."/per" = {
107           directories = [
108             "/var/log"
109             "/var/lib"
110             { directory = "/home/ps"; user = "ps"; group = "users"; mode = "0750"; }
111           ];
112           files = [];
113         };
114         environment.systemPackages = with pkgs; [ helix python312 deno ];
115
116         users.users.ps = { isNormalUser = true; };
117
118         networking.firewall.allowedTCPPorts = [ 80 8080 ];
119
120         system.stateVersion = "25.05";
121       };
122     };
123   };
124   networking.nat.enable = true;
125   networking.nat.internalInterfaces = ["ve-+"];
126   networking.nat.externalInterface = "eth0";
127   networking.networkmanager.unmanaged = [ "interface-name:ve-*" ];
128
129   # Services
130   services = {
131     displayManager = {
132       defaultSession = "xfce+i3";
133     };
134     desktopManager = {
135       plasma6.enable = true;
136     };
137     xserver = {
138       enable = true;
139       
140       displayManager = {
141         lightdm = {
142           enable = true;
143           greeters.gtk = {
144             theme = {
145               name = "Qogir-Dark";
146               package = pkgs.qogir-theme;
147             };
148             iconTheme = {
149               name = "Qogir-dark";
150               package = pkgs.qogir-icon-theme;
151             };
152             cursorTheme = {
153               name = "volantes_light_cursors";
154               package = pkgs.volantes-cursors;
155             };
156           };
157           background = "${wallpaper}";
158         };
159       };
160
161       desktopManager = {
162         xterm.enable = false;
163         xfce = {
164           enable = true;
165           noDesktop = true;
166           enableXfwm = false;
167         };
168       };
169       windowManager.i3.enable = true;
170       windowManager.awesome.enable = true;
171       windowManager.herbstluftwm.enable = true;
172
173       xkb = {
174         layout = "de";
175         variant = "nodeadkeys";
176         options = "caps:ctrl_modifier";
177       };
178       excludePackages = [ pkgs.xterm ];
179       videoDrivers = ["amdgpu"];
180       # libinput.enable = true;
181     };
182   };
183
184   systemd.user.services.plasma-i3wm = {
185     wantedBy = [ "plasma-workspace-x11.target" ];
186     before = [ "plasma-workspace-x11.target" ];
187     description = "Launch Plasma with i3";
188     environment = lib.mkForce {};
189     serviceConfig = {
190       ExecStart = "${pkgs.i3}/bin/i3";
191       Restart = "on-failure";
192     };
193   };
194   # systemd.user.services.plasma-workspace-x11.after = [ "plasma-i3wm.target" ];
195   systemd.user.services.plasma-kwin_x11.enable = false;
196
197   services.autorandr = {
198     enable = true;
199     matchEdid = true;
200     hooks = {
201       postswitch = {
202         "set-wallpaper" = "set-wallpaper";
203       };
204     };
205   };
206   
207   services.syncthing = {
208     enable = true;
209     user = "ps";
210     dataDir = "/home/ps/sync";
211     configDir = "/home/ps/.config/syncthing";
212   };
213   
214   # services.auto-cpufreq.enable = true;
215   services.auto-cpufreq.settings = {
216     battery = {
217        governor = "powersave";
218        turbo = "never";
219     };
220     charger = {
221        governor = "performance";
222        turbo = "auto";
223     };
224   };
225
226   # services.tlp = {
227   #   enable = true;
228   #   settings = {
229   #     CPU_SCALING_GOVERNOR_ON_AC = "performance";
230   #     CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
231   #
232   #     CPU_ENERGY_PERF_POLICY_ON_AC = "balance_performance";
233   #     CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
234   #
235   #     PLATFORM_PROFILE_ON_AC = "balanced";
236   #     PLATFORM_PROFILE_ON_BAT = "low-power";
237   #
238   #     CPU_BOOST_ON_AC = "1";
239   #     CPU_BOOST_ON_BAT = "0";
240   #
241   #     AMDGPU_ABM_LEVEL_ON_AC = "0";
242   #     AMDGPU_ABM_LEVEL_ON_BAT = "3";
243   #
244   #     CPU_MIN_PERF_ON_AC = 0;
245   #     CPU_MAX_PERF_ON_AC = 100;
246   #     CPU_MIN_PERF_ON_BAT = 0;
247   #     CPU_MAX_PERF_ON_BAT = 20;
248   #
249   #     # START_CHARGE_THRESH_BAT0 = 40; # 40 and below it starts to charge
250   #     STOP_CHARGE_THRESH_BAT0 = 90; # 85 and above it stops charging
251   #   };
252   # };
253
254   services.udev.extraRules = ''
255     KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{serial}=="*vial:f64c2b3c*", MODE="0660", GROUP="users", TAG+="uaccess", TAG+="udev-acl"
256   '';
257
258   # OpenGL
259   hardware = {
260     graphics = {
261         enable = true;
262         enable32Bit = true;
263         extraPackages = with pkgs; [
264           rocmPackages.clr.icd
265           mesa.opencl
266           amf
267         ];
268     };
269
270     amdgpu.amdvlk = {
271         enable = true;
272         support32Bit.enable = true;
273     };
274   };
275
276   # services.logind = {
277   #   extraConfig = "HandlePowerKey=suspend";
278   #   lidSwitch = "suspend";
279   # }; 
280
281   # Configure console keymap
282   console.keyMap = "de-latin1-nodeadkeys";
283
284   # Enable CUPS to print documents.
285   services.printing.enable = true;
286   services.printing.drivers = [ pkgs.gutenprint ];
287
288   # Enable scanners
289   hardware.sane.enable = true;
290   hardware.sane.extraBackends = [ pkgs.hplipWithPlugin pkgs.sane-airscan ];
291   services.avahi.enable = true;
292   services.avahi.nssmdns4 = true;
293   services.avahi.reflector = true;
294   services.udev.packages = [ pkgs.sane-airscan ];
295
296   # Enable Bluetooth
297   hardware.bluetooth.enable = true;
298   hardware.bluetooth.powerOnBoot = false;
299   # services.blueman.enable = true;
300
301   # Enable sound with pipewire.
302   services.pulseaudio.enable = false;
303   security.rtkit.enable = true;
304   services.pipewire = {
305     enable = true;
306     alsa.enable = true;
307     alsa.support32Bit = true;
308     pulse.enable = true;
309     # If you want to use JACK applications, uncomment this
310     #jack.enable = true;
311
312     # use the example session manager (no others are packaged yet so this is enabled by default,
313     # no need to redefine it in your config for now)
314     #media-session.enable = true;
315   };
316   services.jack = {
317     jackd.enable = true;
318   };
319
320   # Enable touchpad support (enabled default in most desktopManager).
321   # services.libinput.touchpad = {
322   #   naturalScrolling = false;
323   # };
324
325   # Define a user account. Don't forget to set a password with ‘passwd’.
326   users.groups.ssh = {};
327   users.users = {
328     ps = {
329       isNormalUser = true;
330       description = "Patrick";
331       shell = pkgs.bash;
332       extraGroups = [ "networkmanager" "wheel" "dialout" "jackaudio" "lp" "incus-admin" ];
333     };
334     # sshd = {
335     #   isSystemUser = true;
336     #   packages = [
337     #     pkgs.python3
338     #   ];
339     #   group = "ssh";
340     # };
341     chirp = {
342       isSystemUser = true;
343       packages = [
344         pkgs.python3
345       ];
346       group = "ssh";
347       shell = pkgs.bash;
348       initialPassword = "chirp";
349     };
350   };
351   
352   security.polkit.enable = true;
353   security.sudo.wheelNeedsPassword = false;
354
355   home-manager = {
356     backupFileExtension = "backup";
357     extraSpecialArgs = {
358       inherit inputs;
359       inherit wallpaper;
360     };
361     users = {
362       "ps" = import ./home-ps.nix;
363       "root" = { home.stateVersion = "24.05"; };
364     };
365     sharedModules = [
366       (import ./home-common.nix)
367     ];
368   };
369
370   # Enable automatic login for the user.
371   # services.displayManager.autoLogin.enable = true;
372   # services.displayManager.autoLogin.user = "ps";
373   # services.getty.autologinUser = "ps";
374
375   # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229
376   # systemd.services."getty@tty1".enable = false;
377   # systemd.services."autovt@tty1".enable = false;
378
379   # Allow unfree packages
380   nixpkgs.config.allowUnfree = true;
381
382
383   environment.variables = {
384     RUSTICL_ENABLE = "radeonsi";
385   };
386   # List packages installed in system profile. To search, run:
387   # $ nix search wget
388   environment.systemPackages = with pkgs; [
389     args.inputs.zls.inputs.zig-overlay.packages.${pkgs.system}.master
390     args.inputs.zls.packages.${pkgs.system}.zls
391     args.inputs.psch-flakes.packages.${pkgs.system}.resetmsmice
392     args.inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.zuban
393     vim wget file git kitty i3 gdb
394     mosh
395     cmake
396     entr
397     asciinema asciinema-agg
398     shellify
399     deno
400
401     scrcpy
402
403     xsel
404     xcwd
405
406     pinta
407     mupdf
408     davinci-resolve
409
410     pavucontrol
411     syncthingtray
412     # xfce plugins
413     xfce.xfce4-panel
414     xfce.xfce4-pulseaudio-plugin
415     # xfce.xfce4-verve-plugin
416     xfce.xfce4-notes-plugin
417     # xfce.xfce4-timer-plugin
418     # xfce.xfce4-windowck-plugin
419     xfce.thunar-archive-plugin
420     # xfce.xfce4-i3-workspaces-plugin
421     # xfce.xfce4-xkb-plugin
422     xfce.xfce4-whiskermenu-plugin
423
424   ];
425
426   programs.xfconf.enable = true;
427   programs.nix-ld.enable = true;
428
429   services.fwupd.enable = true;
430
431   # Some programs need SUID wrappers, can be configured further or are
432   # started in user sessions.
433   # programs.mtr.enable = true;
434   # programs.gnupg.agent = {
435   #   enable = true;
436   #   enableSSHSupport = true;
437   # };
438
439   # List services that you want to enable:
440
441   # Enable the OpenSSH daemon.
442   services.openssh = {
443     enable = true;
444     ports = [ 22 ];
445     # settings = {
446     #   PasswordAuthentication = false;
447     #   PermitRootLogin = "no";
448     # };
449     # authorizedKeysCommand =
450     #   let keys = pkgs.writers.writePython3Bin "keys" {} ''
451     #       import sys
452     #
453     #       args = sys.argv
454     #
455     #       print(args)
456     #     '';
457     #   in
458     #     "${keys}/bin/keys";
459     # authorizedKeysCommandUser = "ps";
460   };
461
462   # Open ports in the firewall.
463   networking.firewall.allowedTCPPorts = [ 22 1234 5900 6011 6021 6022 8080 53317 7236 7250 ];
464   networking.firewall.allowedUDPPorts = [ 5901 53317 7236 5353 ];
465   # Or disable the firewall altogether.
466   # networking.firewall.enable = false;
467
468   # This value determines the NixOS release from which the default
469   # settings for stateful data, like file locations and database versions
470   # on your system were taken. It‘s perfectly fine and recommended to leave
471   # this value at the release version of the first install of this system.
472   # Before changing this value read the documentation for this option
473   # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
474   system.stateVersion = "24.05"; # Did you read the comment?
475
476 }