nix-community / home-manager

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

bug: hyprlock and hypridle not working in NixOS with Home Manager #5899

Open theurgi opened 5 days ago

theurgi commented 5 days ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I'm having issues getting hyprlock and hypridle to work in my NixOS setup using Home Manager. I'm able to build the system without any errors and the packages are present in the Nix store, but the commands and services are not found, and no configuration is generated.

Potentially related issues:

What I've Tried:

System Information:

Service Status:

❯ systemctl --user list-unit-files | grep hypr
hyprpaper.service enabled enabled
xdg-desktop-portal-hyprland.service linked-runtime enabled
hyprland-session.target linked enabled

No Configs Generated:

❯ ls ~/.config/hypr                          
hyprland.conf  hyprland.conf.backup  hyprpaper.conf

Nix Store:

❯ ls /nix/store | rg -e '(hyprlock|hypridle)'
0bxazkddh9vlf708x3grkxvd8pz1x0li-hypridle-0.1.2
28g46b8p4hll15nwrw1iszvsgg7ddd77-hm_hyprhypridle.conf
a938cm6w4h4i51n106ksmc6cs6isx5j4-hyprlock-0.4.1.drv
akqffmrgvnh35fc1blfc75n40id3y3w8-hypridle-0.1.2
d7ydd20qwvhaiwccqj6m8r4kailci2ah-hyprlock-0.4.1
hdgb95i2g1l7z30slgc0z8v3xlyxglqz-hypridle.service.drv
jq5r1pfx9cww7xcljzhg6awv03jgg8fc-hypridle-0.1.2.drv
k1y1z0wsqwggydghnr50p7p4nd1fpn7a-hypridle.service
md2d79am59a7wkavc76348rmlw9yz7dr-hypridle-0.1.2.drv
rlwj88g6rk0jbq45a6ld4wiafn8dzxbz-hm_hyprhyprlock.conf.drv
w9wc84dy0vl6i0ldf69zzfqknhyrxidi-hyprlock-0.4.1
x7dbsshj8ynv9fhzij06lxcg99bckxla-hm_hyprhyprlock.conf
xmrszayh6f4812rgja0g8id8r55xmcsh-hm_hyprhypridle.conf.drv
zwxmi3bbgc695c4xw1sym4dvhkghdarm-hyprlock-0.4.1.drv

Configuration:

{config, ...}: let
  inherit (config.lib.stylix.colors) base00 base01 base05 base07;
in {
  programs.hyprlock = {
    enable = true;

    settings = {
      background = {
        path = "screenshot";

        blur_passes = 2;
        blur_size = 7;

        brightness = 0.8;
        contrast = 0.8;

        color = "${base00}99";
      };

      input-field = {
        size = {
          width = 200;
          height = 50;
        };

        outline_thickness = 3;
        dots_size = 0.33;
        dots_spacing = 0.15;
        dots_center = false;
        outer_color = "${base01}";
        inner_color = "${base07}";
        font_color = "${base00}";
        fade_on_empty = true;
        placeholder_text = "<i>Input Password...</i>";
        hide_input = false;
        position = {
          x = 0;
          y = -20;
        };
        halign = "center";
        valign = "center";
      };

      label = {
        text = "$TIME";
        color = "${base05}";
        font_size = 50;
        font_family = "Noto Sans";
        position = {
          x = 0;
          y = 80;
        };
        halign = "center";
        valign = "center";
      };
    };
  };
}
{
  services.hypridle = {
    enable = true;

    settings = {
      general = {
        lock_cmd = "hyprlock";

        before_sleep_cmd = "hyprlock";
        after_sleep_cmd = "hyprctl dispatch dpms on";
      };

      listener = [
        {
          timeout = 600;
          on-timeout = "hyprlock";
        }
        {
          timeout = 900;
          on-timeout = "hyprctl dispatch dpms off";

          on-resume = "hyprctl dispatch dpms on";
        }
        {
          timeout = 1800;
          on-timeout = "systemctl suspend";
        }
      ];
    };
  };
}

Maintainer CC

