From 64e43f45355b45ea08b6c209e0e9fc23fa2a65b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Tue, 18 Oct 2022 21:45:20 -0300 Subject: [PATCH] extract sway system config --- flake.nix | 13 +---- overlays/default.nix | 76 +++++++++++++++------------- overlays/sway.nix | 37 ++++++++++++++ scripts/_gpg-unlock.nix | 2 +- scripts/default.nix | 15 +++--- scripts/wdmenu.nix | 2 +- scripts/wlauncher.nix | 2 +- system/configuration.nix | 106 +++------------------------------------ system/sway.nix | 60 ++++++++++++++++++++++ 9 files changed, 157 insertions(+), 156 deletions(-) create mode 100644 overlays/sway.nix create mode 100644 system/sway.nix diff --git a/flake.nix b/flake.nix index ac36e44..25d683b 100644 --- a/flake.nix +++ b/flake.nix @@ -31,12 +31,10 @@ inherit system; config = { allowUnfree = true; }; }; - overlay-unstable = final: prev: { - unstable = nixpkgs-unstable.legacyPackages.${prev.system}; - }; lib = nixpkgs.lib; common_modules = [ ./system/configuration.nix + ./system/sway.nix ./system/gitlab-runner.nix # nur.nixosModules.nur inputs.hyprland.nixosModules.default @@ -44,14 +42,7 @@ programs.hyprland.enable = true; # programs.hyprland.package = null; } - (mod-inputs@{ config, pkgs, ... }: { - nixpkgs.overlays = [ - overlay-unstable - nur.overlay - (import ./scripts mod-inputs) - (import ./overlays (inputs // { inherit system; })) - ]; - }) + (import ./overlays (inputs // {inherit system;})) home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; diff --git a/overlays/default.nix b/overlays/default.nix index 19c3ffe..f7ee4d2 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,35 +1,43 @@ -inputs@{ system, ... }: -(final: prev: { - uservars = import ../user/variables.nix; - dhist = inputs.dhist.packages.${system}.dhist; - # alacritty = (old-pkgs.alacritty.overrideAttrs - # (old-alacritty: rec { - # src = inputs.alacritty-sixel; - # cargoDeps = old-alacritty.cargoDeps.overrideAttrs - # (old-pkgs.lib.const { - # inherit src; - # outputHash = - # "sha256-2hMntoGHqoQT/Oqz261Ljif5xEuV8SnPH0m52bXdd2s="; - # }); - # })); - # ranger = (old-pkgs.ranger.overridePythonAttrs (old-ranger: rec { - # src = inputs.ranger-sixel; - # checkInputs = [ ]; - # propagatedBuildInputs = with old-pkgs.python3Packages; - # old-ranger.propagatedBuildInputs ++ [ astroid pylint pytest ]; - # })); - material-wifi-icons = final.stdenv.mkDerivation rec { - name = "material-wifi-icons"; - src = inputs.material-wifi-icons; - installPhase = let dest = "$out/share/fonts/${name}"; - in '' - mkdir -p ${dest} - cp material-wifi.ttf ${dest} - ''; - }; - papirus_red = (final.unstable.papirus-icon-theme.override { color = "red"; }); - orchis_theme_compact = - (final.orchis-theme.override { tweaks = [ "compact" "solid" ]; }); - nerdfonts_fira_hack = - (final.nerdfonts.override { fonts = [ "FiraCode" "Hack" ]; }); +(inputs@{ system, ... }: {pkgs, ...}: { + nixpkgs.overlays = [ + inputs.nur.overlay + (import ../scripts) + (import ./sway.nix) + (final: prev: { + unstable = inputs.nixpkgs-unstable.legacyPackages.${prev.system}; + + uservars = import ../user/variables.nix; + dhist = inputs.dhist.packages.${system}.dhist; + # alacritty = (old-pkgs.alacritty.overrideAttrs + # (old-alacritty: rec { + # src = inputs.alacritty-sixel; + # cargoDeps = old-alacritty.cargoDeps.overrideAttrs + # (old-pkgs.lib.const { + # inherit src; + # outputHash = + # "sha256-2hMntoGHqoQT/Oqz261Ljif5xEuV8SnPH0m52bXdd2s="; + # }); + # })); + # ranger = (old-pkgs.ranger.overridePythonAttrs (old-ranger: rec { + # src = inputs.ranger-sixel; + # checkInputs = [ ]; + # propagatedBuildInputs = with old-pkgs.python3Packages; + # old-ranger.propagatedBuildInputs ++ [ astroid pylint pytest ]; + # })); + material-wifi-icons = final.stdenv.mkDerivation rec { + name = "material-wifi-icons"; + src = inputs.material-wifi-icons; + installPhase = let dest = "$out/share/fonts/${name}"; + in '' + mkdir -p ${dest} + cp material-wifi.ttf ${dest} + ''; + }; + papirus_red = (final.unstable.papirus-icon-theme.override { color = "red"; }); + orchis_theme_compact = + (final.orchis-theme.override { tweaks = [ "compact" "solid" ]; }); + nerdfonts_fira_hack = + (final.nerdfonts.override { fonts = [ "FiraCode" "Hack" ]; }); + }) + ]; }) diff --git a/overlays/sway.nix b/overlays/sway.nix new file mode 100644 index 0000000..70117ef --- /dev/null +++ b/overlays/sway.nix @@ -0,0 +1,37 @@ +(final: pkgs: { + # bash script to let dbus know about important env variables and + # propogate them to relevent services run at the end of sway config + # see + # https://github.com/emersion/xdg-desktop-portal-wlr/wiki/"It-doesn't-work"-Troubleshooting-Checklist + # note: this is pretty much the same as /etc/sway/config.d/nixos.conf but also restarts + # some user services to make sure they have the correct environment variables + dbus-sway-environment = pkgs.writeTextFile { + name = "dbus-sway-environment"; + destination = "/bin/dbus-sway-environment"; + executable = true; + text = '' + dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway + systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr + systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr + ''; + }; + # currently, there is some friction between sway and gtk: + # https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland + # the suggested way to set gtk settings is with gsettings + # for gsettings to work, we need to tell it where the schemas are + # using the XDG_DATA_DIR environment variable + # run at the end of sway config + configure-gtk = pkgs.writeTextFile { + name = "configure-gtk"; + destination = "/bin/configure-gtk"; + executable = true; + text = let + schema = pkgs.gsettings-desktop-schemas; + datadir = "${schema}/share/gsettings-schemas/${schema.name}"; + in '' + export XDG_DATA_DIRS=${datadir}:$XDG_DATA_DIRS + gnome_schema=org.gnome.desktop.interface + # gsettings set $gnome_schema gtk-theme 'Dracula' + ''; + }; +}) diff --git a/scripts/_gpg-unlock.nix b/scripts/_gpg-unlock.nix index b2eb444..d5bea9d 100644 --- a/scripts/_gpg-unlock.nix +++ b/scripts/_gpg-unlock.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ pkgs, ... }: pkgs.writeShellScriptBin "_gpg-unlock" '' ${pkgs.gnupg}/bin/gpg-connect-agent reloadagent /bye diff --git a/scripts/default.nix b/scripts/default.nix index 3f5df34..75262cb 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -1,8 +1,7 @@ -{ config, lib, ... }: -(pkgs: _: - with pkgs; +(final: prev: + with prev; let - import_script = (_: path: import (path) { inherit config pkgs lib; }); + import_script = (_: path: import (path) { inherit pkgs lib; }); create_script = (name: text: runtimeInputs: let script_body = pkgs.writeTextFile { @@ -21,13 +20,13 @@ lib.mapAttrs (name: deps: create_script name ./${name} deps); in create_scripts { br = [ ]; - bmenu = [ bemenu dhist fish j4-dmenu-desktop jq sway ]; + bmenu = [ bemenu final.dhist fish j4-dmenu-desktop jq sway ]; _diffr = [ diffr ]; - kak-pager = [ fish _diffr ]; + kak-pager = [ fish final._diffr ]; terminal = [ alacritty ]; - wpass = [ bmenu fd pass sd wl-clipboard wtype ]; + wpass = [ final.bmenu fd pass sd wl-clipboard wtype ]; screenshotsh = - [ capitaine-cursors grim jq sway wl-clipboard xdg-user-dirs ]; + [ capitaine-cursors grim slurp jq sway wl-clipboard xdg-user-dirs ]; volumesh = [ pulseaudio libnotify ]; } // lib.mapAttrs import_script { wdmenu = ./wdmenu.nix; diff --git a/scripts/wdmenu.nix b/scripts/wdmenu.nix index 2f09513..2f93ad5 100644 --- a/scripts/wdmenu.nix +++ b/scripts/wdmenu.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ pkgs, ... }: let inherit (pkgs.uservars) dmenu; available_menus = { diff --git a/scripts/wlauncher.nix b/scripts/wlauncher.nix index c54fc4e..b98adc1 100644 --- a/scripts/wlauncher.nix +++ b/scripts/wlauncher.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ pkgs, ... }: let inherit (pkgs.uservars) dmenu; available_menus = { diff --git a/system/configuration.nix b/system/configuration.nix index c0f9d46..045727a 100644 --- a/system/configuration.nix +++ b/system/configuration.nix @@ -1,44 +1,7 @@ # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, ... }: -let - # bash script to let dbus know about important env variables and - # propogate them to relevent services run at the end of sway config - # see - # https://github.com/emersion/xdg-desktop-portal-wlr/wiki/"It-doesn't-work"-Troubleshooting-Checklist - # note: this is pretty much the same as /etc/sway/config.d/nixos.conf but also restarts - # some user services to make sure they have the correct environment variables - dbus-sway-environment = pkgs.writeTextFile { - name = "dbus-sway-environment"; - destination = "/bin/dbus-sway-environment"; - executable = true; - text = '' - dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway - systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr - systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr - ''; - }; - # currently, there is some friction between sway and gtk: - # https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland - # the suggested way to set gtk settings is with gsettings - # for gsettings to work, we need to tell it where the schemas are - # using the XDG_DATA_DIR environment variable - # run at the end of sway config - configure-gtk = pkgs.writeTextFile { - name = "configure-gtk"; - destination = "/bin/configure-gtk"; - executable = true; - text = let - schema = pkgs.gsettings-desktop-schemas; - datadir = "${schema}/share/gsettings-schemas/${schema.name}"; - in '' - export XDG_DATA_DIRS=${datadir}:$XDG_DATA_DIRS - gnome_schema=org.gnome.desktop.interface - # gsettings set $gnome_schema gtk-theme 'Dracula' - ''; - }; -in { +{ config, pkgs, ... }: { # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; @@ -67,42 +30,6 @@ in { # services.xserver.displayManager.gdm.enable = true; # services.xserver.desktopManager.gnome.enable = true; # services.xserver.displayManager.autologin.user = "lelgenio"; - services.greetd = let - greetd_main_script = pkgs.writeShellScriptBin "main" '' - ${dbus-sway-environment}/bin/dbus-sway-environment - ${configure-gtk}/bin/configure-gtk - export XDG_CURRENT_DESKTOP=sway GTK_THEME=Orchis-Red-Dark-Compact - ${pkgs.greetd.gtkgreet}/bin/gtkgreet -l -c sway - swaymsg exit - ''; - swayConfig = pkgs.writeText "greetd-sway-config" '' - # `-l` activates layer-shell mode. Notice that `swaymsg exit` will run after gtkgreet. - exec "${greetd_main_script}/bin/main" - bindsym Mod4+shift+e exec swaynag \ - -t warning \ - -m 'What do you want to do?' \ - -b 'Poweroff' 'systemctl poweroff' \ - -b 'Reboot' 'systemctl reboot' - input "*" { - repeat_delay 200 - repeat_rate 30 - xkb_layout us(colemak) - xkb_numlock enabled - xkb_options lv3:lsgt_switch,grp:shifts_toggle - } - ''; - in { - enable = true; - settings = { - initial_session = { - command = "${pkgs.sway}/bin/sway"; - user = "lelgenio"; - }; - default_session = { - command = "${pkgs.sway}/bin/sway --config ${swayConfig}"; - }; - }; - }; # Configure keymap in X11 services.xserver = { layout = "us"; @@ -111,16 +38,9 @@ in { console.keyMap = "colemak"; # Enable CUPS to print documents. # services.printing.enable = true; - services.dbus.enable = true; - xdg.portal = { - enable = true; - wlr.enable = true; - # gtk portal needed to make gtk apps happy - # extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; - # gtkUsePortal = false; - }; services.flatpak.enable = true; virtualisation.docker.enable = true; + security.rtkit.enable = true; services.sshd.enable = true; @@ -137,6 +57,7 @@ in { # Enable touchpad support (enabled default in most desktopManager). services.xserver.libinput.enable = true; + # Define a user account. Don't forget to set a password with ‘passwd’. users.users.lelgenio = { isNormalUser = true; @@ -171,23 +92,12 @@ in { tdesktop # recomended by nixwiki alacritty # gpu accelerated terminal - sway - dbus-sway-environment - pkgs.xdg-desktop-portal - pkgs.xdg-desktop-portal-wlr - configure-gtk - wayland + glib # gsettings usbutils # dracula-theme # gtk theme gnome3.adwaita-icon-theme # default gnome cursors - swaylock - swayidle - grim # screenshot functionality - slurp # screenshot functionality - wl-clipboard # wl-copy and wl-paste for copy/paste from stdin / stdout - bemenu # wayland clone of dmenu - mako # notification system developed by swaywm maintainer + orchis_theme_compact pulseaudio @@ -208,11 +118,7 @@ in { sqlx-cli nodePackages.sass ]; - # enable sway window manager - programs.sway = { - enable = true; - wrapperFeatures.gtk = true; - }; + services.geoclue2.enable = true; # programs.qt5ct.enable = true; programs.steam.enable = true; diff --git a/system/sway.nix b/system/sway.nix new file mode 100644 index 0000000..6a2cc0b --- /dev/null +++ b/system/sway.nix @@ -0,0 +1,60 @@ +{ pkgs, ... }: { + # enable sway window manager + programs.sway = { + enable = true; + wrapperFeatures.gtk = true; + }; + services.dbus.enable = true; + xdg.portal = { + enable = true; + wlr.enable = true; + # gtk portal needed to make gtk apps happy + # extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; + # gtkUsePortal = false; + }; + services.greetd = let + greetd_main_script = pkgs.writeShellScriptBin "main" '' + ${pkgs.dbus-sway-environment}/bin/dbus-sway-environment + ${pkgs.configure-gtk}/bin/configure-gtk + export XDG_CURRENT_DESKTOP=sway GTK_THEME=Orchis-Red-Dark-Compact + ${pkgs.greetd.gtkgreet}/bin/gtkgreet -l -c sway + swaymsg exit + ''; + swayConfig = pkgs.writeText "greetd-sway-config" '' + # `-l` activates layer-shell mode. Notice that `swaymsg exit` will run after gtkgreet. + exec "${greetd_main_script}/bin/main" + bindsym Mod4+shift+e exec swaynag \ + -t warning \ + -m 'What do you want to do?' \ + -b 'Poweroff' 'systemctl poweroff' \ + -b 'Reboot' 'systemctl reboot' + input "*" { + repeat_delay 200 + repeat_rate 30 + xkb_layout us(colemak) + xkb_numlock enabled + xkb_options lv3:lsgt_switch,grp:shifts_toggle + } + ''; + in { + enable = true; + settings = { + initial_session = { + command = "${pkgs.sway}/bin/sway"; + user = "lelgenio"; + }; + default_session = { + command = "${pkgs.sway}/bin/sway --config ${swayConfig}"; + }; + }; + }; + environment.systemPackages = with pkgs; [ + sway + swaylock + swayidle + + wayland + pkgs.xdg-desktop-portal + pkgs.xdg-desktop-portal-wlr + ]; +}