How to list home manager configs in flake?

Hi!

I’m trying to write a script that automatically tries to install my home manger config for the appropriate user+machine combination. I can’t seem to find the right tool for listing the home manager configs in a shell script like I can with a NixOS config.

The closest I have gotten is a nix flake show --impure command which outputs the following:

git+file:///home/m1mir/dotfiles
├───apps
│   └───x86_64-linux
│       └───default: app
├───checks
│   └───x86_64-linux
│       ├───formatting: derivation 'fmt-chek'
│       └───wm: derivation 'wm-0.1.0.0'
├───devShells
│   └───x86_64-linux
│       └───wm: development environment 'devenv-shell'
├───formatter
│   └───x86_64-linux: package 'alejandra-3.1.0'
├───homeConfigurations: unknown
└───nixosConfigurations
    └───example: NixOS configuration

Does anyone know a good/simple way to list the homeConfigurations part of a flake without writing nix parsing code?

I use –impure because devShell that I’m using requires it.

An example for what I mean by a good/simple solution using the nixosConfigurations is the following:

nix flake show --impure --json 2> /dev/null | jq -r '.nixosConfigurations | keys | join("\n")'

The example outputs the hostname for the nixosConfigurations as a newline separated list and silences the nix command stderr output.

home-manager has this built-in, just name your homeConfigurations user@hostname and omit that when installing.

1 Like

What you suggested wasn’t exactly what I was looking for but based on the link I found a good solution.

nix eval "path/to/flake/#homeConfigurations" --apply 'hconf: builtins.attrNames hconf' --json

The code block above prints the *username+hostname" combinations or username as a json array.

Thank you @TLATER !

2 Likes