From d6e031efd0c59263f67f69fba432d3102c0218d0 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Sat, 15 Feb 2025 10:21:22 -0800 Subject: [PATCH] [desktop] Refactor into multiple components --- machines/nix-book/configuration.nix | 5 +- machines/wixos/configuration.nix | 5 +- roles/default.nix | 6 ++ roles/desktop/default.nix | 98 +++++++---------------------- roles/desktop/gaming.nix | 17 +++++ roles/desktop/kde.nix | 12 ++++ roles/desktop/programs.nix | 16 +++++ roles/desktop/sddm.nix | 15 +++++ roles/desktop/wayland.nix | 23 +++++++ roles/desktop/x11.nix | 19 ++++++ roles/virtualisation/default.nix | 2 + 11 files changed, 139 insertions(+), 79 deletions(-) create mode 100644 roles/desktop/gaming.nix create mode 100644 roles/desktop/kde.nix create mode 100644 roles/desktop/programs.nix create mode 100644 roles/desktop/sddm.nix create mode 100644 roles/desktop/wayland.nix create mode 100644 roles/desktop/x11.nix diff --git a/machines/nix-book/configuration.nix b/machines/nix-book/configuration.nix index 8f09572..025cc2d 100644 --- a/machines/nix-book/configuration.nix +++ b/machines/nix-book/configuration.nix @@ -14,7 +14,10 @@ bluetooth.enable = true; desktop = { enable = true; - waylandOnly = true; + wayland = true; + gaming = true; + kde = true; + sddm = true; }; nfs-mounts.enable = true; printing.enable = true; diff --git a/machines/wixos/configuration.nix b/machines/wixos/configuration.nix index 30c71d3..ba18858 100644 --- a/machines/wixos/configuration.nix +++ b/machines/wixos/configuration.nix @@ -12,7 +12,10 @@ ]; roles = { - desktop.enable = true; + desktop = { + enable = true; + wayland = true; + }; }; networking.hostName = "wixos"; diff --git a/roles/default.nix b/roles/default.nix index 2056133..1932e3a 100644 --- a/roles/default.nix +++ b/roles/default.nix @@ -31,6 +31,12 @@ with lib; }; time.timeZone = "America/Los_Angeles"; + services.xserver.xkb = { + layout = "us"; + variant = ""; + options = "caps:escape"; + }; + # Don't go to emergency mode if we aren't able to mount filesystems. # This is silly if you have multiple hard drives or partitions # configured on a machine and then one goes away intentionally or diff --git a/roles/desktop/default.nix b/roles/desktop/default.nix index 46330c3..2fee5a5 100644 --- a/roles/desktop/default.nix +++ b/roles/desktop/default.nix @@ -4,88 +4,32 @@ with lib; let cfg = config.roles.desktop; - - customPackages = pkgs.callPackage ../../packages {}; - - basePackages = with pkgs; [ - #bambu-studio - brightnessctl - emacs-nox - ]; - - x11BasePackages = with pkgs; [ - ]; - - x11OnlyPackages = with pkgs; [ - ]; - - waylandBasePackages = with pkgs; [ - grim - slurp - wl-clipboard - mako - ]; - - waylandOnlyPackages = with pkgs; [ - ]; in { options.roles.desktop = { - enable = mkEnableOption "Enable the desktop role"; - x11Only = mkOption { - type = types.bool; - default = false; - }; - waylandOnly = mkOption { - type = types.bool; - default = false; - }; + enable = mkEnableOption "Enable the desktop role."; + x11 = mkOption { type = types.bool; default = false; description = "Enable X11 support."; }; + wayland = mkOption { type = types.bool; default = false; description = "Enable Wayland support."; }; + kde = mkOption { type = types.bool; default = false; description = "Enable KDE."; }; + gaming = mkOption { type = types.bool; default = false; description = "Enable gaming support."; }; + sddm = mkOption { type = types.bool; default = false; description = "Enable SDDM greeter."; }; }; - config = mkIf cfg.enable - { - services.xserver.xkb = { - layout = "us"; - variant = ""; - options = "caps:escape"; - }; - services.xserver.enable = true; + imports = [ + ./x11.nix + ./wayland.nix + ./gaming.nix + ./kde.nix + ]; - services.displayManager.sddm = { - enable = true; - wayland.enable = !cfg.x11Only; - }; - services.desktopManager.plasma6.enable = true; - - services.xserver.windowManager.i3 = { - enable = true; - extraPackages = with pkgs; [ - dmenu - i3status - i3lock - ]; - }; - programs.dconf.enable = true; - services.gnome.gnome-keyring.enable = true; - - programs.sway = mkIf (!cfg.x11Only) { - enable = true; - wrapperFeatures.gtk = true; - }; - programs.light.enable = mkIf (!cfg.x11Only) true; - - programs.kdeconnect.enable = true; - - virtualisation.docker.enable = true; - users.extraGroups.docker.members = [ "johno" ]; - - environment.systemPackages = with pkgs; mkMerge [ - basePackages - (mkIf (!cfg.waylandOnly) x11BasePackages) - (mkIf cfg.x11Only x11OnlyPackages) - (mkIf (!cfg.x11Only) waylandBasePackages) - (mkIf (cfg.waylandOnly) waylandOnlyPackages) - ]; - }; + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + brightnessctl + emacs-nox + ]; + programs.dconf.enable = true; + services.gnome.gnome-keyring.enable = true; + programs.kdeconnect.enable = true; + }; } diff --git a/roles/desktop/gaming.nix b/roles/desktop/gaming.nix new file mode 100644 index 0000000..c0e25c0 --- /dev/null +++ b/roles/desktop/gaming.nix @@ -0,0 +1,17 @@ +{ lib, config, pkgs, ... }: + +with lib; + +let + cfg = config.roles.desktop; +in +{ + config = mkIf (cfg.enable && cfg.gaming) { + environment.systemPackages = with pkgs; [ + steam + lutris + ]; + + # Possibly other gaming specific services or settings + }; +} diff --git a/roles/desktop/kde.nix b/roles/desktop/kde.nix new file mode 100644 index 0000000..5f1b5bc --- /dev/null +++ b/roles/desktop/kde.nix @@ -0,0 +1,12 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.roles.desktop; +in +{ + config = mkIf (cfg.enable && cfg.kde) { + services.desktopManager.plasma6.enable = true; + }; +} diff --git a/roles/desktop/programs.nix b/roles/desktop/programs.nix new file mode 100644 index 0000000..cc7070e --- /dev/null +++ b/roles/desktop/programs.nix @@ -0,0 +1,16 @@ +{ lib, config, pkgs, ... }: + +with lib; + +{ + config = { + environment.systemPackages = with pkgs; [ + brightnessctl + emacs-nox + ]; + + programs.dconf.enable = true; + services.gnome.gnome-keyring.enable = true; + programs.kdeconnect.enable = true; + }; +} diff --git a/roles/desktop/sddm.nix b/roles/desktop/sddm.nix new file mode 100644 index 0000000..bca0187 --- /dev/null +++ b/roles/desktop/sddm.nix @@ -0,0 +1,15 @@ +{ lib, config, pkgs, ... }: + +with lib; + +let + cfg = config.roles.desktop; +in +{ + config = mkIf (cfg.enable && cfg.sddm) { + services.displayManager.sddm = { + enable = true; + wayland.enable = (!cfg.x11 && cfg.wayland); + }; + }; +} diff --git a/roles/desktop/wayland.nix b/roles/desktop/wayland.nix new file mode 100644 index 0000000..4b6a0e1 --- /dev/null +++ b/roles/desktop/wayland.nix @@ -0,0 +1,23 @@ +{ lib, config, pkgs, ... }: + +with lib; + +let + cfg = config.roles.desktop; +in +{ + config = mkIf (cfg.enable && cfg.wayland) { + programs.sway = { + enable = true; + wrapperFeatures.gtk = true; + }; + programs.light.enable = true; + + environment.systemPackages = with pkgs; [ + grim + slurp + wl-clipboard + mako + ]; + }; +} diff --git a/roles/desktop/x11.nix b/roles/desktop/x11.nix new file mode 100644 index 0000000..33131d7 --- /dev/null +++ b/roles/desktop/x11.nix @@ -0,0 +1,19 @@ +{ lib, config, pkgs, ... }: + +with lib; + +let + cfg = config.roles.desktop; +in +{ + config = mkIf (cfg.enable && cfg.x11) { + services.xserver = { + enable = true; + + windowManager.i3 = { + enable = true; + extraPackages = with pkgs; [ dmenu i3status i3lock ]; + }; + }; + }; +} diff --git a/roles/virtualisation/default.nix b/roles/virtualisation/default.nix index 7232362..5e362d7 100644 --- a/roles/virtualisation/default.nix +++ b/roles/virtualisation/default.nix @@ -14,5 +14,7 @@ in { virtualisation.libvirtd.enable = true; programs.virt-manager.enable = true; + virtualisation.docker.enable = true; + users.extraGroups.docker.members = [ "johno" ]; }; }