Hello all, I am a (very) new user of Nix, mainly interested in it as Nix provides unified mechanism for outputting various package types (debian, python, docker images, appimages etc).
I am trying to setup something which would act like a privae registry / repository housing various flakes I will write. Is there anyway I can ask Nix to look at the flakes defined in this registry before it tries to look at any other registry? Sort of like primary and secondary PyPI indices.
For example:
Lets assume my private registry has following flakes defined:
foo
bar
baz
When I run:
nix profile install foo#MAIN_PKG
Nix first looks at my registry, if it finds the flake with appropriate target, it uses it. If Nix is unable to find a match in my registry, it looks at the standard nix registries.
If you could point me to a very bare-bones example or better yet (if its simple/quick enough) show me how to implement this, I would really appreciate it.
Edit:
I realise, I could simply use the absolute path to the flake like:
nix profile install /path/to/flake/parent/dir#MAIN_PKG
However, I dont want to pollute my scripts with absolute paths and would prefer a more configurable way.
As my planB, I could possibly have an ENV_VAR providing the path to the collection of flakes,
but I would prefer to avoid it if I can.
Hey, good question. To be honest, I’m not sure if that’s possible to do natively. There might be a clever way to generate nix.registry.somesubdir registries programmatically, but I’m not so sure that’s the right approach.
Is it possible to have a registry behave like the nixpkgs repository in your example?
As far as I’m aware, the nixpkgs repository is not a collection of flakes. Instead, it’s a single flake with many outputs. That’s why you can run github:NixOS/nixpkgs#hello or any other package.
Similarly, I would recommend having a single flake with lots of outputs (devShells, packages, etc.) for each of your packages and projects. That way, the flake is what controls the “registry”, and each of the projects are available as outputs provided by the flake. So you would access them with nix profile install mypkgs#foo.
The way I am trying to approach this is, having a repository of flakes with each flake defining output packages, devShells etc tied to the applications.
For example, an application such as blender could be split as following different packages (however they are related) in a single flake:
blender (main application)
blender-docs (only documentation)
blender-python (blender as a python module)
cycles (render engine)
blender-shell (a dev shell)
I really like the fact that flakes can show their outputs. So in this case, I could potentially do something like:
# Provide a visual representation of all the various outputs provided by Blender flake
nix flake show PKGS.blender`
# Also we can easily get the metadata for each flake trivially as follows:
nix flake metadata PKGS.blender
This becomes really difficult to achieve using a single flake, which would simply clutter the information.
I could actually use the registry method you showed earlier (specially since it actually does what I want to achieve), if this proves to be very convoluted to achieve.
Hey @bhaveshpandey, I see why you’d want to build that pattern instead of a single flake.
In that case, I would think about writing a small script that to find all of the directories that you want to include, and either load them into your registry with nix registry add commands, or generate a registry.json file with links that look like this:
If you save that file to ~/config/nix/registry.json (or load that file in manually with nix registry add --registry ./config.json) then you should have those flakes available to your user profile.