Flake.nix to "pull and import" from other flake.nix

I’m new to nix (the language) but been using shell.nix for some time, now I want to do something to ease my process of software development with GNU Emacs using flakes to support that.

So, I started a repository on GitHub GitHub - shackra/flakes: Highly opinionated flakes for working with GNU Emacs

I have a directory called essentials which installs “essential” packages for software development.

Now, I have another folder called golang and added the essentials folder as an input. My idea is that the flake.nix in golang pulls everything from essentials and also uses everything defined in its outputs.

However, I don’t think I’m doing this flake stacking correctly, thus my question is, what am I missing?

Consider maybe putting your “essentials” in your actual system/home-manager config, and then making a single flake that contains templates with language-specific devShells. Then you don’t need to stack stuff because your essentials will already be in the environment, and you don’t have to deal with the madness that is sharing flake inputs between subfolders.

Multiple nested flakes in a single repo technically works, but the UX is painful and unintuitive with some gotchas. Further, you don’t really gain much atm. So if you are gonna have code in the same repo, I’d just stick with a single flake.nix for now.

1 Like

thank you for your answer, but I rather not as I’m looking to have something like asdf-vm but using flakes

Which repo, tho? I’m building a repository with flakes with no specific source code of any programming language.

Perhaps I am misunderstanding, but from your original description it sounds like you are trying to import a flake as a dependency from a flake in the same repository of code. This is sometimes called a subflake.

The language in use doesn’t really matter, a flake is simply a mechanism to declare inputs and produce outputs, nothing more. What I am saying is, if you reference a flake by a relative path to another flake in the same repo, that it will technically work, but it is somewhat brittle in its current form. Hopefully it gets fleshed out at some point, but for the time being it really isn’t worth it, imo at least.

If what you are after is some mechanism to organize your code, a flake.nix doesn’t really help much there. It provides input and outputs but other than that it could care less about how you produce those outputs. There are tools like haumea or flake-parts that try an address this, by adding facilities for organizing your code in a more structured manner.

1 Like