this post was submitted on 28 Jan 2025
12 points (100.0% liked)

Nix / NixOS

1916 readers
9 users here now

Main links

Videos

founded 2 years ago
MODERATORS
 

I've been working on my configuration for a while now using flakes. I can already understand the appeal of flake-parts, and my configuration has always been spread out across multiple files according to specific features. ATM I don't really have any good modules to share, but what's your opinion?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] adept@programming.dev 2 points 4 days ago (1 children)

I don't really like flake-parts or flakelight. I think that part of this is sheer brutalism (I don't mind writing bare Nix) but part of it is a desire to not rely on flakes which don't carry their own weight, following Wirth's principle for compilers.

How can you say this and still use flake-utils? All it does is manage your systems. You can write your own one-liner for that

eachSystem = f: lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});

Where systems is automatically supplied as a flake input (I think), or you can supply your own list of systems to support. You can then use it like this:

devShells = eachSystem (pkgs: {
    default = # your devshell
}

You can of course modify eachSystem to have more function parameters other than pkgs.

See this blog which initially inspired me not to use flake-utils

[โ€“] hallettj@leminal.space 1 points 1 day ago

I've come around to doing it this way too. systems is not automatically supplied as a flake input - you can get such an input like this:

inputs = {
  systems.url = "github:nix-systems/default";
  # ...
};
outputs = { self, nixpkgs, systems }:
  let
    eachSystem = f: lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
  in
  {
    # ...
  } 

The handy thing about importing another flake to get a list of four strings is that anyone consuming your flake can override that input in case they want to use a system that isn't included in your original flake. There is more information at https://github.com/nix-systems/nix-systems