From f1cfe11d4406e351dbeab0dade5061229463f67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Sat, 4 Nov 2023 14:28:53 +0100 Subject: [PATCH] build(flake): add more treefmt'ers, precommit hack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support for additonal formatters: - alejandra: nix - statix: nix static analysis - deadnix: find dead nix code - rustfmt: rust - shellcheck: bash/shell - taplo: toml - yamlfmt: yaml Furhter, this uses https://github.com/eza-community/eza/pull/609 to make it easy to add new formatters to both the pre-commit-hooks and treefmt by having pre-commit-hooks use whatever is specified in treefmt.nix, with a filter to remove those that pre-commit-hook don't support. Signed-off-by: Christina Sørensen --- .gitignore | 4 ++ .pre-commit-config.yaml | 1 - flake.nix | 41 +++++++++++++------ {k8s => kubernetes}/kustomization.yaml | 2 - {k8s => kubernetes}/resources/deployment.yaml | 16 -------- .../resources/load-balancer-service.yaml | 0 {k8s => kubernetes}/resources/namespace.yaml | 0 {k8s => kubernetes}/resources/service.yaml | 0 treefmt.nix | 9 +++- 9 files changed, 39 insertions(+), 34 deletions(-) delete mode 120000 .pre-commit-config.yaml rename {k8s => kubernetes}/kustomization.yaml (99%) rename {k8s => kubernetes}/resources/deployment.yaml (70%) rename {k8s => kubernetes}/resources/load-balancer-service.yaml (100%) rename {k8s => kubernetes}/resources/namespace.yaml (100%) rename {k8s => kubernetes}/resources/service.yaml (100%) diff --git a/.gitignore b/.gitignore index 75d0d29..3e701db 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,8 @@ powertest.yaml /target /result +# Generated by nix-pre-commit-hooks +/.pre-commit-config.yaml + +# Direnv .direnv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 120000 index d31f091..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1 +0,0 @@ -/nix/store/4phrpqzal7381lab29qv5mx73ixnk0kn-pre-commit-config.json \ No newline at end of file diff --git a/flake.nix b/flake.nix index da3fed5..6018bcd 100644 --- a/flake.nix +++ b/flake.nix @@ -126,23 +126,38 @@ nativeBuildInputs = with pkgs; [rustup toolchain just zip reuse pkg-config openssl vhs]; }; - # for `nix flake check` + # For `nix flake check` checks = { - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - convco.enable = true; - reuse = { - enable = true; - name = "reuse"; - entry = with pkgs; "${pkgs.reuse}/bin/reuse lint"; - pass_filenames = false; - }; + pre-commit-check = let + # some treefmt formatters are not supported in pre-commit-hooks we filter them out for now. + toFilter = + # HACK: This is a nice hack to not have to manually filter we should keep in mind for a future refactor. + # Stolen from eza + ["yamlfmt"]; + filterFn = n: _v: (!builtins.elem n toFilter); + treefmtFormatters = pkgs.lib.mapAttrs (_n: v: {inherit (v) enable;}) (pkgs.lib.filterAttrs filterFn (import ./treefmt.nix).programs); + in + pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = + treefmtFormatters + // { + convco.enable = true; # not in treefmt + reuse = { + enable = true; + name = "reuse"; + entry = with pkgs; "${pkgs.reuse}/bin/reuse lint"; + pass_filenames = false; + }; + }; }; - }; formatting = treefmtEval.config.build.check self; build = packages.check; - test = packages.test; + inherit + (packages) + default + test + ; lint = packages.clippy; }; } diff --git a/k8s/kustomization.yaml b/kubernetes/kustomization.yaml similarity index 99% rename from k8s/kustomization.yaml rename to kubernetes/kustomization.yaml index b49059b..4e54296 100644 --- a/k8s/kustomization.yaml +++ b/kubernetes/kustomization.yaml @@ -7,13 +7,11 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization - # Making sure all resources used are created in a dedicated namespace # Also specific annotations are added for later identification namespace: rime commonAnnotations: provider: kubernetes-cafkafk-rime - # rime resources (namespace, services, deployments, etc) resources: - resources/namespace.yaml diff --git a/k8s/resources/deployment.yaml b/kubernetes/resources/deployment.yaml similarity index 70% rename from k8s/resources/deployment.yaml rename to kubernetes/resources/deployment.yaml index e3f75ef..1974bd8 100644 --- a/k8s/resources/deployment.yaml +++ b/kubernetes/resources/deployment.yaml @@ -2,8 +2,6 @@ # SPDX-FileContributor: Christina Sørensen # # SPDX-License-Identifier: AGPL-3.0-only - ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -39,17 +37,3 @@ spec: ports: - name: http containerPort: 3000 - #resources: - # requests: - # cpu: 200m - # memory: 100Mi - # limits: - # cpu: 300m - # memory: 200Mi - # securityContext: - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # allowPrivilegeEscalation: false - # capabilities: - # drop: - # - all diff --git a/k8s/resources/load-balancer-service.yaml b/kubernetes/resources/load-balancer-service.yaml similarity index 100% rename from k8s/resources/load-balancer-service.yaml rename to kubernetes/resources/load-balancer-service.yaml diff --git a/k8s/resources/namespace.yaml b/kubernetes/resources/namespace.yaml similarity index 100% rename from k8s/resources/namespace.yaml rename to kubernetes/resources/namespace.yaml diff --git a/k8s/resources/service.yaml b/kubernetes/resources/service.yaml similarity index 100% rename from k8s/resources/service.yaml rename to kubernetes/resources/service.yaml diff --git a/treefmt.nix b/treefmt.nix index a790322..5d1c48b 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -5,7 +5,12 @@ { projectRootFile = "Cargo.toml"; programs = { - alejandra.enable = true; - rustfmt.enable = true; + alejandra.enable = true; # nix + statix.enable = true; # nix static analysis + deadnix.enable = true; # find dead nix code + rustfmt.enable = true; # rust + shellcheck.enable = true; # bash/shell + taplo.enable = true; # toml + yamlfmt.enable = true; # yaml }; }