Video_74.md

Video 74 reference

Follow this pull request that brings wlr-which-key options to home-manager!

https://github.com/nix-community/home-manager/pull/5677

Watch the video

Examples

Flake with a package

{
  description = "A very cool Nix flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs, ... }: 
    let
      pkgs = nixpkgs.legacyPackages."x86_64-linux";

      mkMenu = menu: let
        configFile = pkgs.writeText "config.yaml"
          (pkgs.lib.generators.toYAML {} {
            anchor = "bottom-right";
            # ...
            inherit menu;
          });
      in
        pkgs.writeShellScriptBin "my-menu" ''
          exec ${pkgs.lib.getExe pkgs.wlr-which-key} ${configFile}
        '';
    in {
      packages.x86_64-linux.default = mkMenu [
        {
          key = "f";
          desc = "Firefox";
          cmd = "firefox";
        }
      ];
    };
}

Home-manager module (Hyprland)

Example home-manager module with a key bound to a custom menu.

{ pkgs, lib, ... }: 

let
  mkMenu = menu: let
    configFile = pkgs.writeText "config.yaml"
      (lib.generators.toYAML {} {
        anchor = "bottom-right";
        # ...
        inherit menu;
      });
  in
    pkgs.writeShellScriptBin "my-menu" ''
      exec ${lib.getExe pkgs.wlr-which-key} ${configFile}
    '';
in
{
  wayland.windowManager.hyprland.settings.bind = [
    ("SUPERSHIFT, D, exec, " + lib.getExe (mkMenu [
       {
         key = "f";
         desc = "Firefox";
         cmd = "firefox";
       }
    ]))
  ];
}

Wrappers flake (Niri)

Example wrapped Niri with a key bound to a custom menu.

{
  description = "A very cool Nix flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    wrappers.url = "github:Lassulus/wrappers";
  };

  outputs = { self, nixpkgs, wrappers, ... }:
  let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};

    mkMenu = menu: let
      configFile = pkgs.writeText "config.yaml"
        (pkgs.lib.generators.toYAML {} {
          anchor = "bottom-right";
          # ...
          inherit menu;
        });
    in
      pkgs.writeShellScriptBin "my-menu" ''
        exec ${pkgs.lib.getExe pkgs.wlr-which-key} ${configFile}
      '';
  in {
    packages.${system}.default =
      (wrappers.wrapperModules.niri.apply {
        inherit pkgs;
        settings = {
          binds = {
            "Mod+d".spawn-sh = pkgs.lib.getExe (mkMenu [
              {
                key = "f";
                desc = "Firefox";
                cmd = "firefox";
              }
            ]);
          };
        };
      }).wrapper;
  };
}

Run niri with

$ nix run /path/to/flake