Feedback on flake setup?

Hi all-

I’ve added a flake.nix file to a Python project of mine, and I was hoping to get some constructive criticism on it. I’ve opened a pull request, and I’d love for anyone who wants to leave a review: Add a nix flake setup by waxlamp · Pull Request #17 · waxlamp/elgato · GitHub.

I’m looking for advice on the following:

  • Does my setup look more or less correct as is?
  • Is there a better way to organize/refactor my flake?
  • Anything else that I don’t know to ask about

And some specific questions about how to make use of this:

  1. What is the normal way for anyone out there to install my package? nix profile? This seems to work, but that brings me to…
  2. How do I make use of this flake declaratively? For instance, how do I install this via home-manager?


It looks pretty good! I left a couple comments. Yeah nix profile is one way to do it, but there are many. The cool part about flakes is you can make your outputs and people can make use of your flake in a number of ways.
They can include an overlay to their package set that includes your package. So then in home.packages you can just add pkgs.elgato. You can provide an overlay too that adds your package to make this process simpler.
Or they could pass your flake to their configuration’s module arguments, so in any module they can reference it like { config, elgato, ... }:. And the package can be added that way. I usually use this method for importing modules. Adding packages is much easier with overlays.

Thank you!!

Could you maybe point me to an example of each of these methods (use a flake as input for an overlay; provide an overlay from a flake; pass a flake to a configuration module)? This is always where I run out of rope with Nix–there are so many ways to do everything, and without good examples I always end up feeling lost.

Thanks again, this is so helpful!

So lets say you had an overlay exported in your flake. As a user of your flake I could do something like this in my own flake:

  inputs.elgato.url = "github:waxlamp/elgato";
  inputs.nixpkgs.url = "nixpkgs";
  outputs = { self, elgato, nixpkgs, ... }: {
    nixosConfigurations.pacman = nixpkgs.lib.nixosSystem {
      modules = [ 
          nixpkgs.pkgs = import nixpkgs { 
            overlays = [ elgato.overlay ];
        ({ pkgs, ... }: {
          environment.systemPackages = [ pkgs.elgato ];

This is a really simple - untested- example of how someone could include your overlay. Optimally you would make use of tools like flake-utils(-plus) or devos to make this much easier. They have ways to easily add overlays to all your hosts from external flakes.

To do the other method - its really impractical for packges its more useful for modules - you could make use of the nixosSystem specialArgs argument:
nixosSystem { specialArgs = { inherit elgato; }; ... }
Then modules could access elgato like this this { config, elgato, ... }:, following module system/nixos semantics.

1 Like

In office hours with @tomberek, I also learned about the builtins.getFlake function, which lets you (among other things) pull a flake into anywhere a derivation is expected. That provided the main bridge between my current NixOS/home-manager setup and the concept/execution of flakes.

Thanks for the help, everyone!