I’ve written a nix flake that can be used to generate other nix flakes for
Hakyll websites. It’s at GitHub - Radvendii/hakyll-flakes: Easy website generation with hakyll + nix flakes. I had a
few questions about best practices. (the questions won’t make sense out of
context though. you’ll have to look at the example in the readme)
There are two steps to make the website: compiling the website builder, and actually building the website. I have these separated as the “builder” package (which just builds the hakyll-based builder) and the “website” package (which does both, and leaves you with the website files).
- First question: Is “builder” a good name for this? I know “builder” has specific meaning in the nix ecosystem, but I couldn’t think of a better name.
hakyll-flake-gen needs to construct it’s own version of nixpkgs to guarantee that hakyll will work. It also takes in a set of build inputs that are needed for the second stage of building (applying the compiled hakyll builder to the website files).
-
Second question: It is currently set up to pass back its modified copy of nixpkgs for the user to use when constructing the build inputs list. This isn’t actually necessary, because those build inputs don’t need hakyll. I figured it was better to use one consistent version of nixpkgs for the flake, rather than having those buildInputs come from the user’s nixpkgs, but now I’m not so sure. Which is better, having one consistent version of nixpkgs for all inputs, or having a simpler API (passing fewer things back and forth)?
-
Third Question: Right now hakyll-flake-gen uses flake-util’s eachDefaultSystem, which means when you use it you have to use it as hakyll-flake.gen."${system}". I noticed that nix-bundle’s flake.nix has a bundlers.nix-bundle attribute that instead takes in system as an argument. (nix-bundle/flake.nix at 8e396533ef8f3e8a769037476824d668409b4a74 · matthewbauer/nix-bundle · GitHub) Is that better?
-
Fourth question: Is there a naming convention for functions that generate flakes from inputs? I’ve called it gen (short for “generator”), but in nix-bundle it’s in bundlers.nix-bundle, and in flake-utils they’re under “lib”.
If there’s anything else I’m doing in a way that’s not ideal, let me know. This is just a first draft.
Thanks,
–Taeer