Flake based Home Manager config is unable to use includes

I’m playing around with nix and Home Manager on my Debian Bookworm system for a while (Nix and Home Manager following nixpkgs 23.05 stable ). I’m really happy so far.
I started straight with a flake based Home Manager setup based on Misterio77s starter configs. This worked with my Home Manger config right of the bat. until I started to try and split the Home Manager config into smaller parts. Since then I always get the following error when building the config with home-manager switch --flake .#manji:

error:
       … while evaluating a branch condition

         at /nix/store/c8aplaf4cij0zr4bca19y1k2vi9qhslz-source/lib/lists.nix:57:9:

           56|       fold' = n:
           57|         if n == len
             |         ^
           58|         then nul

       … while calling the 'length' builtin

         at /nix/store/c8aplaf4cij0zr4bca19y1k2vi9qhslz-source/lib/lists.nix:55:13:

           54|     let
           55|       len = length list;
             |             ^
           56|       fold' = n:

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/hwzgz3zmq1z6zlswsphyzqjyqv69rdxh-source/users/manji/vim.nix': No such file or directory

My repository layout is quite simple. I have the flake on top level and a folder users with a subfolder for the target user that contains the Home Manager config and the subpart I try to include.

This is my flake:

{
  description = "Home Manager configuration";

  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
    home-manager = {
      url = "github:nix-community/home-manager/release-23.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }:
    let
      system = "x86_64-linux";
      user = "manji";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations = {
        ${user} = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;

          # Specify your home configuration modules here, for example,
          # the path to your home.nix.
          modules = [ 
            ./users/${user}/default.nix 
          ];
      };
      };
    };
}

the Home Manager configuration:

{ config, pkgs, ... }:

{
  nixpkgs = {
    config = {
      allowUnfree = true;
      allowUnfreePredicate = _: true;
    };
  };

  imports = [
    ./vim.nix
  ];
  home.username = "manji";
  home.homeDirectory = "/home/manji";

  systemd.user.startServices = "sd-switch";

  targets.genericLinux.enable = true;

  home.stateVersion = "23.05"; # Please read the comment before changing.

  home.packages = [
     pkgs.vscode
     pkgs.rnix-lsp

  ];

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
  };

  home.sessionVariables = {
    EDITOR = "vim";
  };

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
  
  # ZSH
  programs.zsh = {
    enable = true;
    oh-my-zsh = {
      enable = true;
      plugins = [ "git" "thefuck" "ssh-agent"];
      theme = "dpoggi";
    };
  };

}

and finaly the sub file vim.nix that fails to include:

{
  # vim
  programs.vim = {
    enable = true;
  };
}

Is there anything I’m missing? Do I need to make the subfile somehow known to the flake?
I’m grateful for any hint.

Hi!

It seems that you missed adding the file with git add. When using a flake within a git repository, files that are not tracked by git are invisible to the evaluator (thus the No such file or directory error).

Hope that helps. Cheers!

1 Like

That was the issue.

Thank you so much!