[Question] XDG_RUNTIME_DIR not set during nixos-rebuild --flake only when including home manager module.
## Background
Apologies in advance if this isn't a home-manager problem, I'm a bit new to NixOS and home manager, so I might be chasing a red herring. If I need to search for answers elsewhere, I will gladly close the issue and open another somewhere else.
While working on a fresh install of NixOS (installed via the gui installer) that started with no desktop environment, I have been trying to build a minimal system with a flake running Hyprland. However, after trying to include home manager, my `nixos-rebuilds` have been failing with the following stack trace.
These failing builds also show up as generations when I turn on the machine after building, but have never successfully included build details from the home manager file.
```
home-manager-REDACTED_USER.service - Home Manager environment for REDACTED_USER
Loaded: loaded (/etc/systemd/system/home-manager-REDACTED_USER.service; enabled; preset: ignored)
Active: failed (Result: core-dump) since Wed 2026-05-20 19:35:58 EDT; 272ms ago
Invocation: b0b3cfcfb8234ebc95932f0474d1940e
Process: 25503 ExecStart=/nix/store/wzc6y7xbcb6n0xynw46yvr1b7zpzalrk-hm-setup-env /nix/store/xcsmkq77wa51xiji6wjprqj2wcxlb57j-home-manager-generation (code=dumped, signal=ABRT)
Main PID: 25503 (code=dumped, signal=ABRT)
IP: 0B in, 0B out
IO: 0B read, 0B written
Mem peak: 12.8M
CPU: 54ms
May 20 19:35:58 REDACTED_USER systemd[1]: Starting Home Manager environment for REDACTED_USER...
May 20 19:35:58 REDACTED_USER hm-activate-REDACTED_USER[25503]: CRIT ]: Critical error thrown: XDG_RUNTIME_DIR is not set!
May 20 19:35:58 REDACTED_USER hm-activate-REDACTED_USER[25503]: terminate called after throwing an instance of 'std::runtime_error'
May 20 19:35:58 REDACTED_USER hm-activate-REDACTED_USER[25503]: what(): XDG_RUNTIME_DIR is not set!
May 20 19:35:58 REDACTED_USER systemd[1]: home-manager-REDACTED_USER.service: Main process exited, code=dumped, status=6/ABRT
May 20 19:35:58 REDACTED_USER systemd[1]: home-manager-REDACTED_USER.service: Failed with result 'core-dump'.
May 20 19:35:58 vimnovice systemd[1]: Failed to start Home Manager environment for REDACTED_USER.
Command 'systemd-run -E LOCALE_ARCHIVE -E NIXOS_INSTALL_BOOTLOADER -E NIXOS_NO_CHECK --collect --no-ask-password --pipe --quiet --service-type=exec --unit=nixos-rebuild-switch-to-configuration /nix/store/9mp8rx0fd5b1c7gwkdd5qr5jsynp8zyw-nixos-system-REDACTED_USER-26.05.20260515.d233902/bin/switch-to-configuration switch' returned non-zero exit status 4.
```
As a side note, I tried to swap to 26.05 via changing the nixpkg's url (probably bad practice) during one rebuild where I attempted to solve this. I'm not sure if that might have messed up some system state, but it seems to have not affected anything after I switched back.
I have the following flake.nix and home.nix:
#### `Flake.nix`
```
{
description = "NixOS development machine";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
hyprland= {
url = "github:hyprwm/Hyprland";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {nixpkgs, home-manager, ...} @ inputs: {
nixosConfigurations.REDACTED_USER = nixpkgs.lib.nixosSystem{
specialArgs = { inherit inputs; };
modules = [
./configuration.nix
home-manager.nixosModules.home-manager
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.REDACTED_USER = import ./home.nix;
backupFileExtension = "backup";
};
}
];
};
};
}
```
#### `Home.nix`
```
{inputs, config, pkgs, ...}:
{
home.username = "vimnovice";
home.homeDirectory = "/home/vimnovice";
home.stateVersion = "25.11";
xdg.enable = true;
programs.bash = {
enable = true;
shellAliases = {
btw = "echo i use nixos with hyperland btw";
};
profileExtra = ''
if [ -z "$WAYLAND_DISPLAY" ] && [ "XDG_VTNR" = 1 ]; then
exec hyprland
fi
'';
};
home.file.".config/hypr".source = ./config/hypr;
home.file.".config/waybar".source = ./config/waybar;
home.file.".config/foot".source = ./config/foot;
}
```
I've tried commenting out various parts of home.nix to see if the build process was trying to invoke hyprland in a context where `XDG_*` vars hadn't been set, but even commenting out everything not related to setting the `username`, `homeDirectory`, and `stateVersion` from `home.nix`, but still encounter the error on a rebuild. However, commenting out the home manager module in `flake.nix` allows the rebuild to complete without any errors.
One other oddity is that the shell alias defined in home.nix is present/works in my shell after starting the machine.
Finally, here are the entries I have in `configuration.nix` related to hyprland.
#### `Configuration.nix`
```
environment.systemPackages = with pkgs; [
helix
...
foot
kitty
waybar
hyprpaper
];
...
#enable hyprland
programs.hyprland= {
enable = true;
withUWSM = true;
xwayland.enable = true;
package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland;
portalPackage = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland;
};
# enable lock screen and idle manager for hyprland
programs.hyprlock.enable = true;
services.hypridle.enable = true;
```
Changing the settings related to hyprland in `configuration.nix` hasn't changed this behavior, regardless if I'm trying to use UWSM (and subsequentially launch hyprland with UWSM in the home.nix file) or not.
Thanks for any help!
0 条评论