From 4c08bbd0d9116eeafbedc7ca90d0f671e9029103 Mon Sep 17 00:00:00 2001 From: winston Date: Fri, 10 Feb 2023 10:03:16 +0100 Subject: [PATCH] build: include the pre-commit hooks in the flake itself --- .envrc | 2 +- default.nix | 20 --------- flake.lock | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 76 +++++++++++++++++++++---------- shell.nix | 13 ------ 5 files changed, 178 insertions(+), 60 deletions(-) delete mode 100644 default.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 1d953f4..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use nix +use flake diff --git a/default.nix b/default.nix deleted file mode 100644 index 3993bb7..0000000 --- a/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -let - nix-pre-commit-hooks = - import (builtins.fetchTarball - "https://github.com/cachix/pre-commit-hooks.nix/tarball/master"); -in { - pre-commit-check = nix-pre-commit-hooks.run { - src = ./.; - hooks = { - alejandra.enable = true; - editorconfig-checker.enable = true; - deadnix.enable = true; - shellcheck.enable = true; - stylua.enable = true; - }; - settings.deadnix = { - noLambdaPatternNames = true; - noLambdaArg = true; - }; - }; -} diff --git a/flake.lock b/flake.lock index c73ae69..17e00af 100644 --- a/flake.lock +++ b/flake.lock @@ -21,6 +21,73 @@ "type": "github" } }, + "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": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "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": [ @@ -60,6 +127,22 @@ } }, "nixpkgs-stable": { + "locked": { + "lastModified": 1673800717, + "narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable_2": { "locked": { "lastModified": 1676003493, "narHash": "sha256-D7al8mRCMBu6eOF62Nlx1jzCSU6odbBK/OJVynqnMHc=", @@ -92,6 +175,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1671271357, + "narHash": "sha256-xRJdLbWK4v2SewmSStYrcLa0YGJpleufl44A19XSW8k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "40f79f003b6377bd2f4ed4027dde1f8f922995dd", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1656817495, "narHash": "sha256-QEWkUBH4gu6ntNkF+9xIqDM22bto4PB+LSHIL6oWFpM=", @@ -123,20 +222,44 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1675688762, + "narHash": "sha256-oit/SxMk0B380ASuztBGQLe8TttO1GJiXF8aZY9AYEc=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ab608394886fb04b8a5df3cb0bab2598400e3634", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "darwin": "darwin", + "flake-utils": "flake-utils", "home-manager": "home-manager", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "nur": "nur", + "pre-commit-hooks": "pre-commit-hooks", "sops": "sops" } }, "sops": { "inputs": { - "nixpkgs": "nixpkgs_2", - "nixpkgs-stable": "nixpkgs-stable" + "nixpkgs": "nixpkgs_3", + "nixpkgs-stable": "nixpkgs-stable_2" }, "locked": { "lastModified": 1675872570, diff --git a/flake.nix b/flake.nix index 9b8afff..3746266 100644 --- a/flake.nix +++ b/flake.nix @@ -16,12 +16,18 @@ }; nur.url = "github:nix-community/NUR/master"; sops.url = "github:Mic92/sops-nix/master"; + + # dev + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, darwin, home-manager, + flake-utils, + pre-commit-hooks, nixpkgs, nixpkgs-unstable, nur, @@ -34,34 +40,56 @@ config.allowUnfree = true; }; }; - in { - darwinConfigurations = { - "sashimi-slicer" = darwin.lib.darwinSystem rec { - system = "aarch64-darwin"; + in + { + darwinConfigurations = { + "sashimi-slicer" = darwin.lib.darwinSystem rec { + system = "aarch64-darwin"; - modules = [ - home-manager.darwinModules.home-manager + modules = [ + home-manager.darwinModules.home-manager - ./darwin.nix + ./darwin.nix - ({config, ...}: { - config = { - nixpkgs.overlays = [overlay-unstable]; - nixpkgs.config.allowUnfree = true; - home-manager = { - useGlobalPkgs = true; - users.winston.imports = [./home.nix]; - extraSpecialArgs = { - nur = nur.nixosModules.nur; - sops = sops.homeManagerModules.sops; - flakePath = "/Users/winston/.config/nixpkgs"; - machine.personal = true; + ({config, ...}: { + config = { + nixpkgs.overlays = [overlay-unstable]; + nixpkgs.config.allowUnfree = true; + home-manager = { + useGlobalPkgs = true; + users.winston.imports = [./home.nix]; + extraSpecialArgs = { + nur = nur.nixosModules.nur; + sops = sops.homeManagerModules.sops; + flakePath = "/Users/winston/.config/nixpkgs"; + machine.personal = true; + }; }; }; - }; - }) - ]; + }) + ]; + }; }; - }; - }; + } + // flake-utils.lib.eachDefaultSystem (system: { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + alejandra.enable = true; + editorconfig-checker.enable = true; + deadnix.enable = true; + shellcheck.enable = true; + stylua.enable = true; + }; + settings.deadnix = { + noLambdaPatternNames = true; + noLambdaArg = true; + }; + }; + }; + devShell = nixpkgs.legacyPackages.${system}.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + }; + }); } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index c7a15d3..0000000 --- a/shell.nix +++ /dev/null @@ -1,13 +0,0 @@ -let - pkgs = import {}; -in - pkgs.mkShell { - buildInputs = with pkgs; [ - git - git-secret - just - ]; - shellHook = '' - ${(import ./default.nix).pre-commit-check.shellHook} - ''; - }