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 new file mode 100644 index 0000000..7e3a1d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# direnv cache +/.direnv + +# "nix build" default output link +result + +# nix pre-commit autogenerated by devShell +/.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0f19bde --- /dev/null +++ b/flake.lock @@ -0,0 +1,102 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1774104215, + "narHash": "sha256-EAtviqz0sEAxdHS4crqu7JGR5oI3BwaqG0mw7CmXkO8=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "f799ae951fde0627157f40aec28dec27b22076d0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1774623183, + "narHash": "sha256-Oi8z/LMdeGaBBhe1v4P3wRcwbfJjjq1hjpF5EVgnxyA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "73e3cc5c77627ac9037a197e196ae88f5b209121", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "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", + "version": 7 +} diff --git a/flake.nix b/flake.nix index a3ed870..d0bbaf7 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,54 @@ { description = "Shared Nix settings (NixOS, Home Manager etc)"; - outputs = { self }: { - nixosModules = { - nix-settings = import ./modules/nix-settings.nix; - nix-gc = import ./modules/nix-gc.nix; - futureware = import ./modules/futureware.nix; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + systems.url = "github:nix-systems/default"; + git-hooks = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; }; }; + + outputs = + { + self, + nixpkgs, + systems, + git-hooks, + ... + }: + let + eachSystem = nixpkgs.lib.genAttrs (import systems); + in + { + nixosModules = { + nix-settings = import ./modules/nix-settings.nix; + nix-gc = import ./modules/nix-gc.nix; + futureware = import ./modules/futureware.nix; + }; + + lib.pre-commit = import ./pre-commit.nix; + + checks = eachSystem (system: { + pre-commit-check = git-hooks.lib.${system}.run { + src = ./.; + inherit (self.lib.pre-commit) hooks; + }; + }); + + devShells = eachSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages; + in + { + default = pkgs.mkShell { + packages = enabledPackages; + inherit shellHook; + }; + } + ); + }; } diff --git a/pre-commit.nix b/pre-commit.nix new file mode 100644 index 0000000..ed8bf1f --- /dev/null +++ b/pre-commit.nix @@ -0,0 +1,21 @@ +{ + hooks = { + check-added-large-files.enable = true; + check-case-conflicts.enable = true; + check-executables-have-shebangs.enable = true; + check-merge-conflicts.enable = true; + check-symlinks.enable = true; + check-vcs-permalinks.enable = true; + check-yaml.enable = true; + end-of-file-fixer.enable = true; + trim-trailing-whitespace.enable = true; + ripsecrets.enable = true; + + # Nix + flake-checker.enable = true; + nixfmt-rfc-style.enable = true; + deadnix.enable = true; + nil.enable = true; + statix.enable = true; # Use: statix fix + }; +}