Convention-based directory structure for Nix flakes.
nixDir is a flake-parts module that automatically discovers and wires up flake outputs based
on directory conventions. Stop writing boilerplate in flake.nix and start organizing your
Nix code in intuitive directories.
Managing flake outputs manually becomes tedious as projects grow. nixDir lets you organize packages, modules, and configurations in well-named directories, and automatically generates the corresponding flake outputs.
It's like Rails' "convention over configuration" for Nix flakes - structure your code predictably, and it "just works".
- Zero-boilerplate outputs: Place files in
nix/packages/,nix/modules/, etc. and they automatically become flake outputs - Portable and non-portable patterns: Use
with-inputs/for modules that need flake inputs, regular directories for portable resources - Cross-platform support: NixOS, nix-darwin, home-manager and devenv modules
- Development environments: Automatic discovery of devShells and devenv configurations
- Platform-aware filtering: Automatically filters packages based on
meta.platforms, only exposing compatible packages for each system - Type safety: Built on flake-parts' module system
# flake.nix
{
outputs = inputs:
inputs.flake-parts.mkFlake { inherit inputs; } {
systems = [ "..." ];
imports = [ inputs.nixDir.flakeModule ];
nixDir = {
enable = true;
root = ./.;
};
};
}Create nix/packages/hello.nix, run nix build .#hello - done!
See Getting Started Guide for complete setup.
See the docs/ directory for comprehensive guides:
- Getting Started - Installation and first steps
- Directory Structure - How to organize your code
- With-Inputs Pattern - Using flake inputs in outputs
- Testing - Running the test suite
See the example/ directory for a complete working project demonstrating nixDir features.
Key options:
enable/root- RequireddirName- Config directory name (default:"nix")installFlakeOverlay- Make packages available inpkgsacross all your outputsfilterUnsupportedSystems- Filter packages bymeta.platforms(default:true)- Note: Automatically disabled when
generateAllPackage = trueto avoid infinite recursion
- Note: Automatically disabled when
See example flake.nix for all options.
| Directory | Output |
|---|---|
nix/packages/ |
packages.<system>.<name> |
nix/devshells/ |
devShells.<system>.<name> |
nix/devenvs/ |
devenv.shells.<name> |
nix/modules/nixos/ |
nixosModules.<name> |
nix/modules/darwin/ |
darwinModules.<name> |
nix/configurations/nixos/ |
nixosConfigurations.<name> |
nix/with-inputs/*/ |
Non-portable versions |
See Directory Structure for complete details.
Contributions are welcome! See CONTRIBUTING.md for guidelines.
MIT