]> gitweb.ps.run Git - flake_thinkpad/blob - configuration.nix
update
[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       sddm.enable = true;
133       sddm.autoLogin.relogin = true;
134       defaultSession = "xfce+i3";
135     };
136     desktopManager = {
137       plasma6.enable = true;
138     };
139     xserver = {
140       enable = true;
141       
142       displayManager = {
143         session = [
144           {
145             manage = "desktop";
146             name = "plasma-i3wm";
147             start = "KDEWM=${pkgs.i3}/bin/i3 /run/current-system/sw/bin/startplasma-x11";
148           }
149         ];
150       };
151
152       desktopManager = {
153         xterm.enable = false;
154         xfce = {
155           enable = true;
156           noDesktop = true;
157           enableXfwm = false;
158         };
159       };
160       windowManager.i3.enable = true;
161       # windowManager.awesome.enable = true;
162       # windowManager.herbstluftwm.enable = true;
163
164       xkb = {
165         layout = "de";
166         variant = "nodeadkeys";
167         options = "caps:ctrl_modifier";
168       };
169       excludePackages = [ pkgs.xterm ];
170       videoDrivers = ["amdgpu"];
171       # libinput.enable = true;
172     };
173   };
174
175   systemd.user.services.plasma-kwin_x11.enable = false;
176
177   services.autorandr = {
178     enable = true;
179     matchEdid = true;
180     hooks = {
181       postswitch = {
182         "set-wallpaper" = "set-wallpaper";
183       };
184     };
185   };
186   
187   services.syncthing = {
188     enable = true;
189     user = "ps";
190     dataDir = "/home/ps/sync";
191     configDir = "/home/ps/.config/syncthing";
192   };
193   
194   # services.auto-cpufreq.enable = true;
195   services.auto-cpufreq.settings = {
196     battery = {
197        governor = "powersave";
198        turbo = "never";
199     };
200     charger = {
201        governor = "performance";
202        turbo = "auto";
203     };
204   };
205
206   # services.tlp = {
207   #   enable = true;
208   #   settings = {
209   #     CPU_SCALING_GOVERNOR_ON_AC = "performance";
210   #     CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
211   #
212   #     CPU_ENERGY_PERF_POLICY_ON_AC = "balance_performance";
213   #     CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
214   #
215   #     PLATFORM_PROFILE_ON_AC = "balanced";
216   #     PLATFORM_PROFILE_ON_BAT = "low-power";
217   #
218   #     CPU_BOOST_ON_AC = "1";
219   #     CPU_BOOST_ON_BAT = "0";
220   #
221   #     AMDGPU_ABM_LEVEL_ON_AC = "0";
222   #     AMDGPU_ABM_LEVEL_ON_BAT = "3";
223   #
224   #     CPU_MIN_PERF_ON_AC = 0;
225   #     CPU_MAX_PERF_ON_AC = 100;
226   #     CPU_MIN_PERF_ON_BAT = 0;
227   #     CPU_MAX_PERF_ON_BAT = 20;
228   #
229   #     # START_CHARGE_THRESH_BAT0 = 40; # 40 and below it starts to charge
230   #     STOP_CHARGE_THRESH_BAT0 = 90; # 85 and above it stops charging
231   #   };
232   # };
233
234   services.udev.extraRules = ''
235     KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{serial}=="*vial:f64c2b3c*", MODE="0660", GROUP="users", TAG+="uaccess", TAG+="udev-acl"
236   '';
237
238   # OpenGL
239   hardware = {
240     graphics = {
241         enable = true;
242         enable32Bit = true;
243         extraPackages = with pkgs; [
244           rocmPackages.clr.icd
245           mesa.opencl
246           amf
247         ];
248     };
249
250     amdgpu.amdvlk = {
251         enable = true;
252         support32Bit.enable = true;
253     };
254   };
255
256   # services.logind = {
257   #   extraConfig = "HandlePowerKey=suspend";
258   #   lidSwitch = "suspend";
259   # }; 
260
261   # Configure console keymap
262   console.keyMap = "de-latin1-nodeadkeys";
263
264   # Enable CUPS to print documents.
265   services.printing.enable = true;
266   services.printing.drivers = [ pkgs.gutenprint ];
267
268   # Enable scanners
269   hardware.sane.enable = true;
270   hardware.sane.extraBackends = [ pkgs.hplipWithPlugin pkgs.sane-airscan ];
271   services.avahi.enable = true;
272   services.avahi.nssmdns4 = true;
273   services.avahi.reflector = true;
274   services.udev.packages = [ pkgs.sane-airscan ];
275
276   # Enable Bluetooth
277   hardware.bluetooth.enable = true;
278   hardware.bluetooth.powerOnBoot = false;
279   # services.blueman.enable = true;
280
281   # Enable sound with pipewire.
282   services.pulseaudio.enable = false;
283   security.rtkit.enable = true;
284   services.pipewire = {
285     enable = true;
286     alsa.enable = true;
287     alsa.support32Bit = true;
288     pulse.enable = true;
289     # If you want to use JACK applications, uncomment this
290     #jack.enable = true;
291
292     # use the example session manager (no others are packaged yet so this is enabled by default,
293     # no need to redefine it in your config for now)
294     #media-session.enable = true;
295   };
296   services.jack = {
297     jackd.enable = true;
298   };
299
300   # Enable touchpad support (enabled default in most desktopManager).
301   # services.libinput.touchpad = {
302   #   naturalScrolling = false;
303   # };
304
305   # Define a user account. Don't forget to set a password with ‘passwd’.
306   users.groups.ssh = {};
307   users.users = {
308     ps = {
309       isNormalUser = true;
310       description = "Patrick";
311       shell = pkgs.bash;
312       extraGroups = [ "networkmanager" "wheel" "dialout" "jackaudio" "lp" "incus-admin" ];
313     };
314     # sshd = {
315     #   isSystemUser = true;
316     #   packages = [
317     #     pkgs.python3
318     #   ];
319     #   group = "ssh";
320     # };
321     chirp = {
322       isSystemUser = true;
323       packages = [
324         pkgs.python3
325       ];
326       group = "ssh";
327       shell = pkgs.bash;
328       initialPassword = "chirp";
329     };
330   };
331   
332   security.polkit.enable = true;
333   security.sudo.wheelNeedsPassword = false;
334
335   home-manager = {
336     backupFileExtension = "backup";
337     extraSpecialArgs = {
338       inherit inputs;
339       inherit wallpaper;
340     };
341     users = {
342       "ps" = import ./home-ps.nix;
343       "root" = { home.stateVersion = "24.05"; };
344     };
345     sharedModules = [
346       (import ./home-common.nix)
347     ];
348   };
349
350   # Enable automatic login for the user.
351   # services.displayManager.autoLogin.enable = true;
352   # services.displayManager.autoLogin.user = "ps";
353   # services.getty.autologinUser = "ps";
354
355   # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229
356   # systemd.services."getty@tty1".enable = false;
357   # systemd.services."autovt@tty1".enable = false;
358
359   # Allow unfree packages
360   nixpkgs.config.allowUnfree = true;
361
362
363   environment.variables = {
364     RUSTICL_ENABLE = "radeonsi";
365   };
366   # List packages installed in system profile. To search, run:
367   # $ nix search wget
368   environment.systemPackages = with pkgs; [
369     args.inputs.zls.inputs.zig-overlay.packages.${pkgs.system}.master
370     args.inputs.zls.packages.${pkgs.system}.zls
371     args.inputs.psch-flakes.packages.${pkgs.system}.resetmsmice
372     args.inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.zuban
373     vim wget file git kitty i3 gdb
374     mosh
375     cmake
376     entr
377     asciinema asciinema-agg
378     shellify
379     deno
380     typst
381     jdt-language-server
382
383     scrcpy
384
385     xsel
386     xcwd
387
388     pinta
389     mupdf
390     davinci-resolve
391
392     pavucontrol
393     syncthingtray
394     # xfce plugins
395     xfce.xfce4-panel
396     xfce.xfce4-pulseaudio-plugin
397     # xfce.xfce4-verve-plugin
398     xfce.xfce4-notes-plugin
399     # xfce.xfce4-timer-plugin
400     # xfce.xfce4-windowck-plugin
401     xfce.thunar-archive-plugin
402     # xfce.xfce4-i3-workspaces-plugin
403     # xfce.xfce4-xkb-plugin
404     xfce.xfce4-whiskermenu-plugin
405
406   ];
407
408   programs.xfconf.enable = true;
409   programs.nix-ld.enable = true;
410
411   services.fwupd.enable = true;
412
413   # Some programs need SUID wrappers, can be configured further or are
414   # started in user sessions.
415   # programs.mtr.enable = true;
416   # programs.gnupg.agent = {
417   #   enable = true;
418   #   enableSSHSupport = true;
419   # };
420
421   # List services that you want to enable:
422
423   # Enable the OpenSSH daemon.
424   services.openssh = {
425     enable = true;
426     ports = [ 22 ];
427     # settings = {
428     #   PasswordAuthentication = false;
429     #   PermitRootLogin = "no";
430     # };
431     # authorizedKeysCommand =
432     #   let keys = pkgs.writers.writePython3Bin "keys" {} ''
433     #       import sys
434     #
435     #       args = sys.argv
436     #
437     #       print(args)
438     #     '';
439     #   in
440     #     "${keys}/bin/keys";
441     # authorizedKeysCommandUser = "ps";
442   };
443
444   # Open ports in the firewall.
445   networking.firewall.allowedTCPPorts = [ 22 1234 5900 6011 6021 6022 8080 53317 7236 7250 ];
446   networking.firewall.allowedUDPPorts = [ 5901 53317 7236 5353 ];
447   # Or disable the firewall altogether.
448   # networking.firewall.enable = false;
449
450   # This value determines the NixOS release from which the default
451   # settings for stateful data, like file locations and database versions
452   # on your system were taken. It‘s perfectly fine and recommended to leave
453   # this value at the release version of the first install of this system.
454   # Before changing this value read the documentation for this option
455   # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
456   system.stateVersion = "24.05"; # Did you read the comment?
457
458 }