Skip to content

nix-env fails when HOME is not set, even if passed a profile path #224

Closed

Description

@wizeman

I would expect this to work:
env -u HOME nix-env -p /nix/var/nix/profiles/default --list-generations
However, it fails with this error message:
error: HOME environment variable not set

In particular, I've seen this problem in NixOS's nix-gc systemd service, which does the following:

script = "exec ${config.nix.package}/bin/nix-collect-garbage ${cfg.options}";

If ${cfg.options} is "-d", the actual nix-env commands to delete old generations will fail with the error message above.

The problem seems to be here:

globals.instSource.nixExprPath = getDefNixExprPath();

getDefNixExprPath(), which calls getHomeDir(), gets called regardless of command line arguments, and fails if HOME is not set.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions