Skip to content

Commit

Permalink
feat: nix template
Browse files Browse the repository at this point in the history
  • Loading branch information
huuff committed Sep 20, 2024
1 parent 99a71cd commit e294af6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions nix/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
2 changes: 2 additions & 0 deletions nix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.direnv
/.pre-commit-config.yaml
73 changes: 73 additions & 0 deletions nix/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
description = "Template for Nix project";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
pre-commit.url = "github:cachix/git-hooks.nix";
treefmt.url = "github:numtide/treefmt-nix";
systems.url = "github:nix-systems/x86_64-linux";
utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
};

outputs =
{
self,
nixpkgs,
utils,
pre-commit,
treefmt,
...
}:
utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
treefmtEval = treefmt.lib.evalModule pkgs ./treefmt.nix;
in
{
checks = {
pre-commit-check = pre-commit.lib.${system}.run {
src = ./.;
hooks = {
gitleaks = {
name = "gitleaks";
enable = true;
entry = "${pkgs.gitleaks}/bin/gitleaks detect";
stages = [ "pre-commit" ];
};

treefmt = {
enable = true;
packageOverrides.treefmt = treefmtEval.config.build.wrapper;
};

statix.enable = true;
deadnix.enable = true;
nil.enable = true;
};
};

# just check formatting is ok without changing anything
formatting = treefmtEval.config.build.check self;
};

# for `nix fmt`
formatter = treefmtEval.config.build.wrapper;

devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs =
with pkgs;
self.checks.${system}.pre-commit-check.enabledPackages
++ [
nil
nixfmt-rfc-style
];
};
}
);

}
7 changes: 7 additions & 0 deletions nix/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_: {
projectRootFile = "flake.nix";

programs = {
nixfmt.enable = true;
};
}

0 comments on commit e294af6

Please sign in to comment.