at 21.11-pre 5.1 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.programs.sway; 7 8 wrapperOptions = types.submodule { 9 options = 10 let 11 mkWrapperFeature = default: description: mkOption { 12 type = types.bool; 13 inherit default; 14 example = !default; 15 description = "Whether to make use of the ${description}"; 16 }; 17 in { 18 base = mkWrapperFeature true '' 19 base wrapper to execute extra session commands and prepend a 20 dbus-run-session to the sway command. 21 ''; 22 gtk = mkWrapperFeature false '' 23 wrapGAppsHook wrapper to execute sway with required environment 24 variables for GTK applications. 25 ''; 26 }; 27 }; 28 29 swayPackage = pkgs.sway.override { 30 extraSessionCommands = cfg.extraSessionCommands; 31 extraOptions = cfg.extraOptions; 32 withBaseWrapper = cfg.wrapperFeatures.base; 33 withGtkWrapper = cfg.wrapperFeatures.gtk; 34 isNixOS = true; 35 }; 36in { 37 options.programs.sway = { 38 enable = mkEnableOption '' 39 Sway, the i3-compatible tiling Wayland compositor. You can manually launch 40 Sway by executing "exec sway" on a TTY. Copy /etc/sway/config to 41 ~/.config/sway/config to modify the default configuration. See 42 <link xlink:href="https://github.com/swaywm/sway/wiki" /> and 43 "man 5 sway" for more information''; 44 45 wrapperFeatures = mkOption { 46 type = wrapperOptions; 47 default = { }; 48 example = { gtk = true; }; 49 description = '' 50 Attribute set of features to enable in the wrapper. 51 ''; 52 }; 53 54 extraSessionCommands = mkOption { 55 type = types.lines; 56 default = ""; 57 example = '' 58 # SDL: 59 export SDL_VIDEODRIVER=wayland 60 # QT (needs qt5.qtwayland in systemPackages): 61 export QT_QPA_PLATFORM=wayland-egl 62 export QT_WAYLAND_DISABLE_WINDOWDECORATION="1" 63 # Fix for some Java AWT applications (e.g. Android Studio), 64 # use this if they aren't displayed properly: 65 export _JAVA_AWT_WM_NONREPARENTING=1 66 ''; 67 description = '' 68 Shell commands executed just before Sway is started. See 69 <link xlink:href="https://github.com/swaywm/sway/wiki/Running-programs-natively-under-wayland" /> 70 and <link xlink:href="https://github.com/swaywm/wlroots/blob/master/docs/env_vars.md" /> 71 for some useful environment variables. 72 ''; 73 }; 74 75 extraOptions = mkOption { 76 type = types.listOf types.str; 77 default = []; 78 example = [ 79 "--verbose" 80 "--debug" 81 "--unsupported-gpu" 82 "--my-next-gpu-wont-be-nvidia" 83 ]; 84 description = '' 85 Command line arguments passed to launch Sway. Please DO NOT report 86 issues if you use an unsupported GPU (proprietary drivers). 87 ''; 88 }; 89 90 extraPackages = mkOption { 91 type = with types; listOf package; 92 default = with pkgs; [ 93 swaylock swayidle alacritty dmenu 94 rxvt-unicode # For backward compatibility (old default terminal) 95 ]; 96 defaultText = literalExample '' 97 with pkgs; [ swaylock swayidle rxvt-unicode alacritty dmenu ]; 98 ''; 99 example = literalExample '' 100 with pkgs; [ 101 i3status i3status-rust 102 termite rofi light 103 ] 104 ''; 105 description = '' 106 Extra packages to be installed system wide. See 107 <link xlink:href="https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway" /> and 108 <link xlink:href="https://github.com/swaywm/sway/wiki/i3-Migration-Guide#common-x11-apps-used-on-i3-with-wayland-alternatives" /> 109 for a list of useful software. 110 ''; 111 }; 112 113 }; 114 115 config = mkIf cfg.enable { 116 assertions = [ 117 { 118 assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; 119 message = '' 120 The extraSessionCommands for Sway will not be run if 121 wrapperFeatures.base is disabled. 122 ''; 123 } 124 ]; 125 environment = { 126 systemPackages = [ swayPackage ] ++ cfg.extraPackages; 127 etc = { 128 "sway/config".source = mkOptionDefault "${swayPackage}/etc/sway/config"; 129 "sway/config.d/nixos.conf".source = pkgs.writeText "nixos.conf" '' 130 # Import the most important environment variables into the D-Bus and systemd 131 # user environments (e.g. required for screen sharing and Pinentry prompts): 132 exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP 133 ''; 134 }; 135 }; 136 security.pam.services.swaylock = {}; 137 hardware.opengl.enable = mkDefault true; 138 fonts.enableDefaultFonts = mkDefault true; 139 programs.dconf.enable = mkDefault true; 140 # To make a Sway session available if a display manager like SDDM is enabled: 141 services.xserver.displayManager.sessionPackages = [ swayPackage ]; 142 programs.xwayland.enable = mkDefault true; 143 # For screen sharing (this option only has an effect with xdg.portal.enable): 144 xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ]; 145 }; 146 147 meta.maintainers = with lib.maintainers; [ primeos colemickens ]; 148}