From b9dbcfd715c7e4b9c5dca198ace96708efb32159 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Wed, 15 Mar 2023 09:22:48 +0100 Subject: [PATCH] [Desktop] Refactor configuration --- default.nix | 2 +- desktop.nix | 241 ------------------ desktop/browser.nix | 54 ++++ desktop/default.nix | 2 + desktop/games.nix | 5 + desktop/general.nix | 154 +++++++++++ desktop/multimedia.nix | 61 ++++- .../pipewire-noise-filter.cfg.nix | 5 +- 8 files changed, 277 insertions(+), 247 deletions(-) delete mode 100644 desktop.nix create mode 100644 desktop/browser.nix create mode 100644 desktop/general.nix rename {packages => desktop}/pipewire-noise-filter.cfg.nix (92%) diff --git a/default.nix b/default.nix index 7fda388..75664ab 100644 --- a/default.nix +++ b/default.nix @@ -4,7 +4,7 @@ ./general.nix ./nix.nix ./boot.nix - ./desktop.nix + ./desktop ./home-manager.nix ./network.nix ./packages.nix diff --git a/desktop.nix b/desktop.nix deleted file mode 100644 index 49e4b88..0000000 --- a/desktop.nix +++ /dev/null @@ -1,241 +0,0 @@ -{ config, pkgs, lib, ... }: -with lib; -let - cfg = config.aviallon.desktop; - generalCfg = config.aviallon.general; - filterConfig = pkgs.callPackage ./packages/pipewire-noise-filter.cfg.nix { - noiseFilterStrength = cfg.audio.noise-filter.strength; - }; -in { - options.aviallon.desktop = { - enable = mkOption { - default = true; - example = false; - type = types.bool; - description = "Enable desktop related configuration"; - }; - layout = mkOption { - type = types.str; - default = "fr"; - example = "us"; - description = "Default keyboard layout for X and console"; - }; - audio = { - noise-filter.strength = mkOption { - description = "Noise reduction strength (from 0 to 100)"; - type = types.float; - default = 80.0; - example = 0.0; - }; - noise-filter.enable = mkOption { - description = "Wether to enable noise filter at all"; - type = types.bool; - default = true; - example = false; - }; - }; - graphics = { - shaderCache = { - path = mkOption { - description = "Where to put shader cache (currently only for NVidia)"; - type = types.path; - default = "/var/tmp/shadercache"; - example = "/tmp/shadercache"; - }; - cleanupInterval = mkOption { - description = "Interval for cache cleanup (tmpfiles.d format). Set to '-' to disable."; - type = types.str; - default = "180d"; - example = "-"; - }; - }; - }; - }; - - imports = [ - ./desktop - ]; - - config = mkIf cfg.enable { - - aviallon.network.backend = mkDefault "NetworkManager"; - - aviallon.boot.kernel = pkgs.linuxKernel.kernels.linux_xanmod; - - # Enable the X11 windowing system. - services.xserver.enable = true; - # services.xserver.tty = mkOverride 70 1; - - systemd.services."getty@tty1".enable = mkOverride 50 false; - systemd.services."autovt@tty1".enable = mkOverride 50 false; - - # Configure keymap in X11 - services.xserver.layout = cfg.layout; - services.xserver.xkbOptions = "eurosign:e"; - - - boot.plymouth.enable = mkDefault (!generalCfg.minimal); - aviallon.boot.cmdline = { - splash = mkIf (!generalCfg.debug) ""; - "udev.log_level" = mkIf (!generalCfg.debug) 3; - preempt = "full"; - reboot = mkDefault "warm"; - "usbhid.mousepoll" = 1; # 1ms latency for mouse - "usbhid.kbpoll" = 4; # 4ms latency for kb - "intel_pstate" = "passive"; - }; - boot.initrd.verbose = generalCfg.debug; - boot.consoleLogLevel = mkIf (!generalCfg.debug) 1; - - console.earlySetup = true; # Prettier console - fonts.enableDefaultFonts = mkIf (!generalCfg.minimal) true; - - hardware.acpilight.enable = mkIf (!generalCfg.minimal) true; - hardware.opentabletdriver.enable = mkIf (!generalCfg.minimal) true; - - hardware.bluetooth = mkIf (!generalCfg.minimal) { - enable = true; - package = pkgs.bluezFull; - }; - - - # Enable sound. - sound.enable = false; - services.pipewire = mkIf (!generalCfg.minimal) { - enable = true; - pulse.enable = true; - jack.enable = true; - alsa.enable = true; - alsa.support32Bit = mkDefault true; - wireplumber.enable = true; - config.pipewire-pulse = { - "context.exec" = [ - { path = "pactl"; args = ''load-module module-combine-sink sink_name="Sorties combinées"''; } - ]; - }; - }; - environment.etc = { - "wireplumber/bluetooth.lua.d/51-bluez-config.lua".text = '' - bluez_monitor.properties = { - ["bluez5.enable-sbc-xq"] = true, - ["bluez5.enable-msbc"] = true, - ["bluez5.enable-hw-volume"] = true, - ["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]" - } - ''; - }; - security.rtkit.enable = true; # Real-time support for pipewire - - security.polkit.enable = true; # Better interactive privilege prompts - - # Enable running X11 apps on Wayland - programs.xwayland.enable = true; - - # Hardware-agnostic audio denoising - systemd.user.services.pipewire-noise-filter = mkIf cfg.audio.noise-filter.enable { - serviceConfig = { - ExecStart = [ - "${pkgs.pipewire}/bin/pipewire -c ${filterConfig}" - ]; - Type = "simple"; - Restart = "on-failure"; - }; - bindsTo = [ "pipewire.service" ]; - after = [ "pipewire.service" ]; - environment = { - PIPEWIRE_DEBUG = "3"; - }; - enable = cfg.audio.noise-filter.strength > 0.0; - wantedBy = [ "pipewire.service" ]; - description = "Pipewire Noise Filter"; - }; - - # Enable touchpad support (enabled default in most desktopManager). - services.xserver.libinput.enable = true; - - hardware.opengl.driSupport = true; - # For 32 bit applications - hardware.opengl.driSupport32Bit = mkIf (!generalCfg.minimal) (mkDefault true); - - # programs.gnupg.agent.pinentryFlavor = "qt"; - - environment.systemPackages = with pkgs; [ - chromium - p7zip - ] - ++ (optionals (!generalCfg.minimal) [ - glxinfo - vdpauinfo - libva-utils - myFirefox - spotify - nextcloud-client - libreoffice-fresh - tdesktop - vlc - ]); - - programs.chromium = { - enable = true; - # https://docs.microsoft.com/en-us/microsoft-edge/extensions-chromium/enterprise/auto-update - # https://clients2.google.com/service/update2/crx?x=id%3D{extension_id}%26v%3D{extension_version} - extensions = [ - # "gcbommkclmclpchllfjekcdonpmejbdp;https://clients2.google.com/service/update2/crx" # HTTPS Everywhere - "mleijjdpceldbelpnpkddofmcmcaknm" # Smart HTTPS - "cjpalhdlnbpafiamejdnhcphjbkeiagm;https://clients2.google.com/service/update2/crx" # Ublock Origin - "fihnjjcciajhdojfnbdddfaoknhalnja" # I don't care about cookies - "eimadpbcbfnmbkopoojfekhnkhdbieeh" # Dark Reader - ]; - extraOpts = { - "PlatformHEVCDecoderSupport" = true; - "BrowserSignin" = 0; - "SyncDisabled" = true; - "PasswordManagerEnabled" = true; - "SpellcheckEnabled" = true; - "SpellcheckLanguage" = [ - "fr" - "en-US" - ]; - "DefaultSearchProviderEnabled" = true; - "DefaultSearchProviderKeyword" = "duckduckgo"; - "DefaultSearchProviderName" = "DuckDuckGo"; - "ExtensionInstallSources" = [ - "https://chrome.google.com/webstore/*" - "https://microsoftedge.microsoft.com/addons/*" - "https://gitlab.com/magnolia1234/bypass-paywalls-chrome-clean/*" - ]; - "BuiltInDnsClientEnabled" = false; - "TranslateEnabled" = false; - "PasswordLeakDetectionEnabled" = false; - "CloudPrintProxyEnabled" = false; - "CloudPrintSubmitEnabled" = false; - "SafeBrowsingProtectionLevel" = 0; # Force disabled - }; - defaultSearchProviderSearchURL = ''https://duckduckgo.com/?kp=1&k1=-1&kav=1&kak=-1&kax=-1&kaq=-1&kap=-1&kau=-1&kao=-1&kae=d&q={searchTerms}''; - defaultSearchProviderSuggestURL = ''https://ac.duckduckgo.com/ac/?q={searchTerms}''; - }; - - - aviallon.programs.allowUnfreeList = [ - "spotify" - "spotify-unwrapped" - - "steam" "steam-original" "steam-runtime" "steam-run" - ]; - - services.packagekit.enable = mkDefault (!generalCfg.minimal); - security.sudo.extraConfig = - '' - # Keep X-related variables for better GUI integration - Defaults:root,%wheel env_keep+=XAUTHORITY - Defaults:root,%wheel env_keep+=DISPLAY - '' - ; - - networking.networkmanager = { - plugins = [] - ++ optional (!generalCfg.minimal) pkgs.networkmanager-openvpn - ; - }; - }; -} diff --git a/desktop/browser.nix b/desktop/browser.nix new file mode 100644 index 0000000..ea00d9f --- /dev/null +++ b/desktop/browser.nix @@ -0,0 +1,54 @@ +{ config, pkgs, lib, ... }: +with lib; +let + cfg = config.aviallon.desktop; + generalCfg = config.aviallon.general; +in { + config = mkIf (cfg.enable && !generalCfg.minimal) { + environment.systemPackages = with pkgs; [] + ++ optionals (!generalCfg.minimal) [ + chromium + myFirefox + ]; + + programs.chromium = { + enable = true; + # https://docs.microsoft.com/en-us/microsoft-edge/extensions-chromium/enterprise/auto-update + # https://clients2.google.com/service/update2/crx?x=id%3D{extension_id}%26v%3D{extension_version} + extensions = [ + # "gcbommkclmclpchllfjekcdonpmejbdp;https://clients2.google.com/service/update2/crx" # HTTPS Everywhere + "mleijjdpceldbelpnpkddofmcmcaknm" # Smart HTTPS + "cjpalhdlnbpafiamejdnhcphjbkeiagm;https://clients2.google.com/service/update2/crx" # Ublock Origin + "fihnjjcciajhdojfnbdddfaoknhalnja" # I don't care about cookies + "eimadpbcbfnmbkopoojfekhnkhdbieeh" # Dark Reader + ]; + extraOpts = { + "PlatformHEVCDecoderSupport" = true; + "BrowserSignin" = 0; + "SyncDisabled" = true; + "PasswordManagerEnabled" = true; + "SpellcheckEnabled" = true; + "SpellcheckLanguage" = [ + "fr" + "en-US" + ]; + "DefaultSearchProviderEnabled" = true; + "DefaultSearchProviderKeyword" = "duckduckgo"; + "DefaultSearchProviderName" = "DuckDuckGo"; + "ExtensionInstallSources" = [ + "https://chrome.google.com/webstore/*" + "https://microsoftedge.microsoft.com/addons/*" + "https://gitlab.com/magnolia1234/bypass-paywalls-chrome-clean/*" # */ + ]; + "BuiltInDnsClientEnabled" = false; + "TranslateEnabled" = false; + "PasswordLeakDetectionEnabled" = false; + "CloudPrintProxyEnabled" = false; + "CloudPrintSubmitEnabled" = false; + "SafeBrowsingProtectionLevel" = 0; # Force disabled + }; + defaultSearchProviderSearchURL = ''https://duckduckgo.com/?kp=1&k1=-1&kav=1&kak=-1&kax=-1&kaq=-1&kap=-1&kau=-1&kao=-1&kae=d&q={searchTerms}''; + defaultSearchProviderSuggestURL = ''https://ac.duckduckgo.com/ac/?q={searchTerms}''; + }; + }; +} diff --git a/desktop/default.nix b/desktop/default.nix index 22b4464..65038ee 100644 --- a/desktop/default.nix +++ b/desktop/default.nix @@ -2,9 +2,11 @@ with lib; { imports = [ + ./general.nix ./developer.nix ./multimedia.nix ./plasma.nix ./games.nix + ./browser.nix ]; } diff --git a/desktop/games.nix b/desktop/games.nix index ed067f5..d9bf19d 100644 --- a/desktop/games.nix +++ b/desktop/games.nix @@ -68,6 +68,11 @@ in { "MESA_GLSL_CACHE_DIR" = cfg.graphics.shaderCache.path + "/mesa"; }; + + aviallon.programs.allowUnfreeList = [ + "steam" "steam-original" "steam-runtime" "steam-run" + ]; + systemd.tmpfiles.rules = [ (mkTmpDir (cfg.graphics.shaderCache.path + "/nvidia") cfg.graphics.shaderCache.cleanupInterval) (mkTmpDir (cfg.graphics.shaderCache.path + "/mesa") cfg.graphics.shaderCache.cleanupInterval) diff --git a/desktop/general.nix b/desktop/general.nix new file mode 100644 index 0000000..d52435a --- /dev/null +++ b/desktop/general.nix @@ -0,0 +1,154 @@ +{ config, pkgs, lib, ... }: +with lib; +let + cfg = config.aviallon.desktop; + generalCfg = config.aviallon.general; + filterConfig = pkgs.callPackage ./pipewire-noise-filter.cfg.nix { + noiseFilterStrength = cfg.audio.noise-filter.strength; + }; +in { + options.aviallon.desktop = { + enable = mkOption { + default = true; + example = false; + type = types.bool; + description = "Enable desktop related configuration"; + }; + environment = mkOption { + default = "plasma"; + example = "gnome"; + type = with types; enum [ "plasma" "gnome" ]; + description = "What Desktop Environment to use"; + }; + layout = mkOption { + type = types.str; + default = "fr"; + example = "us"; + description = "Default keyboard layout for X and console"; + }; + audio = { + noise-filter.strength = mkOption { + description = "Noise reduction strength (from 0 to 100)"; + type = types.float; + default = 80.0; + example = 0.0; + }; + noise-filter.enable = mkOption { + description = "Wether to enable noise filter at all"; + type = types.bool; + default = true; + example = false; + }; + }; + graphics = { + shaderCache = { + path = mkOption { + description = "Where to put shader cache (currently only for NVidia)"; + type = types.path; + default = "/var/tmp/shadercache"; + example = "/tmp/shadercache"; + }; + cleanupInterval = mkOption { + description = "Interval for cache cleanup (tmpfiles.d format). Set to '-' to disable."; + type = types.str; + default = "180d"; + example = "-"; + }; + }; + }; + }; + + config = mkIf cfg.enable { + + aviallon.network.backend = mkDefault "NetworkManager"; + + aviallon.boot.kernel = pkgs.linuxKernel.kernels.linux_xanmod; + + # Enable the X11 windowing system. + services.xserver.enable = true; + # services.xserver.tty = mkOverride 70 1; + + systemd.services."getty@tty1".enable = mkOverride 50 false; + systemd.services."autovt@tty1".enable = mkOverride 50 false; + + # Configure keymap in X11 + services.xserver.layout = cfg.layout; + services.xserver.xkbOptions = "eurosign:e"; + + + boot.plymouth.enable = mkDefault (!generalCfg.minimal); + aviallon.boot.cmdline = { + splash = mkIf (!generalCfg.debug) ""; + "udev.log_level" = mkIf (!generalCfg.debug) 3; + preempt = "full"; + "usbhid.mousepoll" = 1; # 1ms latency for mouse + "usbhid.kbpoll" = 4; # 4ms latency for kb + }; + boot.initrd.verbose = generalCfg.debug; + boot.consoleLogLevel = mkIf (!generalCfg.debug) 1; + + console.earlySetup = true; # Prettier console + fonts.enableDefaultFonts = mkIf (!generalCfg.minimal) true; + + hardware.acpilight.enable = mkIf (!generalCfg.minimal) true; + hardware.opentabletdriver.enable = mkIf (!generalCfg.minimal) true; + + hardware.bluetooth = mkIf (!generalCfg.minimal) { + enable = true; + package = pkgs.bluezFull; + }; + + security.polkit.enable = true; # Better interactive privilege prompts + + # Enable running X11 apps on Wayland + programs.xwayland.enable = true; + + # Enable touchpad support (enabled default in most desktopManager). + services.xserver.libinput.enable = true; + + hardware.opengl.driSupport = true; + # For 32 bit applications + hardware.opengl.driSupport32Bit = mkIf (!generalCfg.minimal) (mkDefault true); + + # programs.gnupg.agent.pinentryFlavor = "qt"; + + environment.systemPackages = with pkgs; [] + ++ [ + p7zip + ] + ++ optionals (!generalCfg.minimal) [ + glxinfo + vdpauinfo + libva-utils + spotify + nextcloud-client + libreoffice-fresh + tdesktop + vlc + veracrypt + ] + ; + + + aviallon.programs.allowUnfreeList = [ + "spotify" "spotify-unwrapped" + + "veracrypt" + ]; + + services.packagekit.enable = mkDefault (!generalCfg.minimal); + security.sudo.extraConfig = + '' + # Keep X-related variables for better GUI integration + Defaults:root,%wheel env_keep+=XAUTHORITY + Defaults:root,%wheel env_keep+=DISPLAY + '' + ; + + networking.networkmanager = { + plugins = [] + ++ optional (!generalCfg.minimal) pkgs.networkmanager-openvpn + ; + }; + }; +} diff --git a/desktop/multimedia.nix b/desktop/multimedia.nix index e34a00a..cdd7649 100644 --- a/desktop/multimedia.nix +++ b/desktop/multimedia.nix @@ -2,8 +2,12 @@ with lib; let cfg = config.aviallon.desktop; + generalCfg = config.aviallon.general; + filterConfig = pkgs.callPackage ./pipewire-noise-filter.cfg.nix { + noiseFilterStrength = cfg.audio.noise-filter.strength; + }; in { - config = mkIf cfg.enable { + config = mkIf (cfg.enable && !generalCfg.minimal) { environment.systemPackages = with pkgs; [ ffmpeg-full krita @@ -12,7 +16,62 @@ in { yt-dlp jellyfin-media-player + jamesdsp # Audio post-processing + nur.repos.wolfangaukang.vdhcoapp ]; + + + # Enable sound. + sound.enable = mkOverride 40 false; + hardware.pulseaudio.enable = mkOverride 40 false; + services.pipewire = { + enable = true; + pulse.enable = true; + jack.enable = true; + alsa.enable = true; + alsa.support32Bit = mkDefault true; + wireplumber.enable = true; + config.pipewire-pulse = { + "context.exec" = [ + { path = "pactl"; args = ''load-module module-combine-sink sink_name="Sorties combinées"''; } + ]; + }; + }; + environment.etc = { + "wireplumber/bluetooth.lua.d/51-bluez-config.lua".text = '' + bluez_monitor.properties = { + ["bluez5.enable-sbc-xq"] = true, + ["bluez5.enable-msbc"] = true, + ["bluez5.enable-hw-volume"] = true, + ["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]" + } + ''; + }; + security.rtkit.enable = true; # Real-time support for pipewire + + + # Hardware-agnostic audio denoising + systemd.user.services.pipewire-noise-filter = mkIf cfg.audio.noise-filter.enable { + unitConfig = { + Slice = "session.slice"; + }; + serviceConfig = { + ExecStart = [ + "${pkgs.pipewire}/bin/pipewire -c ${filterConfig}" + ]; + Type = "simple"; + Restart = "on-failure"; + }; + bindsTo = [ "pipewire.service" ]; + after = [ "pipewire.service" ]; + environment = { + PIPEWIRE_DEBUG = "3"; + }; + enable = cfg.audio.noise-filter.strength > 0.0; + wantedBy = [ "pipewire.service" ]; + description = "Pipewire Noise Filter"; + }; + }; } diff --git a/packages/pipewire-noise-filter.cfg.nix b/desktop/pipewire-noise-filter.cfg.nix similarity index 92% rename from packages/pipewire-noise-filter.cfg.nix rename to desktop/pipewire-noise-filter.cfg.nix index eceb6e7..eb40fee 100644 --- a/packages/pipewire-noise-filter.cfg.nix +++ b/desktop/pipewire-noise-filter.cfg.nix @@ -21,10 +21,7 @@ context.spa-libs = { context.modules = [ { name = libpipewire-module-rtkit args = { - #nice.level = -11 - #rt.prio = 88 - #rt.time.soft = 200000 - #rt.time.hard = 200000 + nice.level = -11 } flags = [ ifexists nofail ] }