Skip to content

Commit

Permalink
build(flake): add more treefmt'ers, precommit hack
Browse files Browse the repository at this point in the history
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 eza-community/eza#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 <[email protected]>
  • Loading branch information
cafkafk committed Nov 4, 2023
1 parent 31a9962 commit f1cfe11
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 34 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ powertest.yaml
/target
/result

# Generated by nix-pre-commit-hooks
/.pre-commit-config.yaml

# Direnv
.direnv
1 change: 0 additions & 1 deletion .pre-commit-config.yaml

This file was deleted.

41 changes: 28 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down
2 changes: 0 additions & 2 deletions k8s/kustomization.yaml → kubernetes/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# SPDX-FileContributor: Christina Sørensen
#
# SPDX-License-Identifier: AGPL-3.0-only

---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

0 comments on commit f1cfe11

Please sign in to comment.