Flake.nix in root of Git or deeper?

Hi everybody,

I noticed that all git repos with flake has flake.nix in root (same as .git directory). Is that a requirement / recommendation?

I wonder if there is a problem / functional difference if I place flake.nix like this:

# .
# ├── .git
# │   └── ab
# │       └── cd
# │           └── flake.nix
# │           └── flake.lock

and then use it as input in other flake like this

  inputs = {
    myrepo.url = "github:myorg/myrepo/ab/cd";


  inputs = {
    myrepo.url = "path:/home/johndoe/myrepo/ab/cd";

Thank you.

It does not have to be in the root.

Though the syntax to access the flake then is a bit more convoluted than your example.

You always have to specify the “root” of the source, then use dir in the query string to specify the relative location of the folder that contains the flake.{nix,lock}.

And I am not even sure if that works with path. I know only for sure that it works with git, github, and gitlab, eg. github:myorg/myrepo?dir=ab/cd.

Remember though that subfolders of .git are generally not accessible, and you shouldn’t put anything there on your own, except the hooks.


Of course, I made wrong indentation in the first visual. It should be like this:

# .
# ├── .git
# └── ab
#     └── cd
#         └── flake.nix
#         └── flake.lock

Thank you. I’m sure it works with path since so far I’ve been using it only locally and I haven’t used github yet.

I’m just not sure if Nix takes path:/home/johndoe/myrepo/ab/cd as a path that is not version controlled or if it checks that ab/cd is relative path on top of version controlled /home/johndoe/myrepo.

If you force path schema, then the specified path will be used as the flake root, without any VCS. path can be used to explicitely disable any VCS related behaviour flakes usually have.

Please remember, that when not specifying a schema, nix will infear it.

So if you specify /home/johndoe/myrepo/ab/cd and there is a git repo in the parents, nix will use that to my knowledge, if you use nix 2.10 or newer (I think that was when parent search got introduced).

In other words, if I want VCS behavior, I should remove path: like this:


myrepo.url = "path:/home/johndoe/myrepo/ab/cd";


myrepo.url = "/home/johndoe/myrepo/ab/cd";

And the VCS behavior means I can lock to git commit / branch and not to sha256 of the flake.nix file.

Type inference only happens via CLI.

When using an input you always want to specify a schema, otherwise flake is assumed ass far as I understand.

Based on my testing flake is assumed when I use path: in input but VCS is not in use because when I look at the flake.lock file, I don’t see "rev": "..." at the local path.