Error Importing .nix files using flakes

I’m not a programmer and am very new to NixOS. Please be gentle.

I recently installed this configuration by Frost Phoenix and have fallen in love with it. I’ve adapted it to my needs. It’s the latest unstable version. However, there is one problem I cannot figure out a solution.

I get an error every time I try to add a new nix file or directory, despite adding it to my imports. For instance, say I created and added libinput.nix into my home directory. I would import it through /nixos-config/modules/home/default.nix as follows:

{inputs, username, host, ...}: {
  imports =
      [(import ./bat.nix)]
   ++ [(import ./libinput.nix)]
   ...
   ++ [(import ./zsh.nix)];
}

I then run this command:
sudo nixos-rebuild switch --flake /home/neo/nixos-config#desktop --option show-trace true --fast

And then get this error:

at /nix/store/rs4fjbnw4qx7ns2hzzrz2iz52va7vs5z-source/lib/modules.nix:349:12:

348| loadModule = args: fallbackFile: fallbackKey: m:
349| if isFunction m then
   |    ^
350| unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgs fallbackKey m args)

… while calling 'isFunction'

at /nix/store/rs4fjbnw4qx7ns2hzzrz2iz52va7vs5z-source/lib/trivial.nix:991:16:

990| */
991| isFunction = f: builtins.isFunction f ||
   |              ^
992| (f ? __functor && isFunction (f.__functor f));

error: getting status of '/nix/store/fl33dws0knxzfa8yjn4pg6qhw5l02jn2-source/modules/home/libinput.nix': No such file or directory

Again, it does this with any .nix file I try to create and import. I’ve tried importing it in my desktop config and editing my flake.nix but no luck. The workaround is adding my code to a pre-existing .nix file, but this is far from perfect and only a temporary bandaid. Your help is greatly appreciated!

Solution:

cd into the flake and run git status. It will show you ‘untracked’ files in red. You need to add them to git, for example git add . to add everything.

Also, the import keyword here is unnecessary, imports is just a list of paths

  imports = [
    ./bat.nix
    ./libinput.nix

    ./zsh.nix
  ];

Explanation:

Because the flake you’re using is in a git repo, nix will copy the git repo to the store, but only include files in git’s index.

The import keyword is build in to the nix language, and it is treated as the content of the file it imports.

imports = [ ... ]; is part of the module system, and takes a list of paths to include as modules

1 Like

You saved me a lot of headache. Thank you