From 35cf87eb2ea6ab3c5b9753137bb7787a0a8ae892 Mon Sep 17 00:00:00 2001 From: James Walker Date: Wed, 26 Jul 2023 13:04:43 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20add=20pre-commit-hooks=20and=20c?= =?UTF-8?q?leanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- darwin/configuration.nix | 18 +++--- darwin/homebrew.nix | 2 +- flake.lock | 125 ++++++++++++++++++++++++++++++++++++--- flake.nix | 29 ++++++++- home.nix | 2 +- modules/default.nix | 2 +- modules/dev.nix | 2 +- modules/emacs.nix | 2 +- modules/git.nix | 2 +- modules/tmux.nix | 2 +- modules/zsh.nix | 3 +- 12 files changed, 163 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index d1da3a8..84197ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result -.direnv \ No newline at end of file +.direnv +/.pre-commit-config.yaml diff --git a/darwin/configuration.nix b/darwin/configuration.nix index e333dab..9522502 100644 --- a/darwin/configuration.nix +++ b/darwin/configuration.nix @@ -68,16 +68,14 @@ }; }; - system.activationScripts.applications.text = pkgs.lib.mkForce ( - '' - rm -rf /Applications/Nix - mkdir -p /Applications/Nix - for app in $(find ${config.system.build.applications}/Applications -maxdepth 1 -type l); do - src="$(/usr/bin/stat -f%Y "$app")" - cp -r "$src" /Applications/Nix - done - '' - ); + system.activationScripts.applications.text = pkgs.lib.mkForce '' + rm -rf /Applications/Nix + mkdir -p /Applications/Nix + for app in $(find ${config.system.build.applications}/Applications -maxdepth 1 -type l); do + src="$(/usr/bin/stat -f%Y "$app")" + cp -r "$src" /Applications/Nix + done + ''; # Used for backwards compatibility, please read the changelog before changing. # $ darwin-rebuild changelog diff --git a/darwin/homebrew.nix b/darwin/homebrew.nix index eaf12c6..d1ed823 100644 --- a/darwin/homebrew.nix +++ b/darwin/homebrew.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +_: { homebrew = { diff --git a/flake.lock b/flake.lock index 66d4168..08172a3 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,6 +34,45 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -25,11 +80,11 @@ ] }, "locked": { - "lastModified": 1690208251, - "narHash": "sha256-eb/KANeuQADVl5j4wVid4jyPCOMTorSI2+gqoXp3LME=", + "lastModified": 1690303752, + "narHash": "sha256-2YiwFHQERGoaORNORmsdmVlPD8CVVwlwbV2+f77sFhg=", "owner": "nix-community", "repo": "home-manager", - "rev": "d309a62ee81faec56dd31a263a0184b0e3227e36", + "rev": "ba2c0737cc848db03470828fdb5e86df75ed42a8", "type": "github" }, "original": { @@ -40,11 +95,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1690083312, - "narHash": "sha256-I3egwgNXavad1eIjWu1kYyi0u73di/sMmlnQIuzQASk=", + "lastModified": 1690327932, + "narHash": "sha256-Fv7PYZxN4eo0K6zXhHG/vOc+e2iuqQ5ywDrh0yeRjP0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "af8cd5ded7735ca1df1a1174864daab75feeb64a", + "rev": "a9b47d85504bdd199e90846622c76aa0bfeabfac", "type": "github" }, "original": { @@ -54,11 +109,52 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "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": 1689668210, + "narHash": "sha256-XAATwDkaUxH958yXLs1lcEOmU6pSEIkatY3qjqk8X0E=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "eb433bff05b285258be76513add6f6c57b441775", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", "home-manager": "home-manager", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } }, "systems": { @@ -75,6 +171,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", diff --git a/flake.nix b/flake.nix index 5bdba72..163d6e0 100644 --- a/flake.nix +++ b/flake.nix @@ -4,11 +4,18 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; - home-manager.url = "github:nix-community/home-manager"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; - outputs = { self, nixpkgs, home-manager, flake-utils, ... }: + outputs = { self, nixpkgs, home-manager, flake-utils, pre-commit-hooks, ... }: flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ] (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -28,12 +35,28 @@ packages.default = self.homeConfigurations.${system}.walkah.activationPackage; + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + deadnix.enable = true; + nixpkgs-fmt.enable = true; + statix.enable = true; + }; + }; + }; + + devShells.default = pkgs.mkShell { name = "dotfiles"; buildInputs = with pkgs; [ + deadnix nil nixpkgs-fmt + statix ]; + + inherit (self.checks.${system}.pre-commit-check) shellHook; }; }); } diff --git a/home.nix b/home.nix index 7659e4b..e587c4a 100644 --- a/home.nix +++ b/home.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: { +{ pkgs, ... }: { # Let Home Manager install and manage itself. programs.home-manager.enable = true; diff --git a/modules/default.nix b/modules/default.nix index 65e7eb3..ff0468e 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ ... }: { imports = [ diff --git a/modules/dev.nix b/modules/dev.nix index e5b02a1..8e2e1d4 100644 --- a/modules/dev.nix +++ b/modules/dev.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +_: { home.file.".ghci".text = '' diff --git a/modules/emacs.nix b/modules/emacs.nix index d0e9852..b2e1d06 100644 --- a/modules/emacs.nix +++ b/modules/emacs.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ pkgs, ... }: { home.packages = with pkgs; [ diff --git a/modules/git.nix b/modules/git.nix index 57d4ffe..a0cc5c0 100644 --- a/modules/git.nix +++ b/modules/git.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +_: { programs = { diff --git a/modules/tmux.nix b/modules/tmux.nix index bc383da..d57dc4a 100644 --- a/modules/tmux.nix +++ b/modules/tmux.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ pkgs, ... }: { programs = { diff --git a/modules/zsh.nix b/modules/zsh.nix index 7f2831e..b176f63 100644 --- a/modules/zsh.nix +++ b/modules/zsh.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +_: { programs = { @@ -19,6 +19,7 @@ oh-my-zsh = { enable = true; plugins = [ + "1password" "bundler" "direnv" "docker"