Nix flakes best practices question

87 views
Skip to first unread message

Taeer Bar-Yam

unread,
Mar 10, 2021, 12:00:21 PM3/10/21
to nix-...@googlegroups.com
I've written a nix flake that can be used to generate other nix flakes for
Hakyll websites. It's at https://github.com/Radvendii/hakyll-flake-gen. 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 radme)

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
and the "website" package (which does both).

1) 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).

2) Secomd 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)?


3) 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.
(https://github.com/matthewbauer/nix-bundle/blob/master/flake.nix) Is that
better?

4) 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".

Thanks,
--Taeer

Ruben Astudillo

unread,
Mar 11, 2021, 8:28:35 PM3/11/21
to tb...@cornell.edu, nix-...@googlegroups.com
Hi Taeer

Some years ago the nix-devel mailing list was phased out in favor of discourse

https://discourse.nixos.org/

I personally liked the mailing list, but most users have moved on. I guess
you could ask your question there and get more exposure.

--
-- Rubén
-- pgp: 4EE9 28F7 932E F4AD
Reply all
Reply to author
Forward
0 new messages