From 94626bb28bff7ddecbda304b086c5d2aec05fa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 15 Jan 2024 08:45:51 +0200 Subject: [PATCH] some linters --- .gitignore | 2 ++ flake.lock | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 38 ++++++++++++++++++++++++---- 3 files changed, 106 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 621bc82..f083d0b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ __pycache__ db.sqlite3 + +/.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index 5cc0d6b..4bed477 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "flake-compat": { + "locked": { + "lastModified": 1688025799, + "narHash": "sha256-ktpB4dRtnksm9F5WawoIkEneh1nrEvuxb5lJFt1iOyw=", + "owner": "nix-community", + "repo": "flake-compat", + "rev": "8bf105319d44f6b9f0d764efa4fdef9f1cc9ba1c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -54,6 +69,26 @@ "url": "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-Country.mmdb" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "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" + } + }, "nixpkgs": { "locked": { "lastModified": 1704420045, @@ -70,13 +105,48 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "flake-utils": [ + "flake-utils" + ], + "gitignore": [ + "gitignore" + ], + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixpkgs" + ] + }, + "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-compat": "flake-compat", "flake-utils": "flake-utils", "geoip2-asn": "geoip2-asn", "geoip2-city": "geoip2-city", "geoip2-country": "geoip2-country", - "nixpkgs": "nixpkgs" + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } }, "systems": { diff --git a/flake.nix b/flake.nix index 0cefd0f..e21a743 100644 --- a/flake.nix +++ b/flake.nix @@ -19,15 +19,32 @@ url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-Country.mmdb"; flake = false; }; + + flake-compat.url = "github:nix-community/flake-compat"; + gitignore.url = "github:hercules-ci/gitignore.nix"; + gitignore.inputs.nixpkgs.follows = "nixpkgs"; + + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs = { + nixpkgs.follows = "nixpkgs"; + nixpkgs-stable.follows = "nixpkgs"; + flake-compat.follows = "flake-compat"; + flake-utils.follows = "flake-utils"; + gitignore.follows = "gitignore"; + }; + }; }; outputs = { self, nixpkgs, flake-utils, + pre-commit-hooks, geoip2-asn, geoip2-city, geoip2-country, - }: + ... + } @ inputs: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs {inherit system;}; @@ -39,11 +56,21 @@ e11sync = pkgs.callPackage ./pkgs/e11sync.nix {inherit geoip-archive;}; in { - packages.geoip-archive = geoip-archive; - packages.e11sync-static = e11sync-static; - packages.e11sync = e11sync; + packages = { + inherit geoip-archive e11sync-static e11sync; + }; - checks.e11sync-unit = e11sync.passthru.tests.unit; + checks = { + e11sync-unit = e11sync.passthru.tests.unit; + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + alejandra.enable = true; + deadnix.enable = true; + statix.enable = true; + }; + }; + }; apps.e11sync-gunicorn = { type = "app"; @@ -66,6 +93,7 @@ GEOIP_PATH = "${geoip-archive}"; E11SYNC_DEBUG = "1"; LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + inherit (inputs.self.checks.${system}.pre-commit-check) shellHook; }; formatter = pkgs.alejandra;