From cdef7656ffc7bd209ba7fc7c3e9279af62e90e34 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 28 Jun 2024 09:27:48 -0600 Subject: [PATCH 1/3] all: use treefmt for formatting everything --- lib/default.nix | 2 ++ treefmt.toml | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 treefmt.toml diff --git a/lib/default.nix b/lib/default.nix index 3a4a1a1..9b7faf5 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -101,6 +101,8 @@ let ssh-to-age ssh-to-pgp statix + treefmt2 + perlPackages.PerlTidy ]; }; diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 0000000..fd34c9f --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,28 @@ +[formatter.statix] +command = "statix" +options = ["check"] +priority = 1 + +[formatter.deadnix] +command = "deadnix" +options = ["-f"] +includes = [ "*.nix" ] +priority = 2 + +[formatter.nix] +command = "nix" +options = ["fmt"] +includes = ["*.nix"] +priority = 3 + +[formatter.shfmt] +command = "shfmt" +options = ["-w"] +includes = ["*.sh", "bin/*"] +priority = 1 + +[formatter.perltidy] +command = "perltidy" +options = ["-b"] +includes = ["*.pl", "*.PL"] +priority = 1 \ No newline at end of file From 5e5129e5114f1720432797072140110bd855edb2 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 28 Jun 2024 09:37:50 -0600 Subject: [PATCH 2/3] all: fmt --- bin/ci | 3 +-- bin/repair | 3 +-- bin/update-openssh | 14 +++++++------- common.sh | 2 +- pkgs/flake-warn.sh | 4 ++-- templates/mojo/thing.pl | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/bin/ci b/bin/ci index ceaaa4a..545812e 100755 --- a/bin/ci +++ b/bin/ci @@ -47,7 +47,7 @@ if [ "${1}" = "update" ]; then git add pull_requests git commit -m 'watched: update watched pull requests' fi - + for inp in $(nix flake metadata --json | jq -r '.locks.nodes.root.inputs | keys[] as $k | $k'); do if ! git checkout -b "${ci_branch}_${inp}"; then handle_co_fail "${ci_branch}_${inp}" @@ -88,7 +88,6 @@ if [ "${1}" = "update" ]; then exit 1 fi - if ! git checkout main; then handle_co_fail exit 1 diff --git a/bin/repair b/bin/repair index a4c3d65..1cf513e 100755 --- a/bin/repair +++ b/bin/repair @@ -1,5 +1,4 @@ -#!/bin/sh - +#!/usr/bin/env bash while nix flake check --no-build |& grep "is not valid" >/tmp/invalid; do path=$(cat /tmp/invalid | awk -F\' '{print $2}') diff --git a/bin/update-openssh b/bin/update-openssh index 74ea956..4a45e11 100755 --- a/bin/update-openssh +++ b/bin/update-openssh @@ -20,15 +20,15 @@ CURRENT_COMMIT="$(echo $CURRENT | jq -r .rev)" if [ "${CURRENT_COMMIT}" != "${COMMIT}" ]; then nix-prefetch-github openssh openssh-portable \ --rev "${COMMIT}" \ - --json | \ + --json | jq -r --arg v "${UPDATED}" \ - --arg c "${COMMENT}" \ - '. |= . + {"version": $v, "comment": $c}' \ - > pkgs/openssh/version.json + --arg c "${COMMENT}" \ + '. |= . + {"version": $v, "comment": $c}' \ + >pkgs/openssh/version.json FN=$(mktemp) - echo "pkgs/openssh: update to '${COMMIT}'" > ${FN} - echo >> ${FN} - echo "${COMMENT}" >> ${FN} + echo "pkgs/openssh: update to '${COMMIT}'" >${FN} + echo >>${FN} + echo "${COMMENT}" >>${FN} git add pkgs/openssh/version.json && git commit -F $FN else echo "No updates." diff --git a/common.sh b/common.sh index 03978b6..47921e0 100644 --- a/common.sh +++ b/common.sh @@ -56,7 +56,7 @@ resolveAlias() { agentHasKey() { checkKey="$(echo $1 | awk '{print $NF}')" for i in $AgentKeys; do - if [[ "$i" == $checkKey ]]; then + if [[ $i == $checkKey ]]; then return 0 fi done diff --git a/pkgs/flake-warn.sh b/pkgs/flake-warn.sh index 3cc9676..300ae40 100644 --- a/pkgs/flake-warn.sh +++ b/pkgs/flake-warn.sh @@ -9,10 +9,10 @@ NORMAL=$(tput sgr0) FLAKE_EPOCH=$(@nix@/bin/nix flake metadata --json | @jq@/bin/jq .lastModified) NOW_EPOCH=$(@coreutils@/bin/date +"%s") -EPOCH_DIFF=$(($NOW_EPOCH - $FLAKE_EPOCH)) +EPOCH_DIFF=$((NOW_EPOCH - FLAKE_EPOCH)) if [ $EPOCH_DIFF -gt $((60480 * 5)) ]; then echo - echo "${BOLD}WARNING: inputs haven't been updated in $(($EPOCH_DIFF / 86400)) days!${NORMAL}" + echo "${BOLD}WARNING: inputs haven't been updated in $((EPOCH_DIFF / 86400)) days!${NORMAL}" echo fi diff --git a/templates/mojo/thing.pl b/templates/mojo/thing.pl index e9a8ccf..b0fb01b 100644 --- a/templates/mojo/thing.pl +++ b/templates/mojo/thing.pl @@ -8,7 +8,7 @@ use 5.10.0; use Mojolicious::Lite -signatures; get '/' => sub ($c) { - $c->render(text => 'Hello Thing!'); + $c->render( text => 'Hello Thing!' ); }; app->start; From 784a85b15948528dd9885d4f1a0c341e8c7e68a6 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 28 Jun 2024 09:41:02 -0600 Subject: [PATCH 3/3] fmt: switch to treefmt --- bin/fmt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/bin/fmt b/bin/fmt index ef959d7..e071a77 100755 --- a/bin/fmt +++ b/bin/fmt @@ -2,12 +2,4 @@ set -e -find . -name \*.nix -exec nix fmt {} \+ -find . -name \*.sh -exec shfmt -w {} \+ - -deadnix -f . -shfmt -w bin/deploy -shfmt -w bin/mkboot -# TODO: https://github.com/nerdypepper/statix/issues/68 -#statix check --ignore lib/default.nix . -statix check . +treefmt