nix-community / home-manager

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

i3/sway add 'set' option #4435

Open borg1622 opened 1 year ago

borg1622 commented 1 year ago

In i3wm (and sway) you can define i3 variables with the set operator. I use this for example in complex statements like this one:

set $alt Mod1      # alias for second modifier key
...
set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (F12) shutdown

Certainly the nix way would be defining nix variables instead. But I want to get a resulting i3 configuration file which uses i3 variables - so that this configuration file is still suitable for use in other systems outside the nix universe.

Example

Currently I have to split a whole keybinding mode expression this way.


xsession.windowManager.i3 = {
    extraConfig = ''
        set $Locker /etc/i3/lock.sh && sleep 1
        set $Suspend /etc/i3/lock.sh -l && systemctl suspend
        set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (F12) shutdown
    '';
    config = {
        keybindings = {
            "$mod+Pause"          = "mode \"$mode_system\"";
            "$mod+Shift+e"        = "mode \"$mode_system\""; 
        };
        modes = {
            "$mode_system" = { 
            "l"       = "exec --no-startup-id $Locker, mode default";
            "e"       = "exec --no-startup-id autorandr -l Mobile-UHD && i3-msg exit, mode default"; 
            "s"       = "exec --no-startup-id $Suspend, mode default";
            "h"       = "exec --no-startup-id $Locker && systemctl hibernate, mode default";
            "r"       = "exec --no-startup-id systemctl reboot, mode default";
            "F12"     = "exec --no-startup-id systemctl poweroff -p, mode default";

            #back to normal: Enter or Escape
            "Return"  = "mode default";
            "Escape"  = "mode default";
          };
       };
    };
};
teto commented 1 year ago

as a possible workaround xdg.configFile."i3/config" = mkBefore ''set toto tata";

stale[bot] commented 10 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.