NixOS options of type 'pathInStore' break when running nixos-install

Howdy,

I have a Flake with a custom home-manager module that looks something like this:

{ config, lib, ... }:

with lib;
{
    options.my.module.icon = mkOption {
        type = types.pathInStore;
        description = "Image to use for this thing";
    };
}

Elsewhere in the Flake, I use the module in my config referencing a file in the flake:

my.module.icon = ./my-icon.png

I have been happily using this with nixos-rebuild --flake for some time. But today I’m setting up a new machine and it’s suddenly causing problems. nixos-install fails, complaining that the value for the option is invalid.

# (running on the installer image)
> nixos-install --flake .#myNewMachine

<snip>

    error: A definition for option `home-manager.users.me.my.module.icon` is not of type `path in the Nix store'. Definition values:
    - In `/mnt/nix/store/<snip>-source/my-config.nix': /mnt/nix/store/<snip>-source/my-icon.png

I’m doubtful that this is specific to home-manager in any way, and pretty confident that it’s getting thrown off by the /mnt/nix/store prefix. Is there any way to get around this, or a smarter way to refer to files within my flake? Wrapping it in a derivation perhaps?

Any tips would be much appreciated!

That smells like a Nix bug.

pathInStore uses builtins.storeDir to determine the store. nixos-install uses Nix’ --store flag to build in the store at /mnt/ but that doesn’t change the storeDir.

For whatever reason though, the files you reference are interpreted as absolute paths rather than as store paths.

This smells similar: Flake paths should use virtual store directories · Issue #9852 · NixOS/nix · GitHub

Why are you using pathInStore though? It’s a very niche type that’s seldom used and I don’t see any benefit in it over just plain old path here.

Why are you using pathInStore though? It’s a very niche type that’s seldom used and I don’t see any benefit in it over just plain old path here.

That would be a classic case of reading the docs and not understanding what they meant :+1:

But thanks! Changing the type to just path got everything working again.

Same problem here though I’m not using custom home-manager module rather 3rd party flake.parts module: ez-configs - flake-parts

error: A definition for option `ezConfigs.root' is not of type `null or path in the Nix store'. Definition values:
       - In `/mnt/nix/store/pr08xgx825h10pyrbw8czrvgszylr5s3-source/flake.nix': /mnt/nix/store/pr08xgx825h10pyrbw8czrvgszylr5s3-source

I’m afraid that there may be many more such modules that I’m using. After a few yeas using nixos-rebuild with flakes I’m in a need of doing nixos-install and failing hard.

I’ve tried nix 2.18.4 and 2.22.2 to no avail. And I’m trying to run the build command manually so there’s no change nixos-install is picking a different version.

sudo nix --version # Checked version
sudo nix --experimental-features "nix-command flakes" build "git+https://codeberg.org/Uli/nixsauce.git?ref=refs/heads/main&rev=0c1a511dcc856852ef9a480afc9074508065b291#nixosConfigurations.uli-desktop-01.config.system.build.toplevel" --store /mnt --impure

Is there some workaround?