Skip to content

terlar/dev-flake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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:

Default devShell

The default devShell is provided via devshell.

treefmt

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 hooks

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.

Usage

Subflake

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

Existing project

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 ]; };
};
# ...

New project

Create a new project (template):

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

Subflake (with nixpkgs)

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.

Existing project

Within an existing project (template):

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 ]; };
};
# ...

New project

Create a new project (template):

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

Root flake

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

Examples

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •