Refactor configuration.nix into modules

This commit is contained in:
Tyler Beckman 2024-11-22 14:14:54 -07:00
parent 371cf13fc4
commit f3724b07f9
Signed by: Ty
GPG key ID: 2813440C772555A4
19 changed files with 345 additions and 311 deletions

View file

@ -1,308 +0,0 @@
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running nixos-help).
{ pkgs, inputs, system, lib, ... }:
{
imports = [
./hardware-configuration.nix
inputs.sddm-sugar-candy-nix.nixosModules.default
];
nixpkgs.overlays = [
inputs.sddm-sugar-candy-nix.overlays.default
];
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";
};
};
# Bootloader.
boot = {
loader = {
grub = {
enable = true;
useOSProber = false;
devices = [ "nodev" ];
efiSupport = true;
extraEntries = ''
menuentry "Poweroff" {
halt
}
menuentry "Reboot" {
reboot
}
'';
theme = inputs.nixos-grub-themes.packages."${system}".hyperfluent;
};
efi.canTouchEfiVariables = true;
};
plymouth = {
enable = true;
theme = "bgrt";
};
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"
];
initrd.systemd.enable = true;
};
networking.hostName = "ty-nixos"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
# Enable networking
networking.networkmanager.enable = true;
# Set your time zone.
time.timeZone = "America/Denver";
# Select internationalisation properties.
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";
};
# Enable the X11 windowing system.
# You can disable this if you're only using the Wayland session.
services.xserver.enable = false;
# Configure keymap in X11
services.xserver.xkb = {
layout = "us";
variant = "";
};
# Tailscale
services.tailscale = {
enable = true;
useRoutingFeatures = "both";
openFirewall = true;
};
# Enable CUPS to print documents.
services.printing.enable = true;
# Enable sound with pipewire.
hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
# If you want to use JACK applications, uncomment this
#jack.enable = true;
# use the example session manager (no others are packaged yet so this is enabled by default,
# no need to redefine it in your config for now)
#media-session.enable = true;
};
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
users.mutableUsers = false;
users.defaultUserShell = pkgs.zsh;
users.users.ty = {
isNormalUser = true;
shell = pkgs.zsh;
description = "Tyler Beckman";
extraGroups = [ "networkmanager" "wheel" ];
hashedPassword = "$y$j9T$XCQtsX/NObNFzrYu7JcJe/$HHgvh4Re6UjKvxMz.XuHw7dwNecnMP8je.4AHUjHnsB";
};
# Install firefox.
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;
# Experimental prefs
"image.jxl.enabled" = true;
# Security
"security.pki.certificate_transparency.mode" = true;
};
preferencesStatus = "locked";
};
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# List packages installed in system profile. To search, run:
environment.systemPackages = with pkgs; [
# Basic system packages
wget
curl
neovim
git
jujutsu
# SDDM Cursor theme
vimix-cursors
];
programs.zsh.enable = true;
# Env vars
environment.sessionVariables.NIXOS_OZONE_WL = "1";
environment.pathsToLink = [ "/share/zsh" ];
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
networking.firewall.enable = true;
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. Its perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "24.05"; # Did you read the comment?
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Enable bluetooth
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
# KDE + SDDM Configuration
services.desktopManager.plasma6 = {
enable = true;
# enableQt5Integration = true;
};
services.displayManager.sddm = {
enable = true;
wayland = {
enable = true;
compositor = "kwin";
};
enableHidpi = true;
package = lib.mkForce pkgs.libsForQt5.sddm;
extraPackages = lib.mkForce [
pkgs.libsForQt5.qtbase
pkgs.libsForQt5.qt5.qtgraphicaleffects
];
settings = {
Theme = {
CursorTheme = "Vimix-cursors";
};
};
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";
};
};
};
# Nvidia config
hardware.graphics.enable = true;
services.xserver.videoDrivers = ["nvidia" "amdgpu"];
hardware.nvidia = {
modesetting.enable = true;
# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead
# of just the bare essentials.
powerManagement.enable = false;
# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = true;
# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of
# supported GPUs is at:
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
open = false;
nvidiaSettings = true;
prime = {
amdgpuBusId = "PCI:4:0:0";
nvidiaBusId = "PCI:1:0:0";
offload = {
enable = true;
enableOffloadCmd = true;
};
};
};
# Fonts
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" ];
})
];
enableDefaultPackages = false;
};
# Allow electron 27.3.11 (for logseq)
nixpkgs.config.permittedInsecurePackages = [
"electron-27.3.11"
];
}

View file

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