svg

Create Desktop Files With Home Manager

linux home-manager

I want to create .desktop files for shutdown/reboot/sleep so that i can quickly do those action via Rofi. After surfing the internet, I found this useful post and this docs

Based on that, I created a ~/.config/home-manager/power-action.nix

# NOTE: this will create desktop entry for power action
# So I can reboot/shutdown/sleep via Rofi

{ config, pkgs, ... }:

{
  xdg.desktopEntries = {
    reboot = {
      name = "Reboot System";
      comment = "Reboot the system";
      exec = "systemctl reboot";
      icon = "system-reboot";
      terminal = false;
      type = "Application";
      categories = [ "System" ];
    };

    shutdown = {
      name = "Shutdown System";
      comment = "Power off the system";
      exec = "systemctl poweroff";
      icon = "system-shutdown";
      terminal = false;
      type = "Application";
      categories = [ "System" ];
    };

    sleep = {
      name = "Sleep";
      comment = "Suspend the system";
      exec = "systemctl suspend";
      icon = "system-suspend";
      terminal = false;
      type = "Application";
      categories = [ "System" ];
    };

    hibernate = {
      name = "Hibernate";
      comment = "Hibernate the system";
      exec = "systemctl hibernate";
      icon = "system-hibernate";
      terminal = false;
      type = "Application";
      categories = [ "System" ];
    };
  };
}

And then import that to home.nix

{ config, pkgs, ... }:

{
  imports = [
    ./fish.nix
    ./tmux.nix
    ./git.nix
    ./power-action.nix
  ];
}

After I ran home-manager switch, the files ends up at ~/.local/state/nix/profiles/home-manager/home-path/share/applications/ and that share dir is automatically added to XDG_DATA_DIRS.

Now, I can quickly shutdown/reboot/sleep via Rofi.