Help me understand how to have a personal repository of flakes

Hi, beginner here.
I’ve been trying to understand how it is possible to keep/host a personal collection of derivations that could live outside nixpkgs but I think I’m either missing the right search terms or there are no easy examples available.
Sorry in advance if my terminology is lacking.

Use case example:
I am creating a dev environment for a project using a flake.nix.
I use dependencies from nixpkgs as found in a lot of examples but I also want some niche softwares not in any repositories. I want to package it, without going through submitting it to nixpkgs for whatever reason (want to test it first, or I really need it asap and can’t wait for a PR to go through, or it’s just too niche, or I need a very specific version) and it would be best for me to have a git repo of flakes that I can easily add to my dev definitions.

Do you have simple examples of personal repositories of the sort?
Are there specific search terms for this concept that would help me?
Overlays might be it but I had a hard time to grasp if it was it.

2 Likes

https://nur.nix-community.org/

thanks! This is indeed something useful, I now need to understand how that could work in my case.

The repo for NUR links to a NUR-packages-template, and gives an example of adding a package & adding that repo to NUR.

The packages template:

NUR is unnecessary with flakes. Your flake can be used as input directly.

inputs.yourflake.url = "github:user/repo";
1 Like

Flakes are indeed a great usecase for this, as you can have everything in a single repository, and once the packages are there, you can add them to your project just like packages from nixpkgs.

I’ll gladly give you an example and explanation of the different mechanics, but I need to know what kind of project are we talking about here. Is everyone of the contributors on the same architecture and platform? Or does the collection have to be compatible with x64 and ARM, Linux and macOS?

Indeed. But the OP asked for a monorepo for multiple projects and the NUR template is a good starter for that (and can be used as a Flake, too).

2 Likes

To detail a bit more the use case, I’d like to provide a reproducible environment for a bioinformatics pipeline, which includes tools not packaged in nixpkgs.
The primary use would be to use this on linux and to produce a linux based container usable on clusters.

I was thinking of a personal repository mainly because I might want to reuse individual parts of the environments in other pipelines, but that’s not a hard requirement.

I have the feeling that nix can fill a big gap in reproducibility but honestly the docs and resources is a bit lacking on that front unfortunately.

1 Like

The official nix manual’s page on flakes provides good information (albeit isn’t a tutorial) nix flake - Nix Reference Manual
For a tutorial, the unofficial Zero-to-Nix does discuss using flakes Quick start – “collection of derivations that can live outside of nixpkgs” is pretty much what flakes do, so I think you’d be able to achieve what you want.

I believe this may be related/useful; some example package related to HPC

1 Like

Thanks to everyone, I think I am starting to get the idea and will try that when I have more time.

You can use Nix overlays to add or modify packages. Create a default.nix file in a directory with your custom package definitions. Then, add this directory to your Nix configuration. Alternatively, you can create a standalone Nix flake for your custom packages. You’d initialize a new Git repository, create a flake.nix with your custom package definitions, and then include that flake as an input in your project’s flake.nix.

1 Like

Does NUR template purposefully leave out aarch64-darwin as a system, because it’s not supported there for some reason?

Looking at the ‘git blame’ of that flake.nix, the systems was written in mid-2021. My guess is the omission of aarch64-darwin was just its lack of popularity at the time.

I was able to add aarch64-darwin as a github runner to a Gradle-based project of mine, and it built just fine.

However, generally, my understanding is that Apple is less popular on Nix, and whatever works is thanks to some heroic efforts by volunteers. c.f. Nix 🖤 macOS Monthly

1 Like