@khaneliman @fufexan

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.6.52, NixOS, 24.11 (Vicuna), 24.11.20240919.c04d565`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - nixpkgs: `/nix/store/hiasfhl8f5yy88hcfbr3s8s4bm63wsjw-source`
fufexan commented 5 days ago

Do you have your nixos/hm config anywhere?

theurgi commented 5 days ago

Sure. I'm using a flakes-based setup with Home Manager integrated via the flake, not as a separate tool.

general structure

~/nixos-config
├── flake.nix
├── machines
│  ├── machine-p
│  ├── machine-x
│  ├── machine-y
│  └── machine-z
├── modules
│  ├── desktop
│  │  ├── hyprland.nix
│  │  ├── notifications.nix
│  │  ├── stylix.nix
│  │  └── thunar.nix
│  ├── development
│  ├── hardware
│  ├── keyboard
│  ├── networking
│  ├── security
│  ├── services
│  ├── shell
│  ├── system
│  ├── themes
│  └── virtualization
├── overlays
└── users
   ├── home-manager
   │  ├── admin
   │  │  ├── default.nix
   │  │  └── git.nix
   │  ├── shared
   │  │  ├── hypridle.nix
   │  │  ├── hyprland.nix
   │  │  ├── hyprlock.nix
   │  │  ├── hyprpaper.nix
   │  │  └── etc...
   │  ├── user-x
   │  │  ├── default.nix
   │  │  └── git.nix
   │  ├── user-y
   │  │  ├── default.nix
   │  │  └── git.nix
   │  └── user-z
   │     ├── default.nix
   │     └── git.nix
   └── profiles

configs

~/nixos-config/flake.nix

{
  description = "NixOS configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      url = "github:nix-community/nixvim";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    stylix.url = "github:danth/stylix";
    nur.url = "github:nix-community/NUR";
  };

  outputs = {
    self,
    nixpkgs,
    home-manager,
    nixvim,
    stylix,
    nur,
    ...
  } @ inputs: let
    supportedSystems = ["x86_64-linux" "aarch64-linux"];
    forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
    stateVersion = "24.05";

    # Function to get the last part of the hostname (e.g., "z" from "machine-z")
    getHostSuffix = hostName: let
      parts = builtins.split "-" hostName;
    in
      builtins.elemAt parts (builtins.length parts - 1);

    importNUR = pkgs:
      import nur {
        nurpkgs = pkgs;
        inherit pkgs;
      };

    mkSystem = {
      system,
      hostname,
      hasAdmin ? false,
    }: let
      pkgs = import nixpkgs {
        inherit system;
        config.allowUnfree = true;
        overlays = import ./overlays {inherit inputs;};
      };

      nurPkgs = importNUR pkgs;
    in
      nixpkgs.lib.nixosSystem {
        inherit system;

        specialArgs = {
          inherit inputs pkgs stateVersion nurPkgs;
        };

        modules = [
          # Machine-specific configuration
          ./machines/${hostname}

          # Home Manager module
          stylix.nixosModules.stylix
          home-manager.nixosModules.home-manager
          ({config, ...}: {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.backupFileExtension = "backup";
            home-manager.extraSpecialArgs = {
              inherit nixvim stylix stateVersion nurPkgs;
            };
            home-manager.users =
              {
                user = import ./users/home-manager/user-${getHostSuffix hostname}/default.nix;
              }
              // (
                if hasAdmin
                then {
                  admin = import ./users/home-manager/admin/default.nix;
                }
                else {}
              );
          })
        ];
      };
  in {
    nixosConfigurations = {
      machine-x = mkSystem {
        system = "x86_64-linux";
        hostname = "machine-x";
        hasAdmin = false;
      };
      machine-y = mkSystem {
        system = "x86_64-linux";
        hostname = "machine-y";
        hasAdmin = true;
      };
      machine-z = mkSystem {
        system = "x86_64-linux";
        hostname = "machine-z";
        hasAdmin = true;
      };
      machine-p = mkSystem {
        system = "aarch64-linux";
        hostname = "machine-p";
        hasAdmin = true;
      };
    };

    # Standalone Home Manager configuration
    homeConfigurations = forAllSystems (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      nurPkgs = importNUR pkgs;
    in {
      "user@machine-x" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = {
          inherit nixvim stylix stateVersion nurPkgs;
        };
        modules = [./users/home-manager/user-x/default.nix];
      };
      "user@machine-y" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = {
          inherit nixvim stylix stateVersion nurPkgs;
        };
        modules = [./users/home-manager/user-y/default.nix];
      };
      "user@machine-z" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = {
          inherit nixvim stylix stateVersion nurPkgs;
        };
        modules = [./users/home-manager/user-z/default.nix];
      };
      "admin" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = {
          inherit nixvim stylix stateVersion nurPkgs;
        };
        modules = [./users/home-manager/admin/default.nix];
      };
    });
  };
}

~/nixos-config/machines/machine-z/default.nix

{...}: {
  imports = [
    # Machine-specific configurations
    ./machine-specific/boot.nix
    ./machine-specific/hardware-configuration.nix
    ./machine-specific/intel.nix
    ./machine-specific/swap.nix
    ./machine-specific/users.nix

    # Desktop Environment
    ../../modules/desktop/hyprland.nix
    ../../modules/desktop/notifications.nix
    ../../modules/desktop/stylix.nix
    ../../modules/desktop/thunar.nix

    # etc ...
  ];
}

~/nixos-config/users/home-manager/user-z/default.nix

{
  config,
  pkgs,
  stylix,
  stateVersion,
  ...
}: let
  myThemesSessionVariables =
    if config ? myThemes
    then config.myThemes.sessionVariables
    else {};
in {
  imports = [
    ../shared/hypridle.nix
    ../shared/hyprland.nix
    ../shared/hyprlock.nix
    ../shared/hyprpaper.nix
    # etc ...
  ];

  programs.home-manager.enable = true;

  home.username = "user";
  home.homeDirectory = "/home/user";

  home.sessionVariables =
    {
      BROWSER = "librewolf";
      FILE_MANAGER = "yazi";
      NIXOS_VERSION = stateVersion;
      TERMINAL = "kitty";
    }
    // myThemesSessionVariables;

  home.stateVersion = stateVersion;
}

~/nixos-config/users/home-manager/shared/hyprland.nix

Both hyprland and hyprpaper work without issues and generate configs in ~/.config/hypr/

{pkgs, ...}: {
  home.packages = with pkgs; [
    grim
    slurp
    wl-clipboard
  ];

  wayland.windowManager.hyprland = {
    enable = true;
    settings = {
      monitor = [
        "eDP-1,2880x1800@60,0x0,2"
      ];
      exec-once = [
        "mako"
        "waybar"
      ];
      input = {
        kb_layout = "us";
        follow_mouse = 1;

        touchpad = {
          natural_scroll = false;
          disable_while_typing = true;
        };
      };
      general = {
        gaps_in = 3;
        gaps_out = 6;
        border_size = 2;
        "layout" = "dwindle";
      };
      animations = {
        enabled = false;
      };
      decoration = {
        blur = {
          enabled = false;
        };
        drop_shadow = false;
      };
      debug = {
        disable_logs = false;
      };
    };
  };
}
fufexan commented 4 days ago

I've just checked, and there doesn't seem to be any issue with the modules themselves. For example, checking the diff between hypridle and hyprpaper, the only differences are the names and the example config.

Now I'm checking the obvious, but have you enabled hypridle/hyprlock? What happens if you put the hyprlock settings in its extraConfig?

theurgi commented 2 days ago

Now I'm checking the obvious, but have you enabled hypridle/hyprlock?

Yes, programs.hyprlock.enable = true and services.hypridle.enable = true were both originally set if that's what you're asking.

Moving all hyprlock settings to the extraConfig did work -- hyprlock is functional, which hyprlock now returns /etc/profiles/per-user/admin/bin/hyprlock, and there's a generated config at ~/.config/hypr/hyprlock.conf.

However, there doesn't appear to be an extraConfig option for hypridle and it's still not found and generates no config after rebuilding the system.

theurgi commented 2 days ago

Correction: The hypridle config is generated at ~/.config/hypr/hypridle.conf without needing the extraConfig but the executable is still not in my path and the service is still not found:

admin@machine-z ~
❯ ls /nix/store | rg hypridle                
0bxazkddh9vlf708x3grkxvd8pz1x0li-hypridle-0.1.2
28g46b8p4hll15nwrw1iszvsgg7ddd77-hm_hyprhypridle.conf
akqffmrgvnh35fc1blfc75n40id3y3w8-hypridle-0.1.2
hdgb95i2g1l7z30slgc0z8v3xlyxglqz-hypridle.service.drv
jq5r1pfx9cww7xcljzhg6awv03jgg8fc-hypridle-0.1.2.drv
k1y1z0wsqwggydghnr50p7p4nd1fpn7a-hypridle.service
md2d79am59a7wkavc76348rmlw9yz7dr-hypridle-0.1.2.drv
xmrszayh6f4812rgja0g8id8r55xmcsh-hm_hyprhypridle.conf.drv

admin@machine-z ~
❯ which hypridle
hypridle not found

admin@machine-z ~
❯ systemctl status hypridle
Unit hypridle.service could not be found.
fufexan commented 1 day ago

As per the module, the package is not added to PATH, but only used by the service. The fact that the service does not appear might mean you have not logged out/in?