Skip to content
Public template

About

Nix flake template with nixfmt-tree, deadnix, statix, and pre-commit hooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nix template

Nix flake template for Nix projects, built on purr and git-hooks.nix. Part of develop-templates.

Setup

Initialize in the current directory:

nix flake init -t "github:nixcafe/develop-templates#nix" --refresh

Or register the template flake once under beans:

nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#nix

If you use cattery-modules, beans is already registered.

To create a new GitHub repository directly:

gh repo create my-nix-project --template nixcafe-develop/nix --clone

Enter the shell:

direnv allow
# or
nix develop

No flake.lock is shipped. The first Nix command generates one.

Tools

Tool Role
nixfmt Formats Nix files (nix fmt)
deadnix Finds unused Nix bindings
statix Lints Nix files

All three tools are in the dev shell and enabled as git pre-commit hooks. Entering the shell installs the hooks. deadnix only checks and fails on dead code. Run deadnix --edit . to remove unused bindings.

Layout

.
├── .envrc
├── .gitignore
├── flake.nix
├── statix.toml
└── develop/
    ├── checks/
    │   └── git-hooks/
    │       └── default.nix
    └── shells/
        └── default/
            └── default.nix

Customization

Shell packages

Edit develop/shells/default/default.nix:

packages = with pkgs; [
  nixfmt
  deadnix
  statix
  just
];

Keep shellHook and buildInputs wired to gitHooks so pre-commit hooks stay active.

Pre-commit hooks

Edit develop/checks/git-hooks/default.nix:

{ inputs, system, ... }:
inputs.git-hooks.lib.${system}.run {
  src = ../../..;

  hooks = {
    nixfmt.enable = true;
    deadnix.enable = true;
    statix.enable = true;
  };
}

Linter rules

Adjust statix.toml at the repository root:

disabled = ["repeated_keys"]
ignore = ['.direnv']
nix_version = '2.4'

Commands

nix develop        # open dev shell
nix fmt            # format Nix files
nix flake check    # run git-hooks check
statix check .     # lint Nix files
deadnix --fail .   # check for dead code
deadnix --edit .   # remove dead code

About

Nix flake template with nixfmt-tree, deadnix, statix, and pre-commit hooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages