diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 4812d58..fad2ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result .direnv/ +.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index a3f221c..06b89ca 100644 --- a/flake.lock +++ b/flake.lock @@ -172,6 +172,22 @@ } }, "flake-compat_2": { + "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-compat_3": { "flake": false, "locked": { "lastModified": 1673956053, @@ -283,6 +299,24 @@ "type": "github" } }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "fromYaml": { "flake": false, "locked": { @@ -299,6 +333,27 @@ "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" + } + }, "haumea": { "inputs": { "nixpkgs": "nixpkgs" @@ -602,6 +657,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": 1705133751, @@ -711,6 +782,30 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_3", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1705229514, + "narHash": "sha256-itILy0zimR/iyUGq5Dgg0fiW8plRDyxF153LWGsg3Cw=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ffa9a5b90b0acfaa03b1533b83eaf5dead819a05", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-schemas": "flake-schemas", @@ -718,6 +813,7 @@ "home-manager": "home-manager", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks", "stylix": "stylix" } }, @@ -731,7 +827,7 @@ "base16-kitty": "base16-kitty", "base16-tmux": "base16-tmux", "base16-vim": "base16-vim", - "flake-compat": "flake-compat_2", + "flake-compat": "flake-compat_3", "home-manager": [ "home-manager" ], @@ -781,6 +877,21 @@ "repo": "default", "type": "github" } + }, + "systems_3": { + "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", diff --git a/flake.nix b/flake.nix index f26c440..8128728 100644 --- a/flake.nix +++ b/flake.nix @@ -23,8 +23,21 @@ inputs.nixos-hardware.url = "https://flakehub.com/f/NixOS/nixos-hardware/0.1.*.tar.gz"; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + # Flake outputs that other flakes can use - outputs = { self, flake-schemas, nixpkgs, stylix, home-manager, home-config, nixos-hardware, ... }: + outputs = + { self + , flake-schemas + , nixpkgs + , stylix + , home-manager + , home-config + , nixos-hardware + , pre-commit-hooks + , ... + }: let inherit (nixpkgs) lib; # Helpers for producing system-specific outputs @@ -43,6 +56,13 @@ # Schemas tell Nix about the structure of your flake's outputs schemas = flake-schemas.schemas; + checks = forEachSupportedSystem ({ pkgs, system }: { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = builtins.path { path = ./.; name = "configuration.nix"; }; + hooks.nixpkgs-fmt.enable = true; + }; + }); + packages = doc; # Nix files formatter (run `nix fmt`) @@ -120,5 +140,12 @@ default = nixosModule; inherit nixosModule; } // machineModules; + + devShells = forEachSupportedSystem ({ pkgs, system }: + { + default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + }; + }); }; }