diff --git a/home/desktop/default.nix b/home/desktop/default.nix index 2ab18e9..ccadf13 100644 --- a/home/desktop/default.nix +++ b/home/desktop/default.nix @@ -11,6 +11,7 @@ with lib; { }; imports = [ + ./niri/default.nix ./hyprland.nix ./theme.nix ./tools.nix diff --git a/home/desktop/hyprland.nix b/home/desktop/hyprland.nix index 6a2dc6a..cc1fc85 100644 --- a/home/desktop/hyprland.nix +++ b/home/desktop/hyprland.nix @@ -17,7 +17,7 @@ let in { options.modules.desktop.hyprland = { enable = mkOption { - default = cfg.enable; + default = false; example = true; description = "Whether to enable Hyprland configuration."; type = types.bool; diff --git a/home/desktop/niri/config.kdl b/home/desktop/niri/config.kdl new file mode 100644 index 0000000..c05608c --- /dev/null +++ b/home/desktop/niri/config.kdl @@ -0,0 +1,8 @@ +spawn-at-startup "cosmic-ext-alternative-startup" + +binds { + Super+T { spawn "ghostty"; } + Super+Space { spawn "cosmic-launcher"; } + Super+Shift+Space { spawn "cosmic-app-library"; } + Super+Alt+L { spawn "cosmic-greeter"; } +} diff --git a/home/desktop/niri/default.nix b/home/desktop/niri/default.nix new file mode 100644 index 0000000..87845a4 --- /dev/null +++ b/home/desktop/niri/default.nix @@ -0,0 +1,19 @@ +{ lib, config, pkgs, ... }: + +with lib; +let + cfg = config.modules.desktop; +in { + options.modules.desktop.niri = { + enable = mkOption { + default = cfg.enable; + example = true; + description = "Whether to enable Niri configuration."; + type = types.bool; + }; + }; + + config = mkIf cfg.niri.enable { + xdg.configFile."niri/config.kdl".text = (builtins.readFile ./config.kdl); + }; +} diff --git a/home/desktop/theme.nix b/home/desktop/theme.nix index 6581417..13c2978 100644 --- a/home/desktop/theme.nix +++ b/home/desktop/theme.nix @@ -7,7 +7,7 @@ let in { options.modules.desktop.theme = { enable = mkOption { - default = cfg.enable; + default = false; example = true; description = "Whether to enable theming configuration."; type = types.bool; diff --git a/home/desktop/tools.nix b/home/desktop/tools.nix index 4e4e786..ec8bd0a 100644 --- a/home/desktop/tools.nix +++ b/home/desktop/tools.nix @@ -6,7 +6,7 @@ let in { options.modules.desktop.tools = { enable = mkOption { - default = cfg.enable; + default = false; example = true; description = "Whether to enable basic desktop tools."; type = types.bool; diff --git a/machines/pepper/configuration.nix b/machines/pepper/configuration.nix index 04aaa08..9e11f25 100755 --- a/machines/pepper/configuration.nix +++ b/machines/pepper/configuration.nix @@ -14,16 +14,6 @@ modules = { desktop = { enable = true; - hyprland = { - input = { - sensitivity = -0.5; - kb_layout = "us"; - }; - monitor = [ - "desc:Samsung Electric Company Odyssey G60SD HNAX300205, 2560x1440@360, 0x0, 1, vrr, 1, bitdepth, 10" - "desc:LG Electronics 27GL850 005NTPC4Q200, preferred, auto, 1, transform, 1, vrr, 1" - ]; - }; }; server = { enable = true; diff --git a/modules/desktop/audio.nix b/modules/desktop/audio.nix index 2fcdde2..ca9d41c 100644 --- a/modules/desktop/audio.nix +++ b/modules/desktop/audio.nix @@ -36,6 +36,8 @@ in { }; config = mkIf cfg.audio.enable { + xdg.sounds.enable = true; + security.rtkit.enable = true; services = { diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index b279139..26c2306 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -18,16 +18,11 @@ in { }; } // helpers.linuxAttrs { imports = [ - ./session.nix ./affinity.nix ./fonts.nix ./rawaccel.nix ./audio.nix ./networking.nix - ./hyprland.nix + ./niri-cosmic.nix ]; - - config = mkIf cfg.enable { - users.users."${user}".extraGroups = [ "video" ]; - }; } diff --git a/modules/desktop/hyprland.nix b/modules/desktop/hyprland.nix deleted file mode 100644 index 495feda..0000000 --- a/modules/desktop/hyprland.nix +++ /dev/null @@ -1,127 +0,0 @@ -{ lib, pkgs, config, ... }: - -with lib; -let - cfg = config.modules.desktop; - - mkConfig = input: monitor: pkgs.writeText "hyprland.conf" '' - debug { - error_position=1 - } - - general { - allow_tearing=true - } - - input { - touchpad { - clickfinger_behavior=true - scroll_factor=0.180000 - tap-and-drag=false - tap-to-click=false - } - kb_options=ctrl:nocaps,lv3:ralt_switch - kb_layout=${cfg.hyprland.input.kb_layout} - kb_model=${cfg.hyprland.input.kb_model} - kb_variant=${cfg.hyprland.input.kb_variant} - sensitivity=${toString cfg.hyprland.input.sensitivity} - accel_profile = "flat" - } - - misc { - disable_hyprland_logo=true - disable_splash_rendering=true - vrr=1 - } - - render { - direct_scanout=1 - expand_undersized_textures=false - cm_fs_passthrough=1 - cm_enabled=true - } - - experimental { - xx_color_management_v4=true - } - - cursor { - sync_gsettings_theme=false - } - - ecosystem { - no_update_news = true - no_donation_nag = true - } - - ${concatMapStringsSep "\n" (x: "monitor=${x}") cfg.hyprland.monitor} - monitor=, preferred, auto, 1 - ''; -in { - options.modules.desktop.hyprland = { - enable = mkOption { - default = cfg.enable; - example = true; - description = "Whether to enable Hyprland"; - type = types.bool; - }; - - input = mkOption { - default = { }; - type = types.submodule { - options = { - sensitivity = mkOption { - default = 0.0; - type = types.float; - }; - kb_model = mkOption { - default = "apple"; - type = types.str; - }; - kb_variant = mkOption { - default = "mac"; - type = types.str; - }; - kb_layout = mkOption { - default = "gb"; - type = types.str; - }; - }; - }; - }; - - monitor = mkOption { - description = "Monitor configuration"; - default = [ ]; - type = lib.types.listOf lib.types.str; - }; - - configFile = mkOption { - default = mkConfig cfg.hyprland.input cfg.hyprland.monitor; - }; - }; - - config = mkIf cfg.hyprland.enable { - programs = { - hyprlock.enable = true; - hyprland = { - enable = true; - withUWSM = true; - xwayland.enable = true; - }; - }; - - security.pam.services.hyprlock = {}; - - xdg.portal = { - enable = true; - xdgOpenUsePortal = true; - extraPortals = with pkgs; [ - xdg-desktop-portal-hyprland - xdg-desktop-portal-gtk - ]; - }; - - environment.etc."hypr/hyprland.conf".source = cfg.hyprland.configFile; - }; -} diff --git a/modules/desktop/niri-cosmic.nix b/modules/desktop/niri-cosmic.nix new file mode 100644 index 0000000..f6ba1f4 --- /dev/null +++ b/modules/desktop/niri-cosmic.nix @@ -0,0 +1,273 @@ +{ lib, pkgs, config, ... }: + +with lib; +let + cfg = config.modules.desktop; + + corePackages = with pkgs; [ + niri + config.services.displayManager.cosmic-greeter.package + cosmic-applets + cosmic-applibrary + cosmic-bg + cosmic-comp + cosmic-files + cosmic-idle + cosmic-initial-setup + cosmic-launcher + cosmic-notifications + cosmic-osd + cosmic-panel + cosmic-session + cosmic-settings + cosmic-settings-daemon + cosmic-workspaces-epoch + ]; + + supportPackages = with pkgs; [ + adwaita-icon-theme + alsa-utils + glib + hicolor-icon-theme + playerctl + pop-icon-theme + pop-launcher + pulseaudio + xdg-user-dirs + ]; + + optionalPackages = with pkgs; [ + xwayland-satellite + cosmic-icons + cosmic-screenshot + cosmic-wallpapers + ]; + + cosmic-base-config = let + configs = { + "com.system76.CosmicComp/v1/workspaces" = '' + ( + workspace_mode: OutputBound, + workspace_layout: Horizontal, + ) + ''; + "com.system76.CosmicComp/v1/autotile_behavior" = '' + PerWorkspace + ''; + }; + fileDrvs = + attrsets.mapAttrsToList + (name: text: pkgs.writeTextDir "share/cosmic/${name}" text) + configs; + in pkgs.buildEnv { + name = "cosmic-base-config"; + paths = fileDrvs; + pathsToLink = [ "/share/cosmic" ]; + }; + + cosmic-ext-niri-desktop = let + startCosmicExtNiri = pkgs.writeShellApplication { + name = "start-cosmic-ext-niri"; + runtimeInputs = with pkgs; [ systemd coreutils ]; + text = with pkgs; /*sh*/'' + set -e + + if systemctl --user -q is-active cosmic-niri-session.service; then + exit 1 + fi + + for unit in $(systemctl --user --no-legend --state=failed --plain list-units | cut -f1 -d' '); do + partof="$(systemctl --user show -p PartOf --value "$unit")" + for target in cosmic-session.target graphical-session.target; do + if [ "$partof" = "$target" ]; then + systemctl --user reset-failed "$unit" + break + fi + done + done + + export XDG_CURRENT_DESKTOP="''${XDG_CURRENT_DESKTOP:=niri}" + export XDG_SESSION_TYPE="''${XDG_SESSION_TYPE:=wayland}" + export DCONF_PROFILE=cosmic + + systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP DCONF_PROFILE + systemctl --user --wait start cosmic-niri-session.service + + systemctl --user start --job-mode=replace-irreversibly niri-shutdown.target + systemctl --user unset-environment WAYLAND_DISPLAY DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP NIRI_SOCKET + ''; + }; + in (pkgs.writeTextFile { + name = "cosmic-on-niri"; + destination = "/share/wayland-sessions/COSMIC-on-niri.desktop"; + text = '' + [Desktop Entry] + Name=COSMIC-on-niri + Comment=This session logs you into the COSMIC desktop on niri + Type=Application + DesktopNames=niri + Exec=${getExe startCosmicExtNiri} + ''; + }).overrideAttrs (old: { + passthru.providedSessions = [ "COSMIC-on-niri" ]; + }); + + cosmic-ext-alternative-startup = pkgs.rustPlatform.buildRustPackage rec { + pname = "cosmic-ext-alternative-startup"; + version = "unstable-2024-11-24"; + src = pkgs.fetchFromGitHub { + owner = "drakulix"; + repo = pname; + rev = "8ceda00197c7ec0905cf1dccdc2d67d738e45417"; + hash = "sha256-0kqn3hZ58uQMl39XXF94yQS1EWmGIK45/JFTAigg/3M="; + }; + cargoHash = "sha256-DeMkAG2iINGden0Up013M9mWDN4QHrF+FXoNqpGB+mg="; + meta.mainProgram = pname; + }; +in { + options.modules.desktop.niri-cosmic = { + enable = mkOption { + default = cfg.enable; + example = true; + description = "Whether to enable COSMIC on Niri"; + type = types.bool; + }; + }; + + config = mkIf cfg.niri-cosmic.enable { + boot = { + plymouth.enable = true; + initrd.verbose = mkDefault false; + consoleLogLevel = 0; + }; + + programs = { + dconf = { + enable = true; + packages = [ pkgs.cosmic-session ]; + }; + }; + + environment = { + pathsToLink = [ + "/share/backgrounds" + "/share/cosmic" + "/share/cosmic-layouts" + "/share/cosmic-themes" + ]; + systemPackages = corePackages ++ supportPackages ++ optionalPackages ++ [ + cosmic-base-config + cosmic-ext-alternative-startup + ]; + sessionVariables = { + X11_BASE_RULES_XML = "${config.services.xserver.xkb.dir}/rules/base.xml"; + X11_EXTRA_RULES_XML = "${config.services.xserver.xkb.dir}/rules/base.extras.xml"; + + GSK_RENDERER = mkDefault "ngl"; + QT_QPA_PLATFORM = mkDefault "wayland;xcb"; + GDK_BACKEND = mkDefault "wayland,x11,*"; + SDL_VIDEODRIVER = mkDefault "wayland,x11"; + NIXOS_OZONE_WL = mkDefault 1; + COSMIC_DATA_CONTROL_ENABLED = mkDefault 1; + }; + }; + + hardware.system76.power-daemon.enable = mkDefault true; + + services = { + graphical-desktop.enable = true; + displayManager = { + cosmic-greeter.enable = true; + sessionPackages = [ cosmic-ext-niri-desktop ]; + }; + + dbus = { + enable = true; + implementation = mkDefault "broker"; + }; + + accounts-daemon.enable = true; + libinput.enable = true; + upower.enable = true; + + acpid.enable = mkDefault true; + gnome.gnome-keyring.enable = mkDefault true; + gvfs.enable = mkDefault true; + + logind.settings.Login = { + powerKey = "suspend"; + powerKeyLongPress = "poweroff"; + lidSwitch = "suspend"; + }; + + geoclue2 = { + enable = true; + enableDemoAgent = false; + whitelistedAgents = [ "geoclue-demo-agent" ]; + }; + }; + + security = { + polkit.enable = true; + rtkit.enable = true; + pam.services.cosmic-greeter = { }; + }; + + systemd = { + packages = with pkgs; [ cosmic-session niri ]; + user.services = { + cosmic-niri-session = let + set-environment = config.system.build.setEnvironment; + run-session = pkgs.writeShellScriptBin "run-cosmic-niri-session" /*sh*/'' + source ${set-environment} + ${getBin pkgs.dbus}/bin/dbus-update-activation-environment --systemd --all + exec ${getBin pkgs.cosmic-session}/bin/cosmic-session ${getBin pkgs.niri}/bin/niri --session + ''; + in { + bindsTo = [ "graphical-session.target" ]; + serviceConfig = { + Environment = [ + "RUST_BACKTRACE=1" + "RUST_LOG=info" + ]; + Type = "notify"; + NotifyAccess = "all"; + Slice = "session.slice"; + Restart = "on-failure"; + ExecStart = getExe run-session; + }; + }; + }; + }; + + xdg = { + sounds.enable = true; + icons.fallbackCursorThemes = mkDefault [ "Cosmic" ]; + portal = { + enable = true; + xdgOpenUsePortal = true; + configPackages = mkDefault [ pkgs.xdg-desktop-portal-cosmic ]; + extraPortals = with pkgs; [ + xdg-desktop-portal-gnome + xdg-desktop-portal-cosmic + xdg-desktop-portal-gtk + ]; + config.niri = { + default = [ "gnome" "cosmic" "gtk" ]; + "org.freedesktop.impl.portal.Access" = "gtk"; + "org.freedesktop.impl.portal.Notification" = "gtk"; + "org.freedesktop.impl.portal.Secret" = "gnome-keyring"; + "org.freedesktop.impl.portal.FileChooser" = "gtk"; + "org.freedesktop.impl.portal.ScreenCast" = "gnome"; + "org.freedesktop.impl.portal.Screenshot" = "gnome"; + }; + }; + }; + + fonts.packages = with pkgs; [ + fira + noto-fonts + open-sans + ]; + }; +} diff --git a/modules/desktop/session.nix b/modules/desktop/session.nix deleted file mode 100644 index 28828fa..0000000 --- a/modules/desktop/session.nix +++ /dev/null @@ -1,78 +0,0 @@ -{ lib, config, pkgs, user, ... } @ inputs: - -with lib; -let - inherit (import ../../lib/theme.nix inputs) cursorTheme defaultFont iconTheme gtkTheme kvantumTheme; - cfg = config.modules.desktop; -in { - options.modules.desktop.session = { - enable = mkOption { - default = cfg.enable; - example = true; - description = "Whether to enable session and desktop environment."; - type = types.bool; - }; - }; - - config = mkIf cfg.session.enable { - users.users."${user}".extraGroups = [ "video" ]; - - boot = { - plymouth.enable = true; - initrd.verbose = mkDefault false; - consoleLogLevel = 0; - }; - - environment.sessionVariables = { - GSK_RENDERER = mkDefault "ngl"; - QT_QPA_PLATFORM = mkDefault "wayland;xcb"; - GDK_BACKEND = mkDefault "wayland,x11,*"; - SDL_VIDEODRIVER = mkDefault "wayland,x11"; - NIXOS_OZONE_WL = mkDefault "1"; - }; - - services = { - greetd = { - enable = true; - settings = { - terminal.vt = 1; - default_session.command = let - hyprConfig = pkgs.writeTextFile { - name = "hyprland-greeter.conf"; - text = '' - source=${toString cfg.hyprland.configFile} - exec-once = ${getExe config.programs.regreet.package}; hyprctl dispatch exit - animations { - enabled = false - } - ''; - }; - in escapeShellArgs [ - "${pkgs.dbus}/bin/dbus-run-session" - "${getExe pkgs.hyprland}" - "-c" (toString hyprConfig) - ]; - }; - }; - upower.enable = true; - gvfs.enable = true; - logind.settings.Login = { - powerKey = "suspend"; - powerKeyLongPress = "poweroff"; - lidSwitch = "suspend"; - }; - }; - - programs = { - regreet = { - enable = true; - inherit cursorTheme iconTheme; - font = defaultFont; - theme = gtkTheme; - settings.GTK.application_prefer_dark_theme = true; - }; - }; - - security.polkit.enable = true; - }; -}