diff --git a/flake.nix b/flake.nix index 960371e3..0c19cc2f 100644 --- a/flake.nix +++ b/flake.nix @@ -161,6 +161,10 @@ config = ./machine/pc-installer; system = "x86_64-linux"; }; + thinkrac = { + config = ./machine/thinkrac; + system = "x86_64-linux"; + }; }; containers = mapAttrs (_: container: mkSystem { diff --git a/machine/pc-installer/default.nix b/machine/pc-installer/default.nix index 2af6351d..9d81aa37 100644 --- a/machine/pc-installer/default.nix +++ b/machine/pc-installer/default.nix @@ -3,7 +3,19 @@ nixos-config, lib, ... -}: { +}: let + dependencies = + [ + nixos-config.nixosConfigurations.thinkrac.config.system.build.toplevel + nixos-config.nixosConfigurations.thinkrac.config.system.build.diskoScript + nixos-config.nixosConfigurations.thinkrac.config.system.build.diskoScript.drvPath + nixos-config.nixosConfigurations.thinkrac.pkgs.stdenv.drvPath + (nixos-config.nixosConfigurations.thinkrac.pkgs.closureInfo {rootPaths = [];}).drvPath + ] + ++ map (i: i.outPath) (builtins.filter builtins.isAttrs (builtins.attrValues pureInputs)); + + closureInfo = pkgs.closureInfo {rootPaths = dependencies;}; +in { networking.hostName = "pc-installer"; imports = [ "${nixos-config}/config" @@ -17,12 +29,24 @@ configuration.imports = [ ./graphical.nix "${nixos-config}/config/graphical/plymouth.nix" + { + nix.auto-update.specialisation = "graphical"; + } ]; }; specialisation.graphical-verbose = { configuration.imports = [ ./graphical.nix + { + nix.auto-update.specialisation = "graphical-verbose"; + } ]; }; isInstaller = true; + environment.systemPackages = [ + (pkgs.writeShellScriptBin "install-thinkrac-unattended" '' + set -eux + exec ${pkgs.disko}/bin/disko-install --flake "${nixos-config}#thinkrac" --disk main "${nixos-config.nixosConfigurations.thinkrac.config.disko.devices.disk.main.device}" + '') + ]; } diff --git a/machine/pc-installer/graphical.nix b/machine/pc-installer/graphical.nix index 18ecf5a9..c995f285 100644 --- a/machine/pc-installer/graphical.nix +++ b/machine/pc-installer/graphical.nix @@ -3,7 +3,6 @@ nixos-config, ... }: { - nix.auto-update.specialisation = "graphical"; imports = [ "${nixos-config}/config/graphical.nix" ]; diff --git a/machine/thinkrac/default.nix b/machine/thinkrac/default.nix new file mode 100644 index 00000000..caa49438 --- /dev/null +++ b/machine/thinkrac/default.nix @@ -0,0 +1,24 @@ +{ + config, + nixos-config, + lib, + ... +}: { + networking.hostName = "thinkrac"; + imports = [ + "${nixos-config}/config" + ./disko.nix + ./hardware.nix + "${nixos-config}/config/networkmanager.nix" + "${nixos-config}/config/graphical.nix" + ]; + system.stateVersion = "24.11"; + specialisation.quiet = { + configuration.imports = [ + "${nixos-config}/config/graphical/plymouth.nix" + { + nix.auto-update.specialisation = "quiet"; + } + ]; + }; +} diff --git a/machine/thinkrac/disko.nix b/machine/thinkrac/disko.nix new file mode 100644 index 00000000..e5941f83 --- /dev/null +++ b/machine/thinkrac/disko.nix @@ -0,0 +1,63 @@ +{ + disko.devices = { + disk = { + main = { + type = "disk"; + device = "/dev/disk/by-id/nvme-eui.002538b931b01f46"; + content = { + type = "gpt"; + partitions = { + ESP = { + priority = 1; + name = "ESP"; + start = "1M"; + end = "1024M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = ["umask=0077"]; + }; + }; + root = { + end = "-24G"; + content = { + type = "btrfs"; + extraArgs = ["-f"]; # Override existing partition + # Subvolumes must set a mountpoint in order to be mounted, + # unless their parent is mounted + subvolumes = { + # Subvolume name is different from mountpoint + "/root" = { + mountOptions = ["compress=zstd"]; + mountpoint = "/"; + }; + # Subvolume name is the same as the mountpoint + "/persistent" = { + mountOptions = ["compress=zstd"]; + mountpoint = "/persistent"; + }; + # Parent is not mounted so the mountpoint must be set + "/nix" = { + mountOptions = ["compress=zstd" "noatime"]; + mountpoint = "/nix"; + }; + }; + mountpoint = "/partition-root"; + }; + }; + swap = { + size = "100%"; + content = { + type = "swap"; + discardPolicy = "both"; + resumeDevice = true; # resume from hiberation from this device + }; + }; + }; + }; + }; + }; + }; +} diff --git a/machine/thinkrac/hardware.nix b/machine/thinkrac/hardware.nix new file mode 100644 index 00000000..199ff850 --- /dev/null +++ b/machine/thinkrac/hardware.nix @@ -0,0 +1,53 @@ +{ + modulesPath, + nixos-hardware, + ... +}: { + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + nixos-hardware.nixosModules.lenovo-thinkpad-t470s + nixos-hardware.nixosModules.common-cpu-intel + nixos-hardware.nixosModules.common-gpu-intel + nixos-hardware.nixosModules.common-pc-laptop-ssd + ]; + hardware.cpu.intel.updateMicrocode = true; + boot.initrd.availableKernelModules = ["xhci_pci" "nvme" "usb_storage" "sd_mod"]; + boot.initrd.kernelModules = []; + boot.kernelModules = ["kvm-intel"]; + boot.extraModulePackages = []; + nix.settings.cores = 4; + # use the lowest frequency possible, to save power + powerManagement.cpuFreqGovernor = "powersave"; + # lm_sensors who cares + environment.etc."sysconfig/lm_sensors".text = '' + # Generated by sensors-detect on Tue Aug 7 10:54:09 2018 + # This file is sourced by /etc/init.d/lm_sensors and defines the modules to + # be loaded/unloaded. + # + # The format of this file is a shell script that simply defines variables: + # HWMON_MODULES for hardware monitoring driver modules, and optionally + # BUS_MODULES for any required bus driver module (for example for I2C or SPI). + + HWMON_MODULES="coretemp" + ''; + services.thermald.enable = true; + boot.extraModprobeConfig = '' + # enable power savings mode of snd_hda_intel + options snd-hda-intel power_save=1 power_save_controller=y + # enable power savings mode of igpu, enable framebuffer compression, downclock the LVDS connection + options i915 i915_enable_rc6=7 i915_enable_fbc=1 lvds_downclock=1 + # automatically suspend USB devices + options usbcore autosuspend=2 + # Fan control for thinkpads + options thinkpad_acpi fan_control=1 + options zfs zfs_arc_max=4294967296 + ''; + boot.kernel.sysctl = { + # Probably unnecessary + "kernel.nmi_watchdog" = "0"; + "vm.laptop_mode" = "5"; + # The kernel flusher threads will periodically wake up and write `old' data out to disk. This + # tunable expresses the interval between those wakeups, in 100'ths of a second (Default is 500). + "vm.dirty_writeback_centisecs" = "1500"; + }; +}