Refactor configuration.nix into modules

This commit is contained in:
Tyler Beckman 2024-11-22 14:14:54 -07:00
parent 371cf13fc4
commit 662927c774
Signed by: Ty
GPG key ID: 2813440C772555A4
18 changed files with 386 additions and 3 deletions

View file

@ -49,9 +49,7 @@
system = "x86_64-linux";
modules = [
# Import legacy configuration
./configuration.nix
./hosts/laptop
# Home manager
home-manager.nixosModules.home-manager

11
hosts/laptop/default.nix Normal file
View file

@ -0,0 +1,11 @@
{ ... }:
{
imports = [
./hardware-configuration.nix
./modules
];
system.stateVersion = "24.05";
nix.settings.experimental-features = [ "nix-command" "flakes" ];
}

View file

@ -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.<interface>.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;
}

View file

@ -0,0 +1,6 @@
{ ... }:
{
# Enable bluetooth
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
}

View file

@ -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;
};
}

View file

@ -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
];
}

View file

@ -0,0 +1,5 @@
{ ... }:
{
# Enable KDE Plasma 6
services.desktopManager.plasma6.enable = true;
}

View file

@ -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";
};
};
};
}

View file

@ -0,0 +1,8 @@
{ ... }:
{
# Enable wayland support for electron apps
environment.sessionVariables.NIXOS_OZONE_WL = "1";
# Enable zsh-autocomplete compatibility
environment.pathsToLink = [ "/share/zsh" ];
}

View file

@ -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;
};
}

View file

@ -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";
};
}

View file

@ -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";
};
};
}

View file

@ -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;
}

View file

@ -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"
];
}

View file

@ -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;
};
};
};
}

View file

@ -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";
};
}

View file

@ -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;
};
}

View file

@ -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";
};
};
}