Error while writing hyprland config

Hi there! I’m having issues setting up hyprland with nixos via home-manager. Any help appreciated!

All files are stored in /etc/nixos

Basically, I’m having a (system managed) home configuration

Home-Configuraiton (hyprland.nix)

{config, pkgs, ... }: 
{
  wayland.windowManager.hyprland = {
    enable = true;
    package = pkgs.hyprland;
    xwayland.enable = true;

    systemd.enable = true;
    settings = {
      input = {
        kb_layout = "de";
      };
    };
  };
}

which will be imported in my home-manager.nix configuration

Home-Configuraiton (home-manager.nix)

{ config, lib, pkgs, jsonConfig, ... }:
let
	home-manager-src = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-${jsonConfig.system.version}.tar.gz";
	home-manager = import home-manager-src { inherit pkgs; };
	hyprlandConfig = import ./home/hyprland.nix { inherit config lib pkgs; };
in
{
	imports = [
		(import "${home-manager-src}/nixos")
	];

	# Enable the home-manager command globally
	home-manager.useGlobalPkgs = true;
	home-manager.useUserPackages = true;
	home-manager.backupFileExtension = "backup";

	# Add home-manager binary to the system-wide environment
	environment.systemPackages = with pkgs; [
		home-manager.home-manager
	];
	

	# Configure home manager for the user
	home-manager.users.${jsonConfig.user.username} = {
		home.username = jsonConfig.user.username;
		home.homeDirectory = "/home/${jsonConfig.user.username}";
		home.stateVersion = jsonConfig.system.version;

		...

		imports = [
			...
			hyprlandConfig
		];

	};
}

which is part of my configuration.nix

System Configuration (configuration.nix)

{ config, lib, pkgs, ... }:

let
	configFile = ./config.json;
	jsonConfig = builtins.fromJSON (builtins.readFile configFile);
in
{
	imports = [
		(import ./home-manager.nix { inherit config lib pkgs jsonConfig; })
		...
	]
	nixpkgs.config.allowUnfree = true;
	system.stateVersion = jsonConfig.system.version;
}

Everytime, ~/.config/hypr/hyprland.conf will be written, journalctrl shows the following error

Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Creating home file links in /home/<user>
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating onFilesChange
Aug 19 20:10:56 PowerTower hm-activate-<user>[188426]: jq: parse error: Unmatched ']' at line 2, column 1
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating reloadSystemd

thus the systemd service fails to start

systemctl status home-manager-<user>.service
● home-manager-<user>.service - Home Manager environment for <user>
     Loaded: loaded (/etc/systemd/system/home-manager-<user>.service; enabled; preset: enabled)
     Active: active (exited) since Mon 2024-08-19 20:10:56 CEST; 8min ago
    Process: 188251 ExecStart=/nix/store/8yp9zb8805nl91dpdzips42gx8v0v116-hm-setup-env /nix/store/c500ab1qxdf6gbvfmpnf9qfkqmsq22dm-home-manager-generation (code=exited, status=0/SUCCESS)
   Main PID: 188251 (code=exited, status=0/SUCCESS)
         IP: 0B in, 0B out
        CPU: 424ms

Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating writeBoundary
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating installPackages
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating linkGeneration
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Cleaning up orphan links from /home/<user>
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Creating profile generation 52
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Creating home file links in /home/<user>
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating onFilesChange
Aug 19 20:10:56 PowerTower hm-activate-<user>[188426]: jq: parse error: Unmatched ']' at line 2, column 1
Aug 19 20:10:56 PowerTower hm-activate-<user>[188251]: Activating reloadSystemd
Aug 19 20:10:56 PowerTower systemd[1]: Finished Home Manager environment for <user>.

I do not use jq activily for anything, thus I don’t know where this error comes from, how to find out or how to fix it.

The only json related part in my config as that I’m using a file “config.json” as input to configure the username, email, hostname, keys and wheter or not to install some packages to easily manage multiple different setups. I could already rule this out as a potential cause.

Basically, i tried to follow this guide on how to configure hyprland Hyprland - NixOS Wiki

Also, even tough running sudo nixos-rebuild switch triggers the issue the command it self exits normally.

Is the first code block what’s imported in this line?

Yes, I’m trying to update my question for better clarification

At this point I would dig through home-manager source code for that onFilesChange thing to see where it uses jq.

Isn’t there some way to get more information out of hm-activate? I tried do run nixos-rebuild verbose or with trace but no additional info about that activation process has been printed.

Don’t be afraid to dig through the source like I suggested.

I did,

It seems like the home manager at some point executes
/nix/store/vyws1n659vxcqzliagdaxmb7bjlg4iy8-home-manager-generation/activate

which has the lines

324-  if [[ -d "/tmp/hypr" || -d "$XDG_RUNTIME_DIR/hypr" ]]; then
325-    for i in $(/nix/store/f6v5nm08sz8bsvb87696yj7g7n39dw96-hyprland-0.41.2/bin/hyprctl instances -j | jq ".[].instance" -r); do
326-      /nix/store/f6v5nm08sz8bsvb87696yj7g7n39dw96-hyprland-0.41.2/bin/hyprctl -i "$i" reload config-only
327-    done
328-  fi

Testing some examples with this expression shows:

  • echo '[{ "instance": "1" }, { "instance": "2" }]' | jq ".[].instance" -r succeeds
  • echo ']' | jq ".[].instance" -r triggers the same issue

This could imply that running hyprctl (/nix/store/f6v5nm08sz8bsvb87696yj7g7n39dw96-hyprland-0.41.2/bin/hyprctl instances -j) sends an invalid json. Unfortunately, i cannot run it directly because i need to emulate the environment around the activation process …