nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.06k stars 1.82k forks source link

i3 default keybind can't be overriden #485

Closed dali99 closed 5 years ago

dali99 commented 5 years ago

When I tried running home-manager switch today I was met with

error: The unique option `xsession.windowManager.i3.config.keybindings.Mod4+Return' is defined multiple times, in `/nix/store/zkqd8z8a0l9jrm0ba5d3g707ild5aqwg-master.tar.gz/modules/services/window-managers/i3.nix' and `/home/daniel/.config/nixpkgs/nix-dotfiles/home.nix'.
(use '--show-trace' to show detailed location information)

I'd think that the home.nix would override the default home-manager config.

xsession = {
    enable = true;
    windowManager = {
      i3.enable = true;
      i3.config = {
        modifier = "Mod4";
        keybindings = let modifier = "Mod4"; #xsession.windowManager.i3.config.modifier;
        in lib.mkOptionDefault {
          "${modifier}+0" = "workspace 10";

          "${modifier}+Tab" = "workspace next";
          "${modifier}+Shift+Tab" = "workspace prev";

          "XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume 0 +5%";
          "XF86AudioLowerVolume" = "exec --no-startup-id pactl set-sink-volume 0 -5%";
          "XF86AudioMute" = "exec --no-startup-id pactl set-sink-mute 0 toggle";
          "XF86AudioMicMute" = "exec --no-startup-id pactl set-source-mute 1 toggle";

          "XF86MonBrightnessUp" = "exec --no-startup-id xbacklight -inc 5";
          "XF86MonBrightnessDown" = "exec --no-startup-id xbacklight -dec 5";

          "XF86Display" = "exec arandr";

          "Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f /home/daniel/Pictures/screenshots/'";
          "${modifier}+Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f /home/daniel/Pictures/screenshots/'";

          "${modifier}+n" = "exec dolphin";
          "${modifier}+b" = "exec firefox";
          "${modifier}+t" = "exec gedit";

          "${modifier}+Return" = "exec i3-sensible-terminal -e zsh";
          "${modifier}+Shift+Return" = "exec i3-sensible-terminal -e ssh daniel@adam";
        };
      };
    };
  };
rycee commented 5 years ago

Hmm, you are using mkOptionDefault? Howcome? If you use mkDefault instead or leave it oh all together then I think it should work OK 😃

On December 6, 2018 10:16:42 PM GMT+01:00, "Daniel Løvbrøtte Olsen" notifications@github.com wrote:

When I tried running home-manager switch today I was met with

error: The unique option
`xsession.windowManager.i3.config.keybindings.Mod4+Return' is defined
multiple times, in
`/nix/store/zkqd8z8a0l9jrm0ba5d3g707ild5aqwg-master.tar.gz/modules/services/window-managers/i3.nix'
and `/home/daniel/.config/nixpkgs/nix-dotfiles/home.nix'.
(use '--show-trace' to show detailed location information)

I'd think that the home.nix would override the default home-manager config.

xsession = {
   enable = true;
   windowManager = {
     i3.enable = true;
     i3.config = {
       modifier = "Mod4";
keybindings = let modifier = "Mod4";
#xsession.windowManager.i3.config.modifier;
       in lib.mkOptionDefault {
         "${modifier}+0" = "workspace 10";

         "${modifier}+Tab" = "workspace next";
         "${modifier}+Shift+Tab" = "workspace prev";

"XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume 0
+5%";
"XF86AudioLowerVolume" = "exec --no-startup-id pactl set-sink-volume 0
-5%";
"XF86AudioMute" = "exec --no-startup-id pactl set-sink-mute 0 toggle";
"XF86AudioMicMute" = "exec --no-startup-id pactl set-source-mute 1
toggle";

     "XF86MonBrightnessUp" = "exec --no-startup-id xbacklight -inc 5";
   "XF86MonBrightnessDown" = "exec --no-startup-id xbacklight -dec 5";

         "XF86Display" = "exec arandr";

"Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f
/home/daniel/Pictures/screenshots/'";
"${modifier}+Print" = "exec scrot %Y-%m-%d_$wx$h_scrot.png -z -e 'mv $f
/home/daniel/Pictures/screenshots/'";

         "${modifier}+n" = "exec dolphin";
         "${modifier}+b" = "exec firefox";
         "${modifier}+t" = "exec gedit";

         "${modifier}+Return" = "exec i3-sensible-terminal -e zsh";
"${modifier}+Shift+Return" = "exec i3-sensible-terminal -e ssh
daniel@adam";
       };
     };
   };
 };

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/rycee/home-manager/issues/485

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

dali99 commented 5 years ago

The example in the manual is

let
  modifier = xsession.windowManager.i3.config.modifier;
in

lib.mkOptionDefault {
  "${modifier}+Return" = "exec i3-sensible-terminal";
  "${modifier}+Shift+q" = "kill";
  "${modifier}+d" = "exec \${pkgs.dmenu}/bin/dmenu_run";
}

so I just copied that :)

but yes MkDefault worked thanks!

dali99 commented 5 years ago

And also just not having it :smile:

rycee commented 5 years ago

Ah, yeah! The example will need a bit of rethinking. Glad it worked out for you 😃 Please leave the ticket open, though. I'll have a look at this at some later point. @uvNikita This might be interesting for you as well.

On December 6, 2018 10:31:30 PM GMT+01:00, "Daniel Løvbrøtte Olsen" notifications@github.com wrote:

The example in the manual is

let
 modifier = xsession.windowManager.i3.config.modifier;
in

lib.mkOptionDefault {
 "${modifier}+Return" = "exec i3-sensible-terminal";
 "${modifier}+Shift+q" = "kill";
 "${modifier}+d" = "exec \${pkgs.dmenu}/bin/dmenu_run";
}

so I just copied that :)

but yes MkDefault worked thanks!

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/rycee/home-manager/issues/485#issuecomment-445036734

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

dali99 commented 5 years ago

yeah actually I didn't test that enough sorry ^^

mkOption and leaving it empty makes it override the entire setting, so the default keybindings don't work. :confused:

uvNikita commented 5 years ago

Yeah, I think home.nix should be able to redefine keybindings. Right now, I guess you have to add lib.mkForce for every override you are making, which is not a nice user experience. E.g. something like this should work:

"${modifier}+Tab" = lib.mkForce "workspace next";

My guess is that to fix this, we would have to add mkDefault to every keybinding defined in the i3 module.

dali99 commented 5 years ago

This used to work btw, it just broke during the past month or so.

but I'll try your workaround for now

EDIT:

Using lib.mkOptionDefault and lib.mkForce like above did work

uvNikita commented 5 years ago

@dali99 yes, I think this commit changed the behavior: https://github.com/rycee/home-manager/commit/c108eaba425cccf7512e02f173043ee2fb536f85.

uvNikita commented 5 years ago

I created a PR that should fix this issue, so lib.mkForce will not be needed.