Skip to content

jmgilman/nix-pre-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nix-pre-commit

Generate pre-commit configurations with your flake.nix

Usage

Add it as an input to your flake and define the pre-commit configuration:

{
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:nixos/nixpkgs";
    nix-pre-commit.url = "github:jmgilman/nix-pre-commit";
  };

  outputs = { self, nixpkgs, flake-utils, nix-pre-commit }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };

        config = {
          repos = [
            {
              repo = "local";
              hooks = [
                {
                  id = "nixpkgs-fmt";
                  entry = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt";
                  language = "system";
                  files = "\\.nix";
                }
              ];
            }
          ];
        };
      in
      {
        devShell = pkgs.mkShell {
          shellHook = (nix-pre-commit.lib.${system}.mkConfig {
            inherit pkgs config;
          }).shellHook;
        };
      }
    );
}

This produces a .pre-commit-config.yaml in the local directory:

default_stages:
  - commit
repos:
  - hooks:
      - entry: /nix/store/l9vwl9yvjmdj3pixlj5i9kc4524bh78r-nixpkgs-fmt-1.2.0/bin/nixpkgs-fmt
        files: \.nix
        id: nixpkgs-fmt
        language: system
        name: nixpkgs-fmt
    repo: local

The structure for the configuration specified in flake.nix matches the defined structure of the .pre-commit-config.yaml file. A small bootstrapping script is supplied via a shellHook which links the generated config into the local directory and installs the hooks.

Contributing

Check out the issues for items needing attention or submit your own and then:

  1. Fork the repo (https://github.com/jmgilman/dev-container/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

About

Generate pre-commit configurations with your flake.nix

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages