Implement pre-commit using the pre-commit-hooks flake

This commit is contained in:
Daniel Flanagan 2024-02-23 10:35:41 -06:00
parent 6a13c7421a
commit b2f8891ebe
Signed by: lytedev
GPG Key ID: 5B2020A0F9921EF4
6 changed files with 140 additions and 21 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

6
.gitignore vendored
View File

@ -1,3 +1,7 @@
*.log
/.direnv
result
.pre-commit-config.yaml
*.log
*.qcow2

View File

@ -62,6 +62,22 @@
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
@ -80,6 +96,45 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1703887061,
"narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"hardware": {
"locked": {
"lastModified": 1708091350,
@ -154,6 +209,22 @@
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1704874635,
"narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1708118438,
@ -170,6 +241,30 @@
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1708018599,
"narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"api-lyte-dev": "api-lyte-dev",
@ -178,6 +273,7 @@
"helix": "helix",
"home-manager": "home-manager",
"nixpkgs": "nixpkgs_2",
"pre-commit-hooks": "pre-commit-hooks",
"sops-nix": "sops-nix",
"ssbm": "ssbm"
}
@ -281,6 +377,21 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -2,6 +2,10 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks.inputs.nixpkgs-unstable.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager/master";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
@ -37,6 +41,7 @@
self,
nixpkgs,
home-manager,
pre-commit-hooks,
api-lyte-dev,
...
} @ inputs: let
@ -67,6 +72,20 @@
# Other options beside 'alejandra' include 'nixpkgs-fmt'
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
checks = forAllSystems (system: {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
};
};
});
devShell = forAllSystems (system:
nixpkgs.legacyPackages.${system}.mkShell {
inherit (outputs.checks.${system}.pre-commit-check) shellHook;
});
# Your custom packages and modifications, exported as overlays
overlays = import ./overlays {inherit inputs;};

View File

@ -1,7 +0,0 @@
#!/usr/bin/env bash
set -eux
nix flake check
nix run nixpkgs#alejandra -- --check .
# TODO: check commit message format

View File

@ -19,14 +19,6 @@ You don't have even have to clone this crap yourself. How cool is that! But if y
$ nixos-rebuild switch --flake ./repo/dir/for/nix#${FLAKE_ATTR}
```
## Setup
If you're gonna change stuff you had better setup the pre-commit hook:
```shell_session
$ ln -s $PWD/pre-commit.bash .git/hooks/pre-commit
```
## Secrets
If you're deploying anything secrets-related, you will need the proper keys:
@ -39,18 +31,17 @@ $ pass age-key >> ${XDG_CONFIG_HOME:-~/.config}/sops/age/keys.txt
## NixOS
```shell_session
$ nixos-rebuild switch --flake
$ nixos-rebuild switch --flake .
```
## Not NixOS
**NOTE**: I pretty much solely use Home Manager as a NixOS module presently, so this is not fully supported.
**NOTE**: I pretty much solely use Home Manager as a NixOS module presently, so
this is not fully supported.
```shell_session
$ curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
$ nix profile install github:nix-community/home-manager
$ FLAKE_ATTR=base-x86_64-linux
$ home-manager switch --flake git+https://git.lyte.dev/lytedev/nix#$FLAKE_ATTR
$ nix run github:nix-community/home-manager switch --flake git+https://git.lyte.dev/lytedev/nix#${FLAKE_ATTR}
```
# Internal/Advanced Usage