Refactor for multiple systems

First step in refactoring my Nix setup to work better for configuring
multiple machines. Broken things apart into more manageable chunks.
This commit is contained in:
Trevor Vallender 2023-06-10 12:57:11 +01:00
parent d1c7bd7cb3
commit a5a54a86b8
9 changed files with 194 additions and 146 deletions

View File

@ -19,13 +19,13 @@
outputs = inputs@{ nixpkgs, home-manager, devenv, hyprland, hyprcontrib, codeium, ... }: { outputs = inputs@{ nixpkgs, home-manager, devenv, hyprland, hyprcontrib, codeium, ... }: {
nixosConfigurations = { nixosConfigurations = {
ritchie = nixpkgs.lib.nixosSystem { ritchie = nixpkgs.lib.nixosSystem { # My work machine
system = "x86_64-linux"; system = "x86_64-linux";
specialArgs.inputs = inputs; specialArgs.inputs = inputs;
modules = [ modules = [
./system/configuration.nix ./system/ritchie.nix
hyprland.nixosModules.default hyprland.nixosModules.default
{ programs.hyprland.enable = true; } { programs.hyprland.enable = true; }
@ -34,12 +34,32 @@
home-manager = { home-manager = {
useGlobalPkgs = true; useGlobalPkgs = true;
useUserPackages = true; useUserPackages = true;
users.tsv = import users/tsv/home.nix; users.tsv = import users/tsv/ritchie.nix;
users.foxsoft = import users/foxsoft/home.nix; users.foxsoft = import users/foxsoft/home.nix;
}; };
} }
]; ];
}; };
thompson = nixpkgs.lib.nixosSystem { # My personal laptop
system = "x86_64-linux";
specialArgs.inputs = inputs;
modules = [
./system/thompson.nix
hyprland.nixosModules.default
{ programs.hyprland.enable = true; }
home-manager.nixosModules.home-manager {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.tsv = import users/tsv/thompson.nix;
};
}
];
};
}; };
}; };
} }

29
system/filesystem.nix Normal file
View File

@ -0,0 +1,29 @@
# General filesystem setup used by my main machines.
{ config, ... }:
{
boot.initrd.luks.devices = {
root = {
device = "/dev/disk/by-label/CRYPT";
preLVM = true;
allowDiscards = true;
};
};
fileSystems."/" =
{ device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-label/BOOT";
fsType = "vfat";
};
swapDevices = [
{
device = "/dev/mapper/vg-swap";
}
];
}

View File

@ -1,6 +1,3 @@
# 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, ... }: { config, lib, pkgs, modulesPath, ... }:
{ {
@ -12,40 +9,25 @@
boot.initrd.kernelModules = [ "dm-snapshot" ]; boot.initrd.kernelModules = [ "dm-snapshot" ];
boot.kernelModules = [ "kvm-intel" ]; boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ]; boot.extraModulePackages = [ ];
boot.initrd.luks.devices = {
root = {
device = "/dev/disk/by-label/CRYPT";
preLVM = true;
allowDiscards = true;
};
};
fileSystems."/" =
{ device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-label/BOOT";
fsType = "vfat";
};
swapDevices = [
{
device = "/dev/mapper/vg-swap";
}
];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking # 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 # (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 # 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`. # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true; networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp3s0.useDHCP = lib.mkDefault true;
# networking.interfaces.wlo1.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
# NVidia stuff
hardware.nvidia.modesetting.enable = true;
services.xserver.videoDrivers = ["nvidia" ];
hardware.opengl.enable = true;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
hardware.nvidia.prime = {
sync.enable = true;
nvidiaBusId = "PCI:1:0:0";
intelBusId = "PCI:0:2:0";
};
} }

32
system/ritchie.nix Normal file
View File

@ -0,0 +1,32 @@
{ config, pkgs, inputs, ... }:
let
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
'';
in
{
imports =
[
./shared-configuration.nix
./ritchie-hardware.nix
./filesystem.nix
];
networking.hostName = "ritchie";
users.users.foxsoft = {
isNormalUser = true;
extraGroups = [
"tmux"
];
openssh.authorizedKeys.keyFiles = [
../users/foxsoft/authorized_keys
];
};
}

View File

@ -1,26 +1,11 @@
{ config, pkgs, inputs, ... }: { config, pkgs, inputs, ... }:
let
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
'';
in
{ {
imports =
[
./hardware-configuration.nix
];
# Use the systemd-boot EFI boot loader. # Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
boot.supportedFilesystems = [ "ntfs" ]; boot.supportedFilesystems = [ "ntfs" ];
networking.hostName = "ritchie";
networking.networkmanager.enable = true; networking.networkmanager.enable = true;
i18n.defaultLocale = "en_GB.UTF-8"; i18n.defaultLocale = "en_GB.UTF-8";
@ -51,16 +36,6 @@ in
initialPassword = "password"; initialPassword = "password";
}; };
users.users.foxsoft = {
isNormalUser = true;
extraGroups = [
"tmux"
];
openssh.authorizedKeys.keyFiles = [
../users/foxsoft/authorized_keys
];
};
nix.settings.trusted-users = [ "root" "tsv" ]; nix.settings.trusted-users = [ "root" "tsv" ];
nix = { nix = {
@ -76,16 +51,6 @@ in
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.sddm.enable = true; services.xserver.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true; services.xserver.desktopManager.plasma5.enable = true;
hardware.nvidia.modesetting.enable = true;
services.xserver.videoDrivers = ["nvidia" ];
hardware.opengl.enable = true;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
hardware.nvidia.prime = {
sync.enable = true;
nvidiaBusId = "PCI:1:0:0";
intelBusId = "PCI:0:2:0";
};
hardware.bluetooth.enable = true; hardware.bluetooth.enable = true;
@ -109,7 +74,6 @@ in
environment.variables.LC_ALL = "en_GB.UTF-8"; environment.variables.LC_ALL = "en_GB.UTF-8";
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
nixpkgs.overlays = [ nixpkgs.overlays = [

View File

@ -1,6 +1,11 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
imports =
[
./packages.nix
];
home.username = "tsv"; home.username = "tsv";
home.homeDirectory = "/home/tsv"; home.homeDirectory = "/home/tsv";
@ -14,83 +19,6 @@
MOZ_ENABLE_WAYLAND = 1; MOZ_ENABLE_WAYLAND = 1;
}; };
home.packages = with pkgs; [
_1password-gui
aaxtomp3
aerc
anki
audible-cli
awscli2
awsebcli
bitwarden
bitwarden-cli
cachix
calibre
chromium
delta # Nice diffing pager for Git
docker-compose
dunst
feh
firefox
fzf
gcc
git-crypt
gitflow
gnumake
gnupg
gimp
grimblast
gtk4.dev
heroku
htop
hyprland-protocols
hyprland-share-picker
xdg-desktop-portal-hyprland
hyprpaper
imagemagick
kde-gruvbox
kitty
kitty-themes
libreoffice
lshw
microsoft-edge
nerdfonts
pandoc
(pass.withExtensions (exts: [
exts.pass-import
exts.pass-otp
]))
pavucontrol
pkg-config
polkit-kde-agent
progress
pspg
quodlibet
qutebrowser
ripgrep
ruby_3_1
rubyPackages_3_1.dip
rubyPackages_3_1.solargraph
rofi-wayland
slack
spotify
termpdfpy
thunderbird
timg
toot
unzip
usbutils
w3m
waybar
wev
wine
winetricks
wireplumber
wl-clipboard
wlr-randr
zoom-us
];
programs.tmux = { programs.tmux = {
enable = true; enable = true;
plugins = with pkgs.tmuxPlugins; [ plugins = with pkgs.tmuxPlugins; [

69
users/tsv/packages.nix Normal file
View File

@ -0,0 +1,69 @@
{ config, pkgs, ... }:
{
home.packages = with pkgs; [
aaxtomp3
aerc
anki
audible-cli
bitwarden
bitwarden-cli
cachix
calibre
chromium
delta # Nice diffing pager for Git
docker-compose
dunst
feh
firefox
fzf
gcc
git-crypt
gnumake
gnupg
gimp
grimblast
gtk4.dev
htop
hyprland-protocols
hyprland-share-picker
xdg-desktop-portal-hyprland
hyprpaper
imagemagick
kde-gruvbox
kitty
kitty-themes
lshw
nerdfonts
pandoc
(pass.withExtensions (exts: [
exts.pass-import
exts.pass-otp
]))
pavucontrol
pkg-config
polkit-kde-agent
progress
pspg
quodlibet
qutebrowser
ripgrep
ruby_3_1
rubyPackages_3_1.dip
rubyPackages_3_1.solargraph
rofi-wayland
spotify
termpdfpy
thunderbird
timg
toot
unzip
usbutils
w3m
waybar
wev
wireplumber
wl-clipboard
wlr-randr
];
}

9
users/tsv/ritchie.nix Normal file
View File

@ -0,0 +1,9 @@
{ config, pkgs, ... }:
{
imports =
[
./home.nix
./work-packages.nix
];
}

View File

@ -0,0 +1,15 @@
{ config, pkgs, ... }:
{
home.packages = with pkgs; [
_1password-gui
awscli2
awsebcli
gitflow
heroku
libreoffice
microsoft-edge
slack
zoom-us
];
}