From c23ac2891c78e89766e58a1c075d903db53baf6f Mon Sep 17 00:00:00 2001 From: DavHau Date: Sat, 15 Feb 2025 15:48:49 +0700 Subject: [PATCH] setup treefmt --- .envrc | 1 + .gitignore | 4 ++- flake.nix | 84 ++++++++++++---------------------------------------- treefmt.toml | 11 +++++++ 4 files changed, 34 insertions(+), 66 deletions(-) create mode 100644 .envrc create mode 100644 treefmt.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 31b0a4b..8e7f782 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ result +result-* +.direnv/ # Created by the NixOS interactive test driver -.nixos-test-history \ No newline at end of file +.nixos-test-history diff --git a/flake.nix b/flake.nix index 4a04cfc..237c58b 100644 --- a/flake.nix +++ b/flake.nix @@ -61,18 +61,17 @@ diskoVersion = version; }; - shellcheck = pkgs.runCommand "shellcheck" { nativeBuildInputs = [ pkgs.shellcheck ]; } '' - cd ${./.} - shellcheck disk-deactivate/disk-deactivate disko + jsonTypes = pkgs.writeTextFile { name = "jsonTypes"; text = (builtins.toJSON diskoLib.jsonTypes); }; + + treefmt = pkgs.runCommand "treefmt" { } '' + ${self.formatter.${system}}/bin/treefmt --ci --working-dir ${self} touch $out ''; - - jsonTypes = pkgs.writeTextFile { name = "jsonTypes"; text = (builtins.toJSON diskoLib.jsonTypes); }; in # FIXME: aarch64-linux seems to hang on boot lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 (nixosTests // { inherit disko-install; }) // pkgs.lib.optionalAttrs (!pkgs.stdenv.buildPlatform.isRiscV64 && !pkgs.stdenv.hostPlatform.isx86_32) { - inherit shellcheck jsonTypes; + inherit jsonTypes treefmt; inherit (self.packages.${system}) disko-doc; }); @@ -89,67 +88,22 @@ pkgs = nixpkgs.legacyPackages.${system}; in pkgs.writeShellApplication { - name = "format"; - runtimeInputs = with pkgs; [ - nixpkgs-fmt - deno - deadnix + name = "treefmt"; + text = ''treefmt "$@"''; + runtimeInputs = [ + pkgs.deadnix + pkgs.nixfmt-rfc-style + pkgs.shellcheck + pkgs.treefmt ]; - text = '' - showUsage() { - cat <