Override Type in sway configuration setting

i’m trying to set the modifier key in sway to “Mod1+Ctrl”, which i have been using for years.
Unfortunately the package configuration option does not allow that value:

error: A definition for option `wayland.windowManager.sway.config.modifier' is not of type `one of "Shift", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5"'.

i tried “Mod1+Control”, [ “Mod1” “Control” ], and i have been looking in nix.dev for a way to force a ‘invalid’ value.

then i set the modifier in keybindings:

but that resulted in duplicate entries in the generated .config/sway/config:

bindsym Mod1+1 workspace number 1
bindsym Ctrl+Mod1+1 workspace number 1

Ctrl+Mod1+1 being the one that i want.
Mod1+1 being the default value if the modifier is not set in the homemanager/sway configuration:

config = {
    # modifier = "Mod1+Control" 

As you can probably tell i’m new to nixos.
How should i do this?


Looks like an oversight to me. I’d suggest opening an issue upstream, and maybe sending a PR to change the type to a simple type.str to actually solve this: home-manager/modules/services/window-managers/i3-sway/lib/options.nix at 5d151429e1e79107acf6d06dcc5ace4e642ec239 · nix-community/home-manager · GitHub

You can then just switch to using your branch downstream until that gets merged.

Doing this downstream is possible, but not trivial, since you’ll have to overwrite an existing option. Changing modules is a tad more annoying than packages, sadly.

It looks to me also that the modifier option is unnecessary restrictive, and could be a string. My short term solution would be like this:

  wayland.windowManager.sway.config.keybindings =
      modifier = "Mod1+Ctrl";
      "${modifier}+Return" = "exec ${pkgs.foot}/bin/foot";
      # ... etc.

1 Like

Thank you both.
I switched the type as TLATER advised, but wasn’t happy with the keybindings that are being generated (e.g. mod+d for dmenu).

So i ended up replacing keybindings alltogether like dsparby suggested.