refactor: improve handling of Fmt command
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 45s

This commit is contained in:
Price Hiller 2024-03-16 15:21:25 -05:00
parent 78b3796e68
commit 07cf91ca0b
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
8 changed files with 193 additions and 46 deletions

View File

@ -10,5 +10,8 @@ jobs:
- name: Check out code - name: Check out code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install `Fmt` package
run: nix --experimental-features "flakes nix-command" build 'path:./pkgs/Fmt' --out-link fmt-result
- name: Check formatting - name: Check formatting
run: ./scripts/check-fmt-git-files.bash run: PATH="${PATH}:${PWD}/fmt-result/bin" ./scripts/check-fmt-git-files.bash

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
./.luarc.json ./.luarc.json
result/ result
.luarc.json .luarc.json
.direnv .direnv
.nixd.json .nixd.json

View File

@ -1,10 +1,28 @@
{ {
"nodes": { "nodes": {
"Fmt": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1,
"narHash": "sha256-8lIyAZd5WpfmwLW/peBk3eRX3SGUmIeczv+y73pTFwY=",
"path": "./pkgs/Fmt",
"type": "path"
},
"original": {
"path": "./pkgs/Fmt",
"type": "path"
}
},
"agenix": { "agenix": {
"inputs": { "inputs": {
"agenix": "agenix_2", "agenix": "agenix_2",
"crane": "crane", "crane": "crane",
"flake-utils": "flake-utils", "flake-utils": "flake-utils_2",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
@ -32,7 +50,7 @@
"agenix", "agenix",
"nixpkgs" "nixpkgs"
], ],
"systems": "systems" "systems": "systems_2"
}, },
"locked": { "locked": {
"lastModified": 1707830867, "lastModified": 1707830867,
@ -51,7 +69,7 @@
"bob": { "bob": {
"inputs": { "inputs": {
"bob": "bob_2", "bob": "bob_2",
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils_3",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
@ -129,16 +147,16 @@
}, },
"emacs-overlay": { "emacs-overlay": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_3", "flake-utils": "flake-utils_4",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1710553346, "lastModified": 1710608587,
"narHash": "sha256-YHDgW5dnt55Z9DhXOKHhyDL6m6BbsRMyAucRxmNOMvo=", "narHash": "sha256-7to4df2dUDd2LhPSp/XeH9rpONb2MtYDn1uFeVMolVc=",
"owner": "nix-community", "owner": "nix-community",
"repo": "emacs-overlay", "repo": "emacs-overlay",
"rev": "4d36a8316894dbfc9af4364a1d869b9212f778eb", "rev": "895a56e7294c2e5be4f84aa8e1cbc9e53e91307e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -223,14 +241,14 @@
}, },
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems_2" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1705309234, "lastModified": 1710146030,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -262,11 +280,11 @@
"systems": "systems_4" "systems": "systems_4"
}, },
"locked": { "locked": {
"lastModified": 1710146030, "lastModified": 1705309234,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -297,6 +315,24 @@
"inputs": { "inputs": {
"systems": "systems_6" "systems": "systems_6"
}, },
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_6": {
"inputs": {
"systems": "systems_7"
},
"locked": { "locked": {
"lastModified": 1705309234, "lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
@ -311,9 +347,9 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_6": { "flake-utils_7": {
"inputs": { "inputs": {
"systems": "systems_7" "systems": "systems_8"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1701680307,
@ -329,7 +365,7 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_7": { "flake-utils_8": {
"locked": { "locked": {
"lastModified": 1659877975, "lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
@ -344,9 +380,9 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_8": { "flake-utils_9": {
"inputs": { "inputs": {
"systems": "systems_8" "systems": "systems_9"
}, },
"locked": { "locked": {
"lastModified": 1705309234, "lastModified": 1705309234,
@ -462,7 +498,7 @@
}, },
"kanagawa-gtk": { "kanagawa-gtk": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_5", "flake-utils": "flake-utils_6",
"kanagawa-gtk": "kanagawa-gtk_2", "kanagawa-gtk": "kanagawa-gtk_2",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
@ -514,7 +550,7 @@
}, },
"neovim-flake": { "neovim-flake": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_6", "flake-utils": "flake-utils_7",
"nixpkgs": [ "nixpkgs": [
"neovim-nightly-overlay", "neovim-nightly-overlay",
"nixpkgs" "nixpkgs"
@ -560,7 +596,7 @@
}, },
"nixgl": { "nixgl": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_7", "flake-utils": "flake-utils_8",
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
@ -642,11 +678,11 @@
}, },
"nixpkgs_4": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1710503106, "lastModified": 1710534455,
"narHash": "sha256-WQenjcuNH9cnEYqh/PFxpmjK9PQnEPGt1Z7TCfYBhXs=", "narHash": "sha256-huQT4Xs0y4EeFKn2BTBVYgEwJSv8SDlm82uWgMnCMmI=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b1d47989352fcb722a1f19295a9461ed1ef8435a", "rev": "9af9c1c87ed3e3ed271934cb896e0cdd33dae212",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -658,10 +694,11 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"Fmt": "Fmt",
"agenix": "agenix", "agenix": "agenix",
"bob": "bob", "bob": "bob",
"emacs-overlay": "emacs-overlay", "emacs-overlay": "emacs-overlay",
"flake-utils": "flake-utils_4", "flake-utils": "flake-utils_5",
"home-manager": "home-manager_2", "home-manager": "home-manager_2",
"kanagawa-gtk": "kanagawa-gtk", "kanagawa-gtk": "kanagawa-gtk",
"neovim-nightly-overlay": "neovim-nightly-overlay", "neovim-nightly-overlay": "neovim-nightly-overlay",
@ -841,6 +878,21 @@
"type": "github" "type": "github"
} }
}, },
"systems_9": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"waybar": { "waybar": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat_2",
@ -849,11 +901,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1710520627, "lastModified": 1710593646,
"narHash": "sha256-ryb5Wbx/2C58K+PkyoroV2JKeSrvXoBsIlPCZGD89IA=", "narHash": "sha256-0JhJM8dPPLLhVDNsE4d2U0Pjj/TT9X1f0FjjCmcednA=",
"owner": "Alexays", "owner": "Alexays",
"repo": "Waybar", "repo": "Waybar",
"rev": "8174dce77657300531fef8e350753b90dc8f65eb", "rev": "376b4d1c09c25d7e3d75f5d2be288367de4f91c3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -864,7 +916,7 @@
}, },
"wezterm": { "wezterm": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_8", "flake-utils": "flake-utils_9",
"freetype2": "freetype2", "freetype2": "freetype2",
"harfbuzz": "harfbuzz", "harfbuzz": "harfbuzz",
"libpng": "libpng", "libpng": "libpng",
@ -876,11 +928,11 @@
}, },
"locked": { "locked": {
"dir": "nix", "dir": "nix",
"lastModified": 1708994725, "lastModified": 1710600158,
"narHash": "sha256-t/owVTFmpudRe0kFngQMiVCXmN9DjvqECeoe/sg5zxU=", "narHash": "sha256-XjNzpcgqKuz6It6wBPJYtbieFglN4KqEKB306Qvpue0=",
"owner": "wez", "owner": "wez",
"repo": "wezterm", "repo": "wezterm",
"rev": "22424c3280cb21af43317cb58ef7bc34a8cbcc91", "rev": "889f8a9cd71a2b3552f28f6d1864aa3cd9461fdf",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -12,6 +12,10 @@
url = "path:./pkgs/bob-nvim"; url = "path:./pkgs/bob-nvim";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
Fmt = {
url = "path:./pkgs/Fmt";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = { home-manager = {
url = "github:nix-community/home-manager"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -41,7 +45,7 @@
defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux; defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux;
targets.genericLinux = { enable = true; }; targets.genericLinux = { enable = true; };
homeConfigurations.${username} = homeConfigurations.${username} =
home-manager.lib.homeManagerConfiguration rec { home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
extraSpecialArgs = { extraSpecialArgs = {
inherit inputs; inherit inputs;
@ -54,10 +58,10 @@
inputs.neovim-nightly-overlay.overlay inputs.neovim-nightly-overlay.overlay
inputs.emacs-overlay.overlays.emacs inputs.emacs-overlay.overlays.emacs
inputs.bob.overlays.default inputs.bob.overlays.default
inputs.Fmt.overlays.default
inputs.kanagawa-gtk.overlays.default inputs.kanagawa-gtk.overlays.default
inputs.nixgl.overlay inputs.nixgl.overlay
(final: prev: { (final: prev: {
Fmt = pkgs.writeScriptBin "Fmt" (builtins.readFile ./scripts/fmt.bash);
waybar = inputs.waybar.packages.${system}.default; waybar = inputs.waybar.packages.${system}.default;
lxappearance = prev.lxappearance.overrideAttrs (oldAttrs: { lxappearance = prev.lxappearance.overrideAttrs (oldAttrs: {
postInstall = '' postInstall = ''
@ -96,7 +100,6 @@
]; ];
shellHook = '' shellHook = ''
export RULES="$PWD/secrets/secrets.nix" export RULES="$PWD/secrets/secrets.nix"
nix eval --json --file ./.nixd.nix > .nixd.json
''; '';
}; };
}); });

61
pkgs/Fmt/flake.lock Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1710534455,
"narHash": "sha256-huQT4Xs0y4EeFKn2BTBVYgEwJSv8SDlm82uWgMnCMmI=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "9af9c1c87ed3e3ed271934cb896e0cdd33dae212",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"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
}

25
pkgs/Fmt/flake.nix Normal file
View File

@ -0,0 +1,25 @@
{
description = "Flake for custom formatting script";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
# This builds the blog binary then runs it and collects the output. Once done it throws away the binary and
# shoves the newly created static site into the result.
packages.default =
pkgs.writeScriptBin "Fmt" (builtins.readFile ./fmt.bash);
# Rust dev environment
devShells.default = pkgs.mkShell;
}) // {
overlays.default = final: prev: {
Fmt = self.packages.${final.system}.default;
};
};
}

View File

@ -88,6 +88,7 @@ usage() {
Example: Example:
${base} --fmt -- "file-to-format" ${base} --fmt -- "file-to-format"
-F | --fail-fast -F | --fail-fast
Fails on the first format error instead of gathering all errors. Fails on the first format error instead of gathering all errors.

2
scripts/check-fmt-git-pre-commit.bash Normal file → Executable file
View File

@ -16,7 +16,9 @@ main() {
fi fi
done < <(git diff --name-only --staged --diff-filter=d) done < <(git diff --name-only --staged --diff-filter=d)
if ((${#files[@]} > 0)); then
Fmt -- "${files[@]}" Fmt -- "${files[@]}"
fi
} }
main "${@}" main "${@}"