Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
theurgi opened this issue Sep 27, 2024 · 9 comments
Open
2 tasks done

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

theurgi opened this issue Sep 27, 2024 · 9 comments
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@theurgi
Copy link

theurgi commented Sep 27, 2024

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

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:

  • Verified that the packages are in the Nix store
  • Checked for the presence of the commands using which
  • Attempted to start the services manually
  • Checked for configuration files in ~/.config/hypr/

System Information:

  • NixOS Version: 24.05
  • Home Manager Version: 24.05
  • Hyprland Version: 0.43.0

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:

  • hyprlock.nix:
{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";
      };
    };
  };
}
  • hypridle.nix:
{
  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`
@theurgi theurgi added bug triage Issues or feature request that have not been triaged yet labels Sep 27, 2024
@fufexan
Copy link
Contributor

fufexan commented Sep 27, 2024

Do you have your nixos/hm config anywhere?

@theurgi
Copy link
Author

theurgi commented Sep 27, 2024

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
Copy link
Contributor

fufexan commented Sep 28, 2024

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
Copy link
Author

theurgi commented Sep 30, 2024

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
Copy link
Author

theurgi commented Sep 30, 2024

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
Copy link
Contributor

fufexan commented Sep 30, 2024

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?

@shroomist
Copy link

having similar issue with hypridle - home-manager for whatever reason doesn't run the service.
current workaround:
configuration.nix

    services.hypridle = {
      enable = true;
};

hyprland.conf

exec-once = hypridle

and configuring timers the regular way in hypridle.conf

would love to have it configured via home-manager.

@Alpha-Ursae-Minoris
Copy link

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?

Having the same issue with hyprpaper, so at least the issue is consistent.

For references here is the config for hyprpaper that I am using:

{
  services.hyprpaper = {
    enable = true;
    settings = {
      preload = [ "~/wallpapers/wallpaper.png" ];
      wallpaper = [ " , ~/wallpapers/wallpaper.png" ];
    };
  };
}

If I run nix-shell -p hyprpaper and then hyprpaper the config loads as specified in the service.

Using the addition of

{
  home.packages = with pkgs; [ hyprpaper ];

  wayland.windowManager.hyprland.settings = {
    exec-once = [ "hyprpaper" ];
  };
}

in my Home Manager config therefore fixes the issue.

srid added a commit to srid/nixos-config that referenced this issue Oct 24, 2024
@sagikazarmark
Copy link

I'm not sure if it's related to this particular issue, but I see this in hypridle's logs:

/bin/sh: line 1: hyprlock: command not found

I guess it's related to this: https://wiki.hyprland.org/Nix/Hyprland-on-Home-Manager/#programs-dont-work-in-systemd-services-but-do-on-the-terminal

Although I use HM to configure Hyprland, it still didn't work for me.

This is how I solved it for now:

  services.hypridle = {
    enable = true;

    settings = {
      general = {
        # avoid starting multiple hyprlock instances.
        lock_cmd = "${pkgs.procps}/bin/pidof ${pkgs.hyprlock}/bin/hyprlock || ${pkgs.hyprlock}/bin/hyprlock";
        unlock_cmd = "pkill - USR1 ${pkgs.hyprlock}/bin/hyprlock";

        before_sleep_cmd = "loginctl lock-session"; # lock before suspend.
        after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display.
      };
    };

    # TODO: move to settings?
    extraConfig = (builtins.readFile ../../../../dotfiles/hypr/hypridle.conf);
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

8 participants