Flake based Home Manager cannot find home.nix

I am trying to get home manger set up with flakes.

Following the home manager documentation for setting up with flakes I have the following in my flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ nixpkgs, home-manager, ... }: {
    nixosConfigurations."nixos" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager {
          home-manager.useGlobalPkgs = true;
          home-manager.userUserPackages = true;
          home-manager.user.ciferkey = import ./home.nix;
        }
      ];
    };
  };
}

In the same directory I have my home.nix. When I try to nixos-rebuild switch I get the following error

nixos% sudo nixos-rebuild switch --flake .#nixos
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
error: getting status of '/nix/store/gq8j7g8hvsnymr7f41ibjkkarcxvrjd2-source/home.nix': No such file or directory

Here is full stack trace:

nixos% sudo nixos-rebuild switch --flake .#nixos --show-trace
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
error: getting status of '/nix/store/gq8j7g8hvsnymr7f41ibjkkarcxvrjd2-source/home.nix': No such file or directory

       … while realising the context of path '/nix/store/gq8j7g8hvsnymr7f41ibjkkarcxvrjd2-source/home.nix'

       at /nix/store/gq8j7g8hvsnymr7f41ibjkkarcxvrjd2-source/flake.nix:16:40:

           15|           home-manager.userUserPackages = true;
           16|           home-manager.user.ciferkey = import ./home.nix;
             |                                        ^
           17|         }

       … while evaluating 'id'

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/trivial.nix:14:5:

           13|     # The value to return
           14|     x: x;
             |     ^
           15|

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:217:47:

          216|           let
          217|             evalNext = x: mapAny (depth + 1) (transform (depth + 1) x);
             |                                               ^
          218|           in

       … while evaluating anonymous lambda

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:215:40:

          214|           else id;
          215|         mapAny = with builtins; depth: v:
             |                                        ^
          216|           let

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:217:27:

          216|           let
          217|             evalNext = x: mapAny (depth + 1) (transform (depth + 1) x);
             |                           ^
          218|           in

       … while evaluating 'evalNext'

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:217:24:

          216|           let
          217|             evalNext = x: mapAny (depth + 1) (transform (depth + 1) x);
             |                        ^
          218|           in

       … from call site

       … while evaluating 'go'

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:237:18:

          236|     let
          237|     go = indent: v: with builtins;
             |                  ^
          238|     let     isPath   = v: typeOf v == "path";

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:282:57:

          281|               (name: value:
          282|                 "${libStr.escapeNixIdentifier name} = ${go (indent + "  ") value};") v)
             |                                                         ^
          283|         + outroSpace + "}"

       … while evaluating anonymous lambda

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:281:22:

          280|           + libStr.concatStringsSep introSpace (libAttr.mapAttrsToList
          281|               (name: value:
             |                      ^
          282|                 "${libStr.escapeNixIdentifier name} = ${go (indent + "  ") value};") v)

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/attrsets.nix:356:16:

          355|   mapAttrsToList = f: attrs:
          356|     map (name: f name attrs.${name}) (attrNames attrs);
             |                ^
          357|

       … while evaluating anonymous lambda

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/attrsets.nix:356:10:

          355|   mapAttrsToList = f: attrs:
          356|     map (name: f name attrs.${name}) (attrNames attrs);
             |          ^
          357|

       … from call site

       … while evaluating 'go'

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/generators.nix:237:18:

          236|     let
          237|     go = indent: v: with builtins;
             |                  ^
          238|     let     isPath   = v: typeOf v == "path";

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/options.nix:315:10:

          314|       prettyEval = builtins.tryEval
          315|         (lib.generators.toPretty { }
             |          ^
          316|           (lib.generators.withRecursion { depthLimit = 10; throwOnDepthLimit = false; } def.value));

       … while evaluating anonymous lambda

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/options.nix:311:38:

          310|
          311|   showDefs = defs: concatMapStrings (def:
             |                                      ^
          312|     let

       … from call site

       … while evaluating 'concatMapStrings'

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/strings.nix:53:25:

           52|   */
           53|   concatMapStrings = f: list: concatStrings (map f list);
             |                         ^
           54|

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/options.nix:311:20:

          310|
          311|   showDefs = defs: concatMapStrings (def:
             |                    ^
          312|     let

       … while evaluating 'showDefs'

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/options.nix:311:14:

          310|
          311|   showDefs = defs: concatMapStrings (def:
             |              ^
          312|     let

       … from call site

       at /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/lib/modules.nix:227:115:

          226|             firstDef = head merged.unmatchedDefns;
          227|             baseMsg = "The option `${showOption (prefix ++ firstDef.prefix)}' does not exist. Definition values:${showDefs [ firstDef ]}";
             |                                                                                                                   ^
          228|           in

This is on unstable. Here is the flake.lock:

{
  "nodes": {
    "home-manager": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1648078876,
        "narHash": "sha256-oa3RA0Z0UwEZ1M5kQOT9oUVd4ew3XePOu2oDTenFd98=",
        "owner": "nix-community",
        "repo": "home-manager",
        "rev": "ac9404115362c901ffe5c5c215f76f74b79d5eda",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "repo": "home-manager",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1648069223,
        "narHash": "sha256-BXzQV8p/RR440EB9qY0ULYfTH0zSW1stjUCYeP4SF+E=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "1d08ea2bd83abef174fb43cbfb8a856b8ef2ce26",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "home-manager": "home-manager",
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}

Why is flake not able to find the home.nix file and why does it instead look in the store? Can it not handle local paths?

1 Like

This is how flakes work, and have ever done. They are copied to the store and evaluated there.

This has been true even without HM just for the system configuration.

The reason it doesn’t find your home.nix now is probably because you didn’t git add it.

3 Likes

Thank you very much! It was indeed missing from git.

1 Like