at 22.05-pre 5.2 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 ]; 95 defaultText = literalExpression '' 96 with pkgs; [ swaylock swayidle alacritty dmenu ]; 97 ''; 98 example = literalExpression '' 99 with pkgs; [ 100 i3status i3status-rust 101 termite rofi light 102 ] 103 ''; 104 description = '' 105 Extra packages to be installed system wide. See 106 <link xlink:href="https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway" /> and 107 <link xlink:href="https://github.com/swaywm/sway/wiki/i3-Migration-Guide#common-x11-apps-used-on-i3-with-wayland-alternatives" /> 108 for a list of useful software. 109 ''; 110 }; 111 112 }; 113 114 config = mkIf cfg.enable { 115 assertions = [ 116 { 117 assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; 118 message = '' 119 The extraSessionCommands for Sway will not be run if 120 wrapperFeatures.base is disabled. 121 ''; 122 } 123 ]; 124 environment = { 125 systemPackages = [ swayPackage ] ++ cfg.extraPackages; 126 # Needed for the default wallpaper: 127 pathsToLink = [ "/share/backgrounds/sway" ]; 128 etc = { 129 "sway/config".source = mkOptionDefault "${swayPackage}/etc/sway/config"; 130 "sway/config.d/nixos.conf".source = pkgs.writeText "nixos.conf" '' 131 # Import the most important environment variables into the D-Bus and systemd 132 # user environments (e.g. required for screen sharing and Pinentry prompts): 133 exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP 134 ''; 135 }; 136 }; 137 security.pam.services.swaylock = {}; 138 hardware.opengl.enable = mkDefault true; 139 fonts.enableDefaultFonts = mkDefault true; 140 programs.dconf.enable = mkDefault true; 141 # To make a Sway session available if a display manager like SDDM is enabled: 142 services.xserver.displayManager.sessionPackages = [ swayPackage ]; 143 programs.xwayland.enable = mkDefault true; 144 # For screen sharing (this option only has an effect with xdg.portal.enable): 145 xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ]; 146 }; 147 148 meta.maintainers = with lib.maintainers; [ primeos colemickens ]; 149}