Modularizing system configuration #3

Merged
wymiller merged 10 commits from modular into master 2024-12-27 00:27:25 -06:00
10 changed files with 178 additions and 131 deletions
Showing only changes of commit 86970a7f6c - Show all commits

13
flake.lock generated
View File

@ -28,15 +28,16 @@
]
},
"locked": {
"lastModified": 1734344598,
"narHash": "sha256-wNX3hsScqDdqKWOO87wETUEi7a/QlPVgpC/Lh5rFOuA=",
"lastModified": 1734366194,
"narHash": "sha256-vykpJ1xsdkv0j8WOVXrRFHUAdp9NXHpxdnn1F4pYgSw=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "83ecd50915a09dca928971139d3a102377a8d242",
"rev": "80b0fdf483c5d1cb75aaad909bd390d48673857f",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "release-24.11",
"repo": "home-manager",
"type": "github"
}
@ -93,11 +94,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1734323986,
"narHash": "sha256-m/lh6hYMIWDYHCAsn81CDAiXoT3gmxXI9J987W5tZrE=",
"lastModified": 1734737257,
"narHash": "sha256-GIMyMt1pkkoXdCq9un859bX6YQZ/iYtukb9R5luazLM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "394571358ce82dff7411395829aa6a3aad45b907",
"rev": "1c6e20d41d6a9c1d737945962160e8571df55daa",
"type": "github"
},
"original": {

View File

@ -5,7 +5,7 @@
nix-flatpak.url = "github:gmodena/nix-flatpak/?ref=v0.4.1";
nix-ld.url = "github:Mic92/nix-ld";
home-manager = {
url = "github:nix-community/home-manager";
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs";
};
darwin = {

View File

@ -16,16 +16,6 @@
}
]
else flatpakRemotes;
# packages = [
# "com.github.tchx84.Flatseal"
# "com.slack.Slack"
# "info.beyondallreason.bar"
# "io.dbeaver.DBeaverCommunity"
# "io.openrct2.OpenRCT2"
# "md.obsidian.Obsidian"
# "org.prismlauncher.PrismLauncher"
# "sh.cider.Cider"
# ];
packages = flatpakPackages;
update = {
auto = {

View File

@ -71,15 +71,10 @@ in {
};
wine = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable Wine support for Lutris";
};
enable = lib.mkEnableOption "Enable Wine support for Lutris";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.wineWow;
default = pkgs.wine-staging;
description = "Wine package to use with Lutris";
};
};
@ -107,10 +102,10 @@ in {
};
};
minecraft = lib.mkOption {
minecraft = {
enable = lib.mkEnableOption "Minecraft in the form of PrismLauncher, a tool for launching Minecraft";
};
ffxiv = lib.mkOption {
ffxiv = {
enable = lib.mkEnableOption "Final Fantasy XIV and it's accompanied (unofficial) launcher";
};
};
@ -145,36 +140,20 @@ in {
};
environment.systemPackages =
lib.mkIf cfg.lutris.enable (
# Base Lutris package
[cfg.lutris.package]
++
# Wine packages if enabled
(lib.optionals cfg.lutris.enable (
[cfg.lutris.package] ++
(lib.optionals cfg.lutris.wine.enable [
cfg.lutris.wine.package
pkgs.winetricks
])
++
# Proton and compatibility tools
]) ++
(lib.optionals cfg.lutris.compatibility.protonSupport [
pkgs.proton-ge-custom
])
++
# Extra compatibility tools
cfg.lutris.compatibility.extraTools
++
# User-specified extra packages
pkgs.protonup-ng
pkgs.protonup-qt
]) ++
cfg.lutris.compatibility.extraTools ++
cfg.lutris.extraPackages
)
lib.mkIf
cfg.minecraft.enable [pkgs.prismlauncher]
lib.mkIf
cfg.ffxiv.enable [pkgs.xivlauncher];
# Wine configuration
programs.wine = lib.mkIf (cfg.lutris.enable && cfg.lutris.wine.enable) {
enable = true;
package = cfg.lutris.wine.package;
};
)) ++
(lib.optionals cfg.minecraft.enable [pkgs.prismlauncher]) ++
(lib.optionals cfg.ffxiv.enable [pkgs.xivlauncher]);
};
}

View File

@ -1,42 +1,107 @@
{
pkgs,
lib,
config,
lib,
pkgs,
...
}: {
nixosModules.gpuHardware = {gpuVendor ? null, ...}: {
hardware.opengl = {
# Always enable OpenGL support
enable = true;
}:
with lib; let
cfg = config.graphics;
in {
options.graphics = {
gpuVendor = mkOption {
type = types.enum ["nvidia" "amd" "intel" "none"];
default = "none";
description = "GPU vendor to configure graphics drivers for";
};
# Dynamically select packages based on GPU vendor
extraPackages = with pkgs; (
# Base packages that are always included
[
mesa
libvdpau-va-gl
libva
libva-utils
]
# Vendor-specific packages
++ (
if gpuVendor == "intel"
then [
intel-vaapi-driver
intel-media-driver
]
else if gpuVendor == "amd"
then [
rocm-opencl-icd
]
else if gpuVendor == "nvidia"
then [
# Add Nvidia-specific packages if needed
nvidia-vaapi-driver
]
else []
)
);
enable = mkEnableOption "graphics configuration";
wayland = {
enable = mkEnableOption "Wayland support";
variableRefreshRate = mkOption {
type = types.bool;
default = false;
description = "Enable variable refresh rate (FreeSync/G-Sync) support";
};
};
vulkan = {
enable = mkEnableOption "Vulkan support";
debug = mkOption {
type = types.bool;
default = false;
description = "Enable Vulkan validation layers";
};
};
};
config = mkIf cfg.enable (mkMerge [
{
environment.systemPackages = with pkgs; [
glxinfo
vulkan-tools
mesa-demos
];
}
(mkIf (cfg.gpuVendor == "nvidia") {
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
package = config.boot.kernelPackages.nvidiaPackages.stable;
open = true;
modesetting.enable = true;
powerManagement.enable = true;
};
environment.systemPackages = with pkgs; [
nvidia-vaapi-driver
nvtopPackages.full
];
})
(mkIf (cfg.gpuVendor == "amd") {
services.xserver.videoDrivers = ["amdgpu"];
hardware.opengl.extraPackages = with pkgs; [
rocm-opencl-icd
rocm-opencl-runtime
amdvlk
];
environment.systemPackages = with pkgs; [
radeontop
];
})
(mkIf (cfg.gpuVendor == "intel") {
services.xserver.videoDrivers = ["modesetting"];
hardware.opengl.extraPackages = with pkgs; [
intel-media-driver
intel-compute-runtime
];
})
(mkIf cfg.wayland.enable {
programs.xwayland.enable = true;
environment.sessionVariables = {
MOZ_ENABLE_WAYLAND = "1";
QT_QPA_PLATFORM = "wayland";
SDL_VIDEODRIVER = "wayland";
};
})
(mkIf cfg.vulkan.enable {
environment.systemPackages = with pkgs;
[
vulkan-loader
vulkan-validation-layers
]
++ (
if cfg.vulkan.debug
then [
vulkan-tools
]
else []
);
})
]);
}

View File

@ -1,17 +1,32 @@
{
config,
lib,
pkgs,
userName,
...
}: {
}:
let flatpakPackages = [
"com.github.tchx84.Flatseal"
"com.slack.Slack"
"info.beyondallreason.bar"
"io.dbeaver.DBeaverCommunity"
"io.openrct2.OpenRCT2"
"md.obsidian.Obsidian"
"org.prismlauncher.PrismLauncher"
"sh.cider.Cider"
];
in {
imports = [
../../apps/flatpak.nix
(import ../../apps/flatpak.nix {
inherit lib pkgs flatpakPackages;
})
../../apps/gaming.nix
../../graphics
../../pwrMgmt
../../sound/pipewire.nix
../../sound/shairport.nix
../../virtualization/podman.nix
../../virtualization/hardware.nix
(config.nixosModules.gpuHardware {gpuVendor = "amd";})
];
# Enable flakes for NixOS
@ -68,8 +83,15 @@
# Enable Polkit
security.polkit.enable = true;
graphics = {
enable = true;
gpuVendor = "nvidia"; # or "amd" or "intel"
wayland.enable = true;
vulkan.enable = true;
};
# Gaming module (see ../../apps/gaming.nix)
customGaming = {
gaming = {
steam = {
enable = true;
firewall = {
@ -83,13 +105,10 @@
enable = true;
wine = {
enable = true;
package = pkgs.wine;
package = pkgs.wine-staging;
};
compatibility = {
protonSupport = true;
extraTools = with pkgs; [
proton-ge-custom
];
};
extraPackages = with pkgs; [
gamemode
@ -97,17 +116,18 @@
];
};
ffxiv.enable = true;
minecraft.enable = true;
};
# Power management (see ../../pwrMgmt/default.nix)
customPowerManagement = {
pwrMgmt = {
enable = true;
cpuFreqGovernor = "performance";
powertop.enable = false;
};
containers.podman = {
podman = {
enable = true;
extraPackages = with pkgs; [
docker-credential-helpers
@ -119,9 +139,9 @@
];
};
customNetworking = {
networking = {
firewall.enable = true;
networkManager.enable = true;
networkmanager.enable = true;
};
# Enable dconf
@ -130,6 +150,9 @@
# Add username to groups "wheel" and "video" - more may be added here later
users.users.${userName}.extraGroups = ["wheel" "video" "gamemode" "podman" "network"];
# Flatpak packages (see ../../apps/flatpak.nix)
services.flatpak.packages = flatpakPackages;
# XDG stuff
xdg = {
portal = {
@ -150,11 +173,5 @@
};
};
# Firewall stuff not allowed in common user and network creation
networking.firewall.enable = true; # VERY important, do not touch
networking.firewall.allowedTCPPorts = [];
networking.firewall.allowedUDPPorts = [];
networking.networkmanager.enable = true; # Linux tool for managing network connections
system.stateVersion = "24.05";
system.stateVersion = "24.11";
}

View File

@ -1,15 +1,14 @@
{
config,
lib,
pkgs,
...
}: let
cfg = config.customNetworking;
cfg = config.networking;
in {
options.customNetworking = {
options.networking = {
# Firewall Configuration
firewall = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = true;
description = "Enable system firewall";
@ -18,49 +17,49 @@ in {
tcpPorts = {
# Predefined, default common service ports
ssh = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open SSH service port (22)";
};
};
web = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open common web service ports (80, 443)";
};
};
smtp = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open SMTP service ports (25, 465, 587)";
};
};
imap = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open IMAP service ports (143, 993)";
};
};
mysql = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open MySQL service port (3306)";
};
};
mssql = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open Microsoft SQL Server service port (1433)";
};
};
postgres = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open Postgres service port (5432)";
@ -75,14 +74,14 @@ in {
udpPorts = {
dns = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open DNS service port (53)";
};
};
ntp = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = false;
description = "Open NTP service port (123)";
@ -97,7 +96,7 @@ in {
};
networkManager = {
enable = lib.mkOption {
enable = lib.mkEnableOption {
type = lib.types.bool;
default = true;
description = "Enable NetworkManager for network connection management";

View File

@ -1,15 +1,13 @@
{
config,
lib,
pkgs,
...
}: let
# Define a more flexible power management module
cfg = config.pwrMgnt;
cfg = config.pwrMgmt;
in {
# Define options for customizable power management
options.pwrMgnt = {
options.pwrMgmt = {
enable = lib.mkEnableOption "Custom power management configuration";
cpuFreqGovernor = lib.mkOption {
type = lib.types.enum [
"performance"
@ -21,7 +19,6 @@ in {
description = "CPU frequency scaling governor to use";
};
# PowerTop Configuration
powertop = {
enable = lib.mkEnableOption "PowerTop power management tool";
@ -32,7 +29,6 @@ in {
};
};
# Battery-specific settings (for laptops)
battery = {
enable = lib.mkEnableOption "Battery-specific power management";
@ -56,7 +52,7 @@ in {
cpuFreqGovernor = cfg.cpuFreqGovernor;
};
services.powertop.enable = cfg.powertop.enable;
environment.systemPackages = lib.mkIf cfg.powertop.enable [pkgs.powertop];
systemd.services.battery-charge-threshold = lib.mkIf cfg.battery.enable {
description = "Set battery charge thresholds";
wantedBy = ["multi-user.target"];

View File

@ -1,4 +1,4 @@
{pkgs}: {
{pkgs, ...}: {
services.shairport-sync = {
enable = pkgs.stdenv.isLinux;
openFirewall = pkgs.stdenv.isLinux;

View File

@ -4,9 +4,9 @@
pkgs,
...
}: let
cfg = config.containers.podman;
cfg = config.podman;
in {
options.containers = {
options = {
podman = {
enable = lib.mkEnableOption "Podman container runtime";