Any way to access flake reference for current NixOS/Home Manager config?

As a poor-man’s alternative to an up-to-date binary cache, I’ve set up a user service that regularly fetches the latest versions of flakes I use often and builds them, so the results are already present in my nix cache:

So for example:


    bjackman.nix-warmups = [
      "github:bjackman/limmat-kernel-nix/master#devShells.${pkgs.stdenv.hostPlatform.system}.kernel"
      "github:bjackman/boxen/master#devShells.${pkgs.stdenv.hostPlatform.system}.default"
    ];

That’s where I set it up for a couple of devShells that I use a lot, which can take a few minutes to build if the dependencies have updated.

Well, I wanna do this for my actual NixOS and Home Manager configs.

For NixOS systems I just did this:

  bjackman.nix-warmups = [
    "github:bjackman/boxen/master#nixosConfigurations.${pkgs.stdenv.hostPlatform.system}.${osConfig.networking.hostName}"
  ];

That happens to work fine but the equivalent for standalone Home Manager setups (i.e. where I’m using a heathen distro):

  bjackman.nix-warmups = [
    # Doesn't work!
    "github:bjackman/boxen/master#homeConfigurations.${config.home.username}"
  ];

This doesn’t work because not all of my NixOS configurations are defined in the flake that way, some are defined as $user@host for example.

Obviously just defining this individually for each host is not that bad, but I’m curious about this.

Is there any way to figure out the flake ref for the configuration that’s currently being built?

I think it comes down to the construction of your references and of your systemd service. This works: nix build 'github:clhodapp/private-repo#homeConfigurations."user@host".config.home.activationPackage'

So you need to put the quotes inside your reference and you need to make sure that you are building an actual derivation inside of your config.

Ah yeah it works fine if I just explicitly name the config derivation flake reference.

It’s just that I’d like to do that for all my machines with a single line of code, and I don’ think that’s possible, because the structure of the flake reference is heterogeneous in my config.