From 662927c774ef02608822fc1ae2cb917225c609e7 Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Fri, 22 Nov 2024 14:14:54 -0700 Subject: [PATCH] Refactor configuration.nix into modules --- flake.nix | 4 +- hosts/laptop/default.nix | 11 +++++ hosts/laptop/hardware-configuration.nix | 41 ++++++++++++++++++ hosts/laptop/modules/bluetooth.nix | 6 +++ hosts/laptop/modules/bootloader.nix | 48 +++++++++++++++++++++ hosts/laptop/modules/default.nix | 18 ++++++++ hosts/laptop/modules/desktop.nix | 5 +++ hosts/laptop/modules/display.nix | 55 +++++++++++++++++++++++++ hosts/laptop/modules/environment.nix | 8 ++++ hosts/laptop/modules/fonts.nix | 20 +++++++++ hosts/laptop/modules/locale.nix | 19 +++++++++ hosts/laptop/modules/mounts.nix | 14 +++++++ hosts/laptop/modules/networking.nix | 20 +++++++++ hosts/laptop/modules/nixpkgs.nix | 16 +++++++ hosts/laptop/modules/nvidia.nix | 30 ++++++++++++++ hosts/laptop/modules/packages.nix | 39 ++++++++++++++++++ hosts/laptop/modules/sound.nix | 13 ++++++ hosts/laptop/modules/users.nix | 22 ++++++++++ 18 files changed, 386 insertions(+), 3 deletions(-) create mode 100644 hosts/laptop/default.nix create mode 100755 hosts/laptop/hardware-configuration.nix create mode 100644 hosts/laptop/modules/bluetooth.nix create mode 100644 hosts/laptop/modules/bootloader.nix create mode 100644 hosts/laptop/modules/default.nix create mode 100644 hosts/laptop/modules/desktop.nix create mode 100644 hosts/laptop/modules/display.nix create mode 100644 hosts/laptop/modules/environment.nix create mode 100644 hosts/laptop/modules/fonts.nix create mode 100644 hosts/laptop/modules/locale.nix create mode 100644 hosts/laptop/modules/mounts.nix create mode 100644 hosts/laptop/modules/networking.nix create mode 100644 hosts/laptop/modules/nixpkgs.nix create mode 100644 hosts/laptop/modules/nvidia.nix create mode 100644 hosts/laptop/modules/packages.nix create mode 100644 hosts/laptop/modules/sound.nix create mode 100644 hosts/laptop/modules/users.nix diff --git a/flake.nix b/flake.nix index 724e72e..78a4f40 100755 --- a/flake.nix +++ b/flake.nix @@ -49,9 +49,7 @@ system = "x86_64-linux"; modules = [ - - # Import legacy configuration - ./configuration.nix + ./hosts/laptop # Home manager home-manager.nixosModules.home-manager diff --git a/hosts/laptop/default.nix b/hosts/laptop/default.nix new file mode 100644 index 0000000..257f0a4 --- /dev/null +++ b/hosts/laptop/default.nix @@ -0,0 +1,11 @@ +{ ... }: +{ + imports = [ + ./hardware-configuration.nix + ./modules + ]; + + system.stateVersion = "24.05"; + + nix.settings.experimental-features = [ "nix-command" "flakes" ]; +} \ No newline at end of file diff --git a/hosts/laptop/hardware-configuration.nix b/hosts/laptop/hardware-configuration.nix new file mode 100755 index 0000000..fe8333c --- /dev/null +++ b/hosts/laptop/hardware-configuration.nix @@ -0,0 +1,41 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/f9bea90d-1dca-42d5-8297-0b5be85190a1"; + fsType = "btrfs"; + options = [ "subvol=@" ]; + }; + + boot.initrd.luks.devices."luks-16827abe-333c-43d7-b1b0-7d0df0b5931f".device = "/dev/disk/by-uuid/16827abe-333c-43d7-b1b0-7d0df0b5931f"; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/B22B-9CCA"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; + }; + + swapDevices = [ ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp2s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/laptop/modules/bluetooth.nix b/hosts/laptop/modules/bluetooth.nix new file mode 100644 index 0000000..1c756c4 --- /dev/null +++ b/hosts/laptop/modules/bluetooth.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + # Enable bluetooth + hardware.bluetooth.enable = true; + hardware.bluetooth.powerOnBoot = true; +} \ No newline at end of file diff --git a/hosts/laptop/modules/bootloader.nix b/hosts/laptop/modules/bootloader.nix new file mode 100644 index 0000000..8b3ca12 --- /dev/null +++ b/hosts/laptop/modules/bootloader.nix @@ -0,0 +1,48 @@ +{ inputs, system, ... }: +{ + boot = { + loader = { + # Configure GRUB bootloader + grub = { + enable = true; + useOSProber = false; # Don't show other OS-es, the main grub install handles that + devices = [ "nodev" ]; # Assume grub is already installed properly + efiSupport = true; + # Add extra power options to bootloader + extraEntries = '' + menuentry "Poweroff" { + halt + } + menuentry "Reboot" { + reboot + } + ''; + # Use NixOS hyperfluent theme for nicer-looking os-themed bootloader + theme = inputs.nixos-grub-themes.packages."${system}".hyperfluent; + }; + efi.canTouchEfiVariables = true; + }; + + # Enable plymouth for a nicer boot sequence + plymouth = { + enable = true; + theme = "bgrt"; # Emulates windows-style boot animation (vendor + os + spinner) + }; + + # Configure silent boot (no logging displayed) + consoleLogLevel = 0; + initrd.verbose = false; + kernelParams = [ + "quiet" + "splash" + "boot.shell_on_fail" + "loglevel=3" + "rd.systemd.show_status=false" + "rd.udev.log_level=3" + "udev.log_priority=3" + ]; + + # Enable systemd early + initrd.systemd.enable = true; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/default.nix b/hosts/laptop/modules/default.nix new file mode 100644 index 0000000..b0379d0 --- /dev/null +++ b/hosts/laptop/modules/default.nix @@ -0,0 +1,18 @@ +{ ... }: +{ + imports = [ + ./bluetooth.nix + ./bootloader.nix + ./desktop.nix + ./display.nix + ./environment.nix + ./fonts.nix + ./networking.nix + ./mounts.nix + ./nixpkgs.nix + ./nvidia.nix + ./packages.nix + ./sound.nix + ./users.nix + ]; +} \ No newline at end of file diff --git a/hosts/laptop/modules/desktop.nix b/hosts/laptop/modules/desktop.nix new file mode 100644 index 0000000..1be3906 --- /dev/null +++ b/hosts/laptop/modules/desktop.nix @@ -0,0 +1,5 @@ +{ ... }: +{ + # Enable KDE Plasma 6 + services.desktopManager.plasma6.enable = true; +} \ No newline at end of file diff --git a/hosts/laptop/modules/display.nix b/hosts/laptop/modules/display.nix new file mode 100644 index 0000000..2d21716 --- /dev/null +++ b/hosts/laptop/modules/display.nix @@ -0,0 +1,55 @@ +{ pkgs, lib, inputs, ... }: +{ + imports = [ + inputs.sddm-sugar-candy-nix.nixosModules.default + ]; + + # Disable X11 + services.xserver = { + enable = false; + # TODO: Is this necessary without X11? It was added by NixOS installer + xkb = { + layout = "us"; + variant = ""; + }; + }; + + # Enable SDDM w/ Sugar Candy theme + services.displayManager.sddm = { + enable = true; + # Use kwin for wayland support + wayland = { + enable = true; + compositor = "kwin"; + }; + # Enable high resolution support + enableHidpi = true; + # Qt5 compatibility to allow Sugar Candy theme + package = lib.mkForce pkgs.libsForQt5.sddm; + extraPackages = lib.mkForce [ + pkgs.libsForQt5.qtbase + pkgs.libsForQt5.qt5.qtgraphicaleffects + ]; + + # Use same cursor theme as plasma + settings = { + Theme = { + CursorTheme = "Vimix-cursors"; + }; + }; + + # Enable sugar candy theme via sddm-sugar-candy-nix flake + sugarCandyNix = { + enable = true; + settings = { + Background = "${pkgs.kdePackages.plasma-workspace-wallpapers}/share/wallpapers/Patak/contents/images_dark/3840x2160.png"; + ScreenWidth = 3072; + ScreenHeight = 1920; + FormPosition = "left"; + HaveFormBackground = true; + PartialBlur = true; + FontSize = "12"; + }; + }; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/environment.nix b/hosts/laptop/modules/environment.nix new file mode 100644 index 0000000..d01b660 --- /dev/null +++ b/hosts/laptop/modules/environment.nix @@ -0,0 +1,8 @@ +{ ... }: +{ + # Enable wayland support for electron apps + environment.sessionVariables.NIXOS_OZONE_WL = "1"; + + # Enable zsh-autocomplete compatibility + environment.pathsToLink = [ "/share/zsh" ]; +} \ No newline at end of file diff --git a/hosts/laptop/modules/fonts.nix b/hosts/laptop/modules/fonts.nix new file mode 100644 index 0000000..c28b833 --- /dev/null +++ b/hosts/laptop/modules/fonts.nix @@ -0,0 +1,20 @@ +{ pkgs, ... }: +{ + fonts = { + packages = with pkgs; [ + symbola + noto-fonts + noto-fonts-cjk-sans + noto-fonts-emoji + fira-code + fira-code-symbols + jetbrains-mono + # Nerd fonts + (nerdfonts.override { + fonts = [ "FiraCode" "JetBrainsMono" ]; + }) + ]; + # Disable any fonts not defined above + enableDefaultPackages = false; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/locale.nix b/hosts/laptop/modules/locale.nix new file mode 100644 index 0000000..701bc6d --- /dev/null +++ b/hosts/laptop/modules/locale.nix @@ -0,0 +1,19 @@ +{ ... }: +{ + # Set timezone to MST + time.timeZone = "America/Denver"; + + # Set english UTF-8 locale + i18n.defaultLocale = "en_US.UTF-8"; + i18n.extraLocaleSettings = { + LC_ADDRESS = "en_US.UTF-8"; + LC_IDENTIFICATION = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_NAME = "en_US.UTF-8"; + LC_NUMERIC = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_TELEPHONE = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/mounts.nix b/hosts/laptop/modules/mounts.nix new file mode 100644 index 0000000..685865e --- /dev/null +++ b/hosts/laptop/modules/mounts.nix @@ -0,0 +1,14 @@ +{ ... }: +{ + # Mount arch linux partition (encrypted with keyfile at NixOS /root/keyfiles/arch.key) + fileSystems."/mnt/arch" = { + device = "/dev/mapper/arch"; + fsType = "btrfs"; + encrypted = { + enable = true; + blkDev = "/dev/disk/by-uuid/60b6f21d-85b2-4d4b-90f4-38612138eeec"; + keyFile = "/sysroot/root/keyfiles/arch.key"; + label = "arch"; + }; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/networking.nix b/hosts/laptop/modules/networking.nix new file mode 100644 index 0000000..3b3a724 --- /dev/null +++ b/hosts/laptop/modules/networking.nix @@ -0,0 +1,20 @@ +{ ... }: +{ + networking.hostName = "ty-nixos"; + + # Enable firewall + networking.firewall.enable = true; + + # Enable NetworkManager + networking.networkmanager.enable = true; + + # Tailscale overlay network configuration + services.tailscale = { + enable = true; + useRoutingFeatures = "both"; + openFirewall = true; + }; + + # Network printing via CUPS + services.printing.enable = true; +} \ No newline at end of file diff --git a/hosts/laptop/modules/nixpkgs.nix b/hosts/laptop/modules/nixpkgs.nix new file mode 100644 index 0000000..e31bfc0 --- /dev/null +++ b/hosts/laptop/modules/nixpkgs.nix @@ -0,0 +1,16 @@ +{ inputs, ... }: +{ + # Allow closed source packages (like nvida drivers or mozilla firefox binaries) + nixpkgs.config.allowUnfree = true; + + # Add overlays + nixpkgs.overlays = [ + # Used for Sugar Candy theme in SDDM + inputs.sddm-sugar-candy-nix.overlays.default + ]; + + # Allow electron 27.3.11 (for logseq) + nixpkgs.config.permittedInsecurePackages = [ + "electron-27.3.11" + ]; +} \ No newline at end of file diff --git a/hosts/laptop/modules/nvidia.nix b/hosts/laptop/modules/nvidia.nix new file mode 100644 index 0000000..ab7a9ed --- /dev/null +++ b/hosts/laptop/modules/nvidia.nix @@ -0,0 +1,30 @@ +{ ... }: +{ + # Configure dual-gpu AMD+Nvidia + hardware.graphics.enable = true; + services.xserver.videoDrivers = ["nvidia" "amdgpu"]; + hardware.nvidia = { + modesetting.enable = true; + + # Experimental nvidia power management + powerManagement.enable = false; + + # Experimentally turn off Nvidia GPU when not in use + powerManagement.finegrained = true; + + open = false; # Open source module is still very much beta + + nvidiaSettings = true; + + # Configure dual-gpu offloading + prime = { + amdgpuBusId = "PCI:4:0:0"; + nvidiaBusId = "PCI:1:0:0"; + + offload = { + enable = true; + enableOffloadCmd = true; + }; + }; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/packages.nix b/hosts/laptop/modules/packages.nix new file mode 100644 index 0000000..62123a2 --- /dev/null +++ b/hosts/laptop/modules/packages.nix @@ -0,0 +1,39 @@ +{ pkgs, ... }: +{ + # Install system packages + environment.systemPackages = with pkgs; [ + # Basic necessities + wget + curl + neovim + # VCS + git + jujutsu + # Misc + vimix-cursors # SDDM Cursor theme + ]; + + # Install zsh + programs.zsh.enable = true; + + # Manage default firefox web browser install + programs.firefox = { + enable = true; + preferences = { + # Disable bullshit + "browser.ml.chat.enabled" = false; + "browser.aboutConfig.showWarning" = false; + "extensions.pocket.enabled" = false; + "browser.newtabpage.activity-stream.showSponsored" = false; + "browser.newtabpage.activity-stream.showSponsoredTopSites" = false; + "browser.newtabpage.activity-stream.feeds.section.topstories" = false; + "browser.newtabpage.activity-stream.feeds.system.topstories" = false; + "browser.urlbar.suggest.quicksuggest.sponsored" = false; + # Spite chrome + "image.jxl.enabled" = true; + # Security + "security.pki.certificate_transparency.mode" = true; + }; + preferencesStatus = "locked"; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/sound.nix b/hosts/laptop/modules/sound.nix new file mode 100644 index 0000000..ba9c1ed --- /dev/null +++ b/hosts/laptop/modules/sound.nix @@ -0,0 +1,13 @@ +{ ... }: +{ + # Disable pulseaudio + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; # TODO Figure out what this does + # Enable pipewire with ALSA and PulseAudio compatibility + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; +} \ No newline at end of file diff --git a/hosts/laptop/modules/users.nix b/hosts/laptop/modules/users.nix new file mode 100644 index 0000000..4eab7e1 --- /dev/null +++ b/hosts/laptop/modules/users.nix @@ -0,0 +1,22 @@ +{ pkgs, ... }: +{ + # Make users fully declarative + users.mutableUsers = false; + + # Set default shell to Zsh + users.defaultUserShell = pkgs.zsh; + users.users = { + # Main ty user + ty = { + isNormalUser = true; + useDefaultShell = true; + description = "Tyler Beckman"; + extraGroups = [ + "networkmanager" # Can manage networking + "wheel" # Can use sudo + ]; + + hashedPassword = "$y$j9T$XCQtsX/NObNFzrYu7JcJe/$HHgvh4Re6UjKvxMz.XuHw7dwNecnMP8je.4AHUjHnsB"; + }; + }; +} \ No newline at end of file