Skip to content

roman/nixDir

 
 

Repository files navigation

nixDir

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.

Why Directory Conventions?

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

Features

  • 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

Getting Started

# 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.

Documentation

See the docs/ directory for comprehensive guides:

Examples

See the example/ directory for a complete working project demonstrating nixDir features.

Configuration Options

Key options:

  • enable / root - Required
  • dirName - Config directory name (default: "nix")
  • installFlakeOverlay - Make packages available in pkgs across all your outputs
  • filterUnsupportedSystems - Filter packages by meta.platforms (default: true)
    • Note: Automatically disabled when generateAllPackage = true to avoid infinite recursion

See example flake.nix for all options.

Directory Structure Overview

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.

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

MIT

About

Transform a directory into a nix flake

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published