Autowiring
An optional autowiring module is provided that will scan the directory structure and wire up the appropriate flake outputs automatically without you having to do it manually.
A ready demonstration is available in nixos-unified-template as well as srid/nixos-config. In the latter, you will notice the following directory structure:
โฎ lsd --tree --depth 1 configurations modules overlays packages
๐ configurations
โโโ ๐ darwin
โโโ ๐ home
โโโ ๐ nixos
๐ modules
โโโ ๐ darwin
โโโ ๐ flake-parts
โโโ ๐ home
โโโ ๐ nixos
๐ overlays
โโโ โ๏ธ default.nix
๐ packages
โโโ โ๏ธ git-squash.nix
โโโ โ๏ธ sshuttle-via.nix
โโโ ๐ twitter-convert
Each of these are wired to the corresponding flake output, as indicated in the below table:
Directory | Flake Output |
---|---|
configurations/nixos/foo.nix 1 | nixosConfigurations.foo |
configurations/darwin/foo.nix 1 | darwinConfigurations.foo |
configurations/home/foo.nix 1 | legacyPackages.${system}.homeConfigurations.foo 2 |
modules/nixos/foo.nix | nixosModules.foo |
modules/darwin/foo.nix | darwinModules.foo |
modules/flake-parts/foo.nix | flakeModules.foo |
overlays/foo.nix | overlays.foo |
flake-parts
Autowiring is also provided if you use just flake-parts, via the lib.mkFlake
function. In your top-level flake.nix, you only need to define your outputs
as follows:
{
inputs = ...;
outputs = inputs:
inputs.nixos-unified.lib.mkFlake
{ inherit inputs; root = ./.; };
}
This will,
- Auto-import flake-parts modules under either
./nix/modules/flake-parts
or./modules/flake-parts
(whichever exists) - Use a sensible default for
systems
which can be overriden. - Pass
root
as top-level module args, as a non-recursive way of referring to the path of the flake (without needinginputs.self
).
See srid/haskell-templateโs flake.nix for a ready example. For another example, see this emanote PR.
This path could as well be configurations/nixos/foo/default.nix
. Likewise for other output types.
Why legacyPackages
? Because, creating a home-manager configuration requires pkgs
. See https://github.com/nix-community/home-manager/issues/3075