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 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.
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):
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):
mkdir -p project
nix flake init -t github:terlar/dev-flake#subflake-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):
mkdir -p dev
cd dev
nix flake init -t github:terlar/dev-flake#root
Create a new project (template):
mkdir -p project
nix flake init -t github:terlar/dev-flake#root-project