Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

terlar/dev-flake

Nix flake to support the pattern of using a separate development flake

terlar/dev-flake.json
{
"createdAt": "2023-07-07T06:01:03Z",
"defaultBranch": "main",
"description": "Nix flake to support the pattern of using a separate development flake",
"fullName": "terlar/dev-flake",
"homepage": null,
"language": "Nix",
"name": "dev-flake",
"pushedAt": "2025-11-20T16:48:41Z",
"stargazersCount": 10,
"topics": [],
"updatedAt": "2025-11-03T08:32:52Z",
"url": "https://github.com/terlar/dev-flake"
}

Nix flake to support the pattern of using a separate development sub-flake. dev-flake can also be used within the root flake. The integration is done via flake-parts.

Features are enabled by default in order to get “the best experience out of the box”, however it is possible to opt-out from the default configuration and/or add additional configuration. See available configuration options in the [flake module interface]!(flake-module/interface.nix) and the corresponding documentation for each dependency flake module.

Dependency flake modules:

The default devShell is provided via devshell.

  • Installs pre-commit hooks.
  • Menu with available commands.
  • Named shell prompt
  • Can be used together with direnv for seamless shell integration.
    • See the example [subflake-project template]!(template/subflake-project).

treefmt is a nice abstraction on top of formatters to format the whole project.

To configure more formatters, see the treefmt-nix documentation.

pre-commit is a framework to configure and run git hooks before commit. Usually formatting and linting.

  • Configures flake check to run pre-commit hooks
  • Enables hooks for:
    • deadnix
    • statix
    • treefmt

To configure more pre-commit hooks, see the git-hooks-nix documentation.

To avoid polluting the top-level flake inputs with development inputs, dev-flake can be used in a subflake.

Within an existing project ([template]!(template/subflake)):

Terminal window
mkdir -p dev
cd dev
nix flake init -t github:terlar/dev-flake

Add the following to your flake-parts config:

# ...
imports = [ inputs.flake-parts.flakeModules.partitions ];
partitionedAttrs = {
checks = "dev";
devShells = "dev";
};
partitions.dev = {
extraInputsFlake = ./dev;
module = { imports = [ ./dev/flake-module.nix ]; };
};
# ...

Create a new project ([template]!(template/subflake-project)):

Terminal window
mkdir -p project
nix flake init -t github:terlar/dev-flake#subflake-project

If you are creating a flake-parts library or some other flake that only produce system outputs for development purposes, you do not need to include nixpkgs within the main flake.

Within an existing project ([template]!(template/subflake-nixpkgs)):

Terminal window
mkdir -p dev
cd dev
nix flake init -t github:terlar/dev-flake#subflake-nixpkgs

Add the following to your flake-parts config:

# ...
imports = [ inputs.flake-parts.flakeModules.partitions ];
systems = [ ];
partitionedAttrs = {
checks = "dev";
devShells = "dev";
};
partitions.dev = {
extraInputsFlake = ./dev;
module = { imports = [ ./dev/flake-module.nix ]; };
};
# ...

Create a new project ([template]!(template/subflake-nixpkgs-project)):

Terminal window
mkdir -p project
nix flake init -t github:terlar/dev-flake#subflake-nixpkgs-project

You can also use this flake in the root flake, when using flake-parts, all you need to do is import the flake.

{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
dev-flake.url = "github:terlar/dev-flake";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
imports = [ inputs.dev-flake.flakeModule ];
dev.name = "my-project";
};
}

Within an existing project ([template]!(template/root)):

Terminal window
mkdir -p dev
cd dev
nix flake init -t github:terlar/dev-flake#root

Create a new project ([template]!(template/root-project)):

Terminal window
mkdir -p project
nix flake init -t github:terlar/dev-flake#root-project