From 2e9b6911d98e8189d77cf791aa743c81fcd76534 Mon Sep 17 00:00:00 2001 From: jayrovacsek Date: Tue, 5 Nov 2024 20:40:55 +1100 Subject: [PATCH] feat: add nix based checks --- .envrc | 1 + .github/workflows/checks.yml | 12 +++ .gitignore | 1 + flake.lock | 184 +++++++++++++++++++++++++++++++++++ flake.nix | 112 +++++++++++++++++++++ 5 files changed, 310 insertions(+) create mode 100644 .envrc create mode 100644 .github/workflows/checks.yml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..8392d159 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 00000000..f66d34bd --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,12 @@ +name: checks + +on: + push: + +jobs: + checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: DeterminateSystems/nix-installer-action@main + - run: nix flake check -Lv diff --git a/.gitignore b/.gitignore index 67241276..10ebc9cb 100755 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ yarn.lock /playwright-report/ /blob-report/ /playwright/.cache/ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..6e1a6614 --- /dev/null +++ b/flake.lock @@ -0,0 +1,184 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1728330715, + "narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=", + "owner": "numtide", + "repo": "devshell", + "rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "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" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": ["nixpkgs"], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1730797577, + "narHash": "sha256-SrID5yVpyUfknUTGWgYkTyvdr9J1LxUym4om3SVGPkg=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "1864030ed24a2b8b4e4d386a5eeaf0c5369e50a9", + "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" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1730207686, + "narHash": "sha256-SCHiL+1f7q9TAnxpasriP6fMarWE5H43t25F5/9e28I=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "776e68c1d014c3adde193a18db9d738458cd2ba4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722073938, + "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils", + "git-hooks": "git-hooks", + "nix-filter": "nix-filter", + "nixpkgs": "nixpkgs_2" + } + }, + "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 new file mode 100644 index 00000000..d5a6d1d6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,112 @@ +{ + description = "Nodejs Dev Shell"; + + inputs = { + devshell.url = "github:numtide/devshell"; + flake-utils.url = "github:numtide/flake-utils"; + git-hooks = { + inputs.nixpkgs.follows = "nixpkgs"; + url = "github:cachix/git-hooks.nix"; + }; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + + nix-filter.url = "github:numtide/nix-filter"; + }; + + outputs = + { + devshell, + flake-utils, + git-hooks, + nixpkgs, + nix-filter, + self, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + app-source = nix-filter.lib.filter { + root = ./.; + exclude = [ ]; + + include = [ + "src" + (nix-filter.lib.matchExt "js") + (nix-filter.lib.matchExt "json") + (nix-filter.lib.matchExt "ts") + ]; + }; + + pkg-lock = builtins.fromJSON (builtins.readFile ./package.json); + + pkgs = import nixpkgs { + overlays = [ devshell.overlays.default ]; + inherit system; + }; + in + { + checks.git-hooks = git-hooks.lib.${system}.run { + src = self; + hooks = { + actionlint.enable = true; + + deadnix = { + enable = true; + settings.edit = true; + }; + + nixfmt-rfc-style.enable = true; + + prettier = { + enable = true; + settings.write = true; + }; + + statix.enable = true; + + statix-write = { + enable = true; + name = "Statix Write"; + entry = "${pkgs.statix}/bin/statix fix"; + language = "system"; + pass_filenames = false; + }; + + trufflehog-verified = { + enable = pkgs.stdenv.isLinux; + name = "Trufflehog Search"; + entry = "${pkgs.trufflehog}/bin/trufflehog git file://. --since-commit HEAD --only-verified --fail --no-update"; + language = "system"; + pass_filenames = false; + }; + }; + }; + + devShells.default = pkgs.devshell.mkShell { + devshell.startup.git-hooks.text = self.checks.${system}.git-hooks.shellHook; + name = "dev-shell"; + packages = with pkgs; [ + deadnix + nixfmt-rfc-style + nodejs_20 + nodePackages.prettier + nodePackages.typescript + statix + ]; + }; + + formatter = pkgs.nixfmt-rfc-style; + + packages = { + newwwie = pkgs.buildNpmPackage { + inherit (pkg-lock) version; + pname = "newwwie"; + src = app-source; + npmDepsHash = "sha256-FGQpZmR5uSh3kLYyRPLG4KlQnnOzUxnJKeVkCVMabZM="; + }; + }; + } + ); + +}