dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
commit 93f9f8dbc4e27d2d1b4f66169c3e45ff7bde9631 parent efbc46071c9945fed8dac259f1f1236cd01db1b7 Author: maydayv7 <maydayv7@gmail.com> Date: Wed, 20 Apr 2022 18:12:50 +0530 style: Use `treefmt` to Format Code
Diffstat:
| M | README.md | | | 6 | +++++- |
| M | configuration.nix | | | 2 | +- |
| M | files/git/hooks/pre-commit | | | 6 | ++++++ |
| M | modules/apps/git/default.nix | | | 1 | + |
| M | scripts/README.md | | | 1 | - |
| M | scripts/nixos.nix | | | 15 | +++------------ |
| M | shells/default.nix | | | 2 | +- |
| M | site/content/anime.md | | | 2 | +- |
| A | treefmt.toml | | | 23 | +++++++++++++++++++++++ |
9 files changed, 41 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md @@ -329,7 +329,7 @@ The system build cache is publicly hosted using [Cachix](https://www.cachix.org) #### Continuous Integration -This repository makes use of [`GitHub Actions`](./.github/workflows) in order to automatically check the configuration syntax on every commit (using [`nix-linter`](https://github.com/Synthetica9/nix-linter) and [`statix`](https://github.com/nerdypepper/statix)) and format it (using [`alejandra`](https://github.com/kamadorueda/alejandra) and [`prettier`](https://github.com/prettier/prettier)), update the `inputs` every week, build the configuration and upload the build cache to [Cachix](https://app.cachix.org/cache/maydayv7-dotfiles) as well as publish the Install Media `.iso` to a draft Release upon creation of a tag (You can also find `GitLab CI/CD` configuration in [`.gitlab`](./.gitlab/.gitlab-ci.yml)). A `git` [hook](./.git-hooks) is used to check the commit message to adhere to the [`Conventional Commits`](https://www.conventionalcommits.org) specification +This repository makes use of [`GitHub Actions`](./.github/workflows) in order to automatically check the configuration syntax on every commit (using [`nix-linter`](https://github.com/Synthetica9/nix-linter) and [`statix`](https://github.com/nerdypepper/statix)) and format it (using [`treefmt`](https://github.com/numtide/treefmt)), update the `inputs` every week, build the configuration and upload the build cache to [Cachix](https://app.cachix.org/cache/maydayv7-dotfiles) as well as publish the Install Media `.iso` to a draft Release upon creation of a tag (You can also find `GitLab CI/CD` configuration in [`.gitlab`](./.gitlab/.gitlab-ci.yml)). A `git` [hook](./.git-hooks) is used to check the commit message to adhere to the [`Conventional Commits`](https://www.conventionalcommits.org) specification ###### Variables @@ -410,6 +410,10 @@ You can navigate to the `README`'s present in the various directories to know mo <details> <summary><b>Changelog</b></summary> +### NEXT + +- Use [`treefmt`](https://github.com/numtide/treefmt) for Formatting Code + ### 22.04 (v10) - Deprecate `git-crypt` Usage diff --git a/configuration.nix b/configuration.nix @@ -48,7 +48,7 @@ in }; ## Code Formatter ## - formatter = pkgs.unstable.alejandra; + formatter = pkgs.treefmt; ## Package Configuration ## legacyPackages = self.channels."${system}".stable; diff --git a/files/git/hooks/pre-commit b/files/git/hooks/pre-commit @@ -2,6 +2,12 @@ error() { echo -e "\033[0;31merror:\033[0m $1"; exit 7; } ## Pre-Commit Checks ## +# Code Format +if [ -f "treefmt.toml" ] +then + treefmt +fi + # Nix Syntax if [ "$(find . -name '*.nix' 2>/dev/null | wc -l)" != 0 ] && [ "$(git branch --show-current)" == "stable" ] then diff --git a/modules/apps/git/default.nix b/modules/apps/git/default.nix @@ -22,6 +22,7 @@ in { git-lfs gh tig + treefmt ]; # Settings diff --git a/scripts/README.md b/scripts/README.md @@ -16,7 +16,6 @@ $ nixos check [ --trace | --fast ] - Checks System Configuration [ Displays Error to Trace ] clean [ --all ] - Garbage Collects and Optimises Nix Store explore - Opens Interactive Shell to explore Syntax and Configuration - format [ 'path' ] - Formats Configuration Syntax [ in 'path' ] install - Installs NixOS onto System iso 'variant' [ --burn ] - Builds Image for Specified Install Media or Device [ Burns '.iso' to USB ] list [ 'pattern' ] - Lists all Installed Packages [ Returns Matches ] diff --git a/scripts/nixos.nix b/scripts/nixos.nix @@ -29,7 +29,6 @@ with files; let check [ --trace | --fast ] - Checks System Configuration [ Displays Error to Trace ] clean [ --all ] - Garbage Collects and Optimises Nix Store explore - Opens Interactive Shell to explore Syntax and Configuration - format [ 'path' ] - Formats Configuration Syntax [ in 'path' ] install - Installs NixOS onto System iso 'variant' [ --burn ] - Builds Image for Specified Install Media or Device [ Burns '.iso' to USB ] list [ 'pattern' ] - Lists all Installed Packages [ Returns Matches ] @@ -165,8 +164,11 @@ in fi ;; check) + echo "Formatting Code..." + pushd ${path.system} > /dev/null; nix fmt; popd > /dev/null echo "Checking Syntax..." nix-linter -r ${path.system} || true + newline case $2 in "") nix flake check ${path.system} --keep-going;; "--trace") nix flake check ${path.system} --keep-going --show-trace;; @@ -198,17 +200,6 @@ in *) nix repl --arg path "$(readlink -f "$2" | sed 's|/flake.nix||')" ${repl};; esac ;; - format) - echo "Formatting Code..." - if [ -z "$2" ] - then - path=${path.system} - else - path="$2" - fi - alejandra "$path" - prettier --write --list-different --ignore-unknown "$path" - ;; install) internet if [ "$EUID" -ne 0 ] diff --git a/shells/default.nix b/shells/default.nix @@ -2,7 +2,7 @@ with pkgs; mkShell { name = "devShell"; - packages = [git gnupg jq sops] ++ [figlet neofetch]; + packages = [git gnupg jq sops treefmt] ++ [figlet neofetch]; shellHook = '' echo -e "\e[36m## Default Developer Shell ##" echo -e "\e[34m Version: $(nix --version)" diff --git a/site/content/anime.md b/site/content/anime.md @@ -54,7 +54,7 @@ comments = true - [ ] Gosick - [x] Hyouka - [ ] One Outs -- [ ] Kanojo mo Kanojo +- [x] Date a Live <sup>\*</sup> <sup>#</sup> - [ ] Steins;Gate <sup>#</sup> - [ ] Skilled Teaser Takagi-san <sup>#</sup> diff --git a/treefmt.toml b/treefmt.toml @@ -0,0 +1,23 @@ +[formatter.nix] +command = "alejandra" +includes = ["*.nix"] + +[formatter.prettier] +command = "prettier" +options = [ + "--write", + "--list-different", + "--ignore-unknown", +] +includes = [ + "*.css", + "*.html", + "*.js", + "*.json", + "*.jsx", + "*.md", + "*.mdx", + "*.scss", + "*.ts", + "*.yaml", +]