From 3cafa9f613ece4368539bd56288bc0225558d0f3 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 25 Jan 2024 18:52:07 +0800 Subject: [PATCH] nixos/suites/desktop: modularize submodules into dedicated profiles It's practically enabled every time so why not set them as profiles instead. The structure should be enough for some control over what is enabled. --- modules/nixos/_private/suites/desktop.nix | 118 -------------------- modules/nixos/_private/suites/gaming.nix | 4 - modules/nixos/profiles/desktop/audio.nix | 37 ++++++ modules/nixos/profiles/desktop/default.nix | 10 ++ modules/nixos/profiles/desktop/fonts.nix | 48 ++++++++ modules/nixos/profiles/desktop/hardware.nix | 16 +++ 6 files changed, 111 insertions(+), 122 deletions(-) create mode 100644 modules/nixos/profiles/desktop/audio.nix create mode 100644 modules/nixos/profiles/desktop/default.nix create mode 100644 modules/nixos/profiles/desktop/fonts.nix create mode 100644 modules/nixos/profiles/desktop/hardware.nix diff --git a/modules/nixos/_private/suites/desktop.nix b/modules/nixos/_private/suites/desktop.nix index bd4b8763..2bfa77bf 100644 --- a/modules/nixos/_private/suites/desktop.nix +++ b/modules/nixos/_private/suites/desktop.nix @@ -8,21 +8,8 @@ in { options.suites.desktop = { enable = lib.mkEnableOption "basic desktop-related services and default programs"; - audio.enable = - lib.mkEnableOption "desktop audio-related configurations"; - fonts.enable = lib.mkEnableOption "font-related configuration"; - hardware.enable = - lib.mkEnableOption "the common hardware-related configuration"; cleanup.enable = lib.mkEnableOption "activation of various cleanup services"; autoUpgrade.enable = lib.mkEnableOption "auto-upgrade service with this system"; - wine = { - enable = lib.mkEnableOption "Wine and Wine-related tools"; - package = lib.mkOption { - type = lib.types.package; - description = "The Wine package to be used for related tools."; - default = pkgs.wineWowPackages.stable; - }; - }; }; config = lib.mkIf cfg.enable (lib.mkMerge [ @@ -113,102 +100,6 @@ in { boot.kernelModules = [ "v4l2loopback" ]; }) - (lib.mkIf cfg.audio.enable { - # Enable the preferred audio workflow. - sound.enable = false; - hardware.pulseaudio.enable = false; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - - # This is enabled by default but I want to explicit since - # this is my preferred way of managing anyways. - wireplumber.enable = true; - - # Enable all the bi-...bridges. - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - jack.enable = true; - }; - - # This is based from https://jackaudio.org/faq/linux_rt_config.html. - security.pam.loginLimits = [ - { - domain = "@audio"; - type = "-"; - item = "rtprio"; - value = "95"; - } - { - domain = "@audio"; - type = "-"; - item = "memlock"; - value = "unlimited"; - } - ]; - }) - - (lib.mkIf cfg.fonts.enable { - fonts = { - enableDefaultPackages = true; - fontDir.enable = true; - fontconfig = { - enable = true; - includeUserConf = true; - - defaultFonts = { - monospace = [ "Iosevka" "Jetbrains Mono" "Source Code Pro" ]; - sansSerif = [ "Source Sans Pro" "Noto Sans" ]; - serif = [ "Source Serif Pro" "Noto Serif" ]; - emoji = [ "Noto Color Emoji" ]; - }; - }; - - packages = with pkgs; [ - # Some monospace fonts. - iosevka - monaspace - jetbrains-mono - - # Noto font family - noto-fonts - noto-fonts-cjk - noto-fonts-cjk-sans - noto-fonts-cjk-serif - noto-fonts-lgc-plus - noto-fonts-extra - noto-fonts-emoji - noto-fonts-emoji-blob-bin - - # Adobe Source font family - source-code-pro - source-sans-pro - source-han-sans - source-serif-pro - source-han-serif - source-han-mono - - # Math fonts - stix-two # Didn't know rivers can have sequels. - xits-math # NOTE TO SELF: I wouldn't consider to name the fork with its original project's name backwards. - ]; - }; - }) - - (lib.mkIf cfg.hardware.enable { - # Enable tablet support with OpenTabletDriver. - hardware.opentabletdriver.enable = true; - - # Enable support for Bluetooth. - hardware.bluetooth.enable = true; - - # Enable yer game controllers. - hardware.steam-hardware.enable = true; - hardware.xone.enable = true; - hardware.xpadneo.enable = true; - }) - (lib.mkIf cfg.cleanup.enable { # Weekly garbage collection of Nix store. nix.gc = { @@ -250,14 +141,5 @@ in { randomizedDelaySec = "1min"; }; }) - - # I try to avoid using Wine on NixOS because most of them uses FHS or - # something and I just want it to work but here goes. - (lib.mkIf cfg.wine.enable { - environment.systemPackages = with pkgs; [ - cfg.wine.package # The star of the show. - bottles # The Windows environment package manager. - ]; - }) ]); } diff --git a/modules/nixos/_private/suites/gaming.nix b/modules/nixos/_private/suites/gaming.nix index ca35466d..c601db65 100644 --- a/modules/nixos/_private/suites/gaming.nix +++ b/modules/nixos/_private/suites/gaming.nix @@ -44,10 +44,6 @@ in hardware.steam-hardware.enable = true; hardware.xone.enable = true; hardware.xpadneo.enable = true; - - # Enabling all hardware settings for the desktop (unless the user - # explicitly disabled it). - suites.desktop.hardware.enable = lib.mkDefault true; } (lib.mkIf cfg.emulators.enable { diff --git a/modules/nixos/profiles/desktop/audio.nix b/modules/nixos/profiles/desktop/audio.nix new file mode 100644 index 00000000..5eaab914 --- /dev/null +++ b/modules/nixos/profiles/desktop/audio.nix @@ -0,0 +1,37 @@ +# Enable the preferred audio workflow. +{ lib, ... }: + +{ + security.rtkit.enable = lib.mkDefault true; + + # The main preferred setup of our audio system. + services.pipewire = { + enable = lib.mkDefault true; + + # This is enabled by default but I want to explicit since + # this is my preferred way of managing anyways. + wireplumber.enable = true; + + # Enable all the bi-...bridges. + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + jack.enable = true; + }; + + # This is based from https://jackaudio.org/faq/linux_rt_config.html. + security.pam.loginLimits = [ + { + domain = "@audio"; + type = "-"; + item = "rtprio"; + value = "95"; + } + { + domain = "@audio"; + type = "-"; + item = "memlock"; + value = "unlimited"; + } + ]; +} diff --git a/modules/nixos/profiles/desktop/default.nix b/modules/nixos/profiles/desktop/default.nix new file mode 100644 index 00000000..2219df0d --- /dev/null +++ b/modules/nixos/profiles/desktop/default.nix @@ -0,0 +1,10 @@ +# A common profile for desktop systems. Most of the configurations featured +# here should be enough in common to the typical desktop setups found on +# non-NixOS systems. +{ + imports = [ + ./fonts.nix + ./audio.nix + ./hardware.nix + ]; +} diff --git a/modules/nixos/profiles/desktop/fonts.nix b/modules/nixos/profiles/desktop/fonts.nix new file mode 100644 index 00000000..236ceacf --- /dev/null +++ b/modules/nixos/profiles/desktop/fonts.nix @@ -0,0 +1,48 @@ +# A subprofile for desktop handling the fonts. +{ config, lib, pkgs, ... }: + +{ + fonts.enableDefaultPackages = lib.mkDefault true; + fonts.fontDir.enable = lib.mkDefault true; + + fonts.fontconfig = { + enable = lib.mkDefault true; + includeUserConf = true; + + defaultFonts = { + monospace = [ "Iosevka" "Jetbrains Mono" "Source Code Pro" ]; + sansSerif = [ "Source Sans Pro" "Noto Sans" ]; + serif = [ "Source Serif Pro" "Noto Serif" ]; + emoji = [ "Noto Color Emoji" ]; + }; + }; + + fonts.packages = with pkgs; [ + # Some monospace fonts. + iosevka + monaspace + jetbrains-mono + + # Noto font family + noto-fonts + noto-fonts-cjk + noto-fonts-cjk-sans + noto-fonts-cjk-serif + noto-fonts-lgc-plus + noto-fonts-extra + noto-fonts-emoji + noto-fonts-emoji-blob-bin + + # Adobe Source font family + source-code-pro + source-sans-pro + source-han-sans + source-serif-pro + source-han-serif + source-han-mono + + # Math fonts + stix-two # Didn't know rivers can have sequels. + xits-math # NOTE TO SELF: I wouldn't consider to name the fork with its original project's name backwards. + ]; +} diff --git a/modules/nixos/profiles/desktop/hardware.nix b/modules/nixos/profiles/desktop/hardware.nix new file mode 100644 index 00000000..b62fc940 --- /dev/null +++ b/modules/nixos/profiles/desktop/hardware.nix @@ -0,0 +1,16 @@ +# A bunch of common hardware settings for desktop systems. Mostly, we're just +# adding drivers for common gaming peripherals. +{ lib, ... }: + +{ + # Enable tablet support with OpenTabletDriver. + hardware.opentabletdriver.enable = lib.mkDefault true; + + # Enable support for Bluetooth. + hardware.bluetooth.enable = lib.mkDefault true; + + # Enable yer game controllers. + hardware.steam-hardware.enable = lib.mkDefault true; + hardware.xone.enable = lib.mkDefault true; + hardware.xpadneo.enable = lib.mkDefault true; +}