Flake Parts
flake-parts provides the options that represent standard flake attributes and establishes a way of working with system. Opinionated features are provided by an ecosystem of modules that you can import.
Flakes are configuration. The module system lets you refactor configuration into modules that can be shared.
It reduces the proliferation of custom Nix glue code, similar to what the module system has done for NixOS configurations.
Unlike NixOS, but following Flakes’ spirit, flake-parts is not a monorepo with the implied goal of absorbing all of open source, but rather a single module that other repositories can build upon, while ensuring a baseline level of compatibility: the core attributes that constitute a flake.
Features:
- Split your
flake.nixinto focused units, each in their own file. - Take care of
system. - Allow users of your library flake to easily integrate your generated flake outputs into their flake.
- Reuse project logic written by others
Usage
If your project does not have a flake yet:
nix flake init -t github:hercules-ci/flake-partsOtherwise, add the input, flake-parts.url = "github:hercules-ci/flake-parts";, then slide mkFlake between your outputs function head and body,
outputs = inputs@{ flake-parts, ... }:
# https://flake.parts/module-arguments.html
flake-parts.lib.mkFlake { inherit inputs; } (top@{ config, withSystem, moduleWithSystem, ... }: {
imports = [
# Optional: use external flake logic, e.g.
# inputs.foo.flakeModules.default
];
flake = {
# Put your original flake attributes here.
};
systems = [
# systems for which you want to build the `perSystem` attributes
"x86_64-linux"
# ...
];
perSystem = { config, pkgs, ... }: {
# Recommended: move all package definitions here.
# e.g. (assuming you have a nixpkgs input)
# packages.foo = pkgs.callPackage ./foo/package.nix { };
# packages.bar = pkgs.callPackage ./bar/package.nix {
# foo = config.packages.foo;
# };
};
});Now you can start using the flake-parts options.