Nix nested flakes

Hello. I’m using NixOS for a while, but i’m new to flakes :sweat_smile:
I’m trying to build my system structured.
Now I have an issue with updating my system when referencing flake when it’s under directory that contains my system flake.
here is the strucutre:

|-nixos
|  |-flake.nix
|  |-flake.lock
|  |-packages
|    |-myflake
|      |-flake.nix
|-Projects
  |-myflake

And here is the inputs section of my system flake (in nixos dir)

    inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
        home-manager = {
            url = "github:nix-community/home-manager/release-24.11";
            inputs.nixpkgs.follows = "nixpkgs";
        };
        hello-flake.url = "/home/maksi/Projects/myflake";
        # hello-flake-nested.url = "/home/maksi/nixos/packages/myflake"; #this doesn't work
    };

Flake i’m using for testing is basic hello world flake that is given to you when you write nix flake init

Any help will be appreciated :slight_smile:

To be honest, i’m just trying to chech out this desktop shell, but so far i have no success)))

What’s the issue you met? Are you trying to do this? If yes, then the feature has been merged into Nix 2.26 so you need a newer version of Nix.
Also, is there a particular reason for nesting flakes? If you just want to structure you nix files, you can create sub-directories and use paths to refer to each other.

1 Like

I’m having the following issue

error:
       … while updating the lock file of flake 'git+file:///home/maksi/nixos'

       … while updating the flake input 'my-flake'

       … while fetching the input 'path:./packages/myflake'

       error: path '//nix/store/s4pyyfl42zwn3pmgr36lakjc2gyd23nl-source/packages/myflake' does not exist

There is no reason for nesting flakes, except that it’s easier to track.

I’m already using sub-directories, the issue is they not seem to work together well.

Well what version of nix are you using?

Please elaborate.

2 Likes

For system flake I’m using the last stable version, a.k.a. 24.11.
And for sub-directories i printed a tree in the original message:

|-nixos
|  |-flake.nix
|  |-flake.lock
|  |-packages
|    |-myflake
|      |-flake.nix
|-Projects
  |-myflake
    |-flake.nix

“nixos” is dir for my system flake and “packages” is dir where I want to place flake (it’s subdirectory of “nixos” dir).
Also, there is “Projects”, under where i nave copy of flake, which i want to place under “packages” dir. When i reference the flake from there, it works.

Nix, not nixos. What is nix --version telling you?

I’ll be more specific: what exactly doesn’t “work together well”?
Why do you want to use subflakes which are frankly even more unstable than just creating subdirectories within one flake?

1 Like

the version of nix: nix (Nix) 2.24.12

i don’t know how to do it, will research it.

When i include flake from sub-directory, i get message, that this flake is not found, error is specified there:

Right, since your nix is before 2.26, I would suggest not using subflakes (2.26 brought some much-needed improvements to how lockfiles are handled).

3 Likes