dotfiles

My PC Dotfiles & Website
commit 4cb02825643f8f8b11a28acf2ea4c751d0926ca5
parent f63620c0e9316e3c4fa8dd555ca926e612588d49
Author: maydayv7 <maydayv7@gmail.com>
Date:   Sun, 19 Nov 2023 22:27:22 +0530

feat: Improve Syntax Formatting with `treefmt-nix`

Also drop `pre-commit-hooks` and `gitignore.nix`

Diffstat:

D.prettierignore | 10----------
D.prettierrc | 1-
MREADME.md | 11+++++------
Mfiles/git/hooks/pre-commit | 8+-------
Mflake.lock | 110++++++++++++++++++-------------------------------------------------------------
Mflake.nix | 44+++++++-------------------------------------
Dmodules/nix/checks.nix | 5-----
Mmodules/nix/default.nix | 9+++++++--
Amodules/nix/format.nix | 40++++++++++++++++++++++++++++++++++++++++
Dmodules/nix/tools.nix | 7-------
Dpackages/overlays/miscellaneous.nix | 4----
Mscripts/nixos.nix | 37++++++++++++++++++-------------------
Mshells/flake.nix | 15++++++++-------
Dshells/format.nix | 5-----
Dtreefmt.toml | 23-----------------------
15 files changed, 110 insertions(+), 219 deletions(-)

diff --git a/.prettierignore b/.prettierignore @@ -1,10 +0,0 @@ -result - -# Formatting Errors -flake.lock -site/templates/macros/edit.html -site/templates/macros/head.html -site/templates/macros/javascript.html -site/templates/macros/menu.html -site/templates/macros/posts.html -site/templates/tags/list.html diff --git a/.prettierrc b/.prettierrc @@ -1 +0,0 @@ -bracketSameLine: true diff --git a/README.md b/README.md @@ -36,8 +36,8 @@ This [repository](https://github.com/maydayv7/dotfiles) contains the configurati - Auto-Magic using [`flake-utils-plus`](https://github.com/gytis-ivaskevicius/flake-utils-plus) helper functions - Automatic `packages` Updates using [`update.sh`](./packages/update.sh) - Install Media and Device Images using [`nixos-generators`](https://github.com/nix-community/nixos-generators) image generation modules -- Configuration [Checks](./modules/nix/checks.nix) using [`pre-commit-hooks.nix`](https://github.com/cachix/pre-commit-hooks.nix) -- Support for `source` filters with [`nix-filter`](https://github.com/numtide/nix-filter) and [`gitignore.nix`](https://github.com/hercules-ci/gitignore.nix) +- Syntax [Formatting](./modules/nix/format.nix) using [`treefmt`](https://github.com/numtide/treefmt) and [`treefmt-nix`](https://github.com/numtide/treefmt-nix) +- Support for `source` filters with [`nix-filter`](https://github.com/numtide/nix-filter) - Support for Base16 color theming using [`stylix`](https://github.com/danth/stylix) - Support for declaratively installing [Flatpak](./modules/apps/flatpak.nix) applications using [`nix-flatpak`](https://github.com/gmodena/nix-flatpak) - Wrapped `wine` [Applications](./packages/wine) using Emmanuel's [Wrapper](https://github.com/emmanuelrosa/erosanix/tree/0dabea58d483e13d2de141517cb4ff1cb230b2aa/pkgs/mkwindowsapp) @@ -73,8 +73,7 @@ github:maydayv7/dotfiles │ └───x86_64-linux │ ├───Device-gnome: derivation 'nixos-rebuild' │ ├───Device-xfce: derivation 'nixos-rebuild' -│ ├───commit: derivation 'pre-commit-run' -│ └───schema: derivation 'jsonschema-deploy-system' +│ └───treefmt: derivation 'treefmt-check' ├───devShells │ └───x86_64-linux │ ├───cc: development environment 'C' @@ -110,7 +109,6 @@ github:maydayv7/dotfiles │ ├───shell: NixOS module │ └───user: NixOS module ├───overlays -│ └───miscellaneous: Nixpkgs overlay ├───packages │ └───x86_64-linux │ ├───dotfiles: package 'Dotfiles-v15.0' @@ -416,9 +414,10 @@ You can navigate to the `README`s present in the various directories to know mor ### v15 - Use the [`flake-parts`](https://flake.parts/) Flakes framework +- Improve Syntax Formatting with `treefmt-nix` and drop `pre-commit-hooks` - Fix Emoji Support -- Miscellaneous Updates - Support declarative [Flatpak](https://flatpak.org/) application install +- Miscellaneous Updates ### v13 diff --git a/files/git/hooks/pre-commit b/files/git/hooks/pre-commit @@ -2,14 +2,8 @@ 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" ] +if [ "$(find . -name '*.nix' 2>/dev/null | wc -l)" != 0 ] then nix flake check || error "Invalid Syntax" fi diff --git a/flake.lock b/flake.lock @@ -177,22 +177,6 @@ "type": "github" } }, - "flake-compat_3": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems_3" @@ -226,6 +210,26 @@ "type": "github" } }, + "formatter": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1699786194, + "narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "e82f32aa7f06bbbd56d7b12186d555223dc399d1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, "framework": { "inputs": { "nixpkgs-lib": [ @@ -337,55 +341,6 @@ "type": "github" } }, - "hooks": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": [ - "utils", - "flake-utils" - ], - "gitignore": [ - "ignore" - ], - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1699271226, - "narHash": "sha256-8Jt1KW3xTjolD6c6OjJm9USx/jmL+VVmbooADCkdDfU=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "ea758da1a6dcde6dc36db348ed690d09b9864128", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "ignore": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1694102001, - "narHash": "sha256-vky6VPK1n1od6vXbqzOXnekrQpTL4hbPAwUhT5J9c9E=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "9e21c80adf67ebcb077d75bd5e7d724d21eeafd6", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, "impermanence": { "locked": { "lastModified": 1697303681, @@ -454,22 +409,6 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1685801374, - "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable_2": { - "locked": { "lastModified": 1699756042, "narHash": "sha256-bHHjQQBsEPOxLL+klYU2lYshDnnWY12SewzQ7n5ab2M=", "owner": "NixOS", @@ -585,13 +524,12 @@ "inputs": { "filters": "filters", "flatpak": "flatpak", + "formatter": "formatter", "framework": "framework", "gaming": "gaming", "generators": "generators", "hardware": "hardware", "home": "home", - "hooks": "hooks", - "ignore": "ignore", "impermanence": "impermanence", "index": "index", "nixpkgs": "nixpkgs_3", @@ -608,7 +546,7 @@ "sops": { "inputs": { "nixpkgs": "nixpkgs_5", - "nixpkgs-stable": "nixpkgs-stable_2" + "nixpkgs-stable": "nixpkgs-stable" }, "locked": { "lastModified": 1699770333, @@ -634,7 +572,7 @@ "base16-kitty": "base16-kitty", "base16-tmux": "base16-tmux", "base16-vim": "base16-vim", - "flake-compat": "flake-compat_2", + "flake-compat": "flake-compat", "home-manager": [ "home" ], @@ -757,7 +695,7 @@ }, "wine": { "inputs": { - "flake-compat": "flake-compat_3", + "flake-compat": "flake-compat_2", "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix @@ -74,19 +74,11 @@ # Source Filter Functions filters.url = "github:numtide/nix-filter"; - ignore = { - url = "github:hercules-ci/gitignore.nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - # Pre-Commit Hooks - hooks = { - url = "github:cachix/pre-commit-hooks.nix"; - inputs = { - nixpkgs.follows = "nixpkgs"; - flake-utils.follows = "utils/flake-utils"; - gitignore.follows = "ignore"; - }; + # Syntax Formatter + formatter = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; }; ## Feature Modules @@ -148,7 +140,9 @@ debug = false; _module.args = {util = self.lib;}; - imports = (import ./lib/map.nix {inherit lib;}).flake ./.; + imports = + (import ./lib/map.nix {inherit lib;}).flake ./. + ++ [modules/nix/format.nix]; flake = { # Supported Architectures @@ -159,30 +153,6 @@ inherit lib inputs; }; }; - - perSystem = { - system, - pkgs, - ... - }: { - # Code Formatter - formatter = pkgs.treefmt; - - # Pre-Commit Hooks - checks = with inputs; { - commit = hooks.lib."${system}".run { - src = ignore.lib.gitignoreSource ./.; - settings.statix.ignore = ["_*"]; - hooks = { - alejandra.enable = true; - prettier.enable = true; - shellcheck.enable = false; - statix.enable = true; - stylua.enable = true; - }; - }; - }; - }; }; ## Nix Configuration ## diff --git a/modules/nix/checks.nix b/modules/nix/checks.nix @@ -1,5 +0,0 @@ -{inputs, ...}: { - ## Configuration Checks ## - perSystem = {system, ...}: { - }; -} diff --git a/modules/nix/default.nix b/modules/nix/default.nix @@ -1,7 +1,6 @@ { config, lib, - util, inputs, pkgs, ... @@ -19,7 +18,13 @@ in { user.persist.directories = [".cache/nix"] ++ optionals tools [".cache/manix"]; environment.systemPackages = [pkgs.cachix] - ++ optionals tools (util.map.array (import ./tools.nix) pkgs); + ++ optionals tools (with pkgs; [ + alejandra + manix + nodePackages.prettier + shellcheck + statix + ]); # Settings nix = { diff --git a/modules/nix/format.nix b/modules/nix/format.nix @@ -0,0 +1,40 @@ +{inputs, ...}: { + ## Code Formatter ## + imports = [inputs.formatter.flakeModule]; + + perSystem = {pkgs, ...}: { + treefmt.config = rec { + package = pkgs.treefmt; + + projectRoot = ../../.; + projectRootFile = "${projectRoot}/flake.nix"; + settings.global.excludes = [ + "_*" + "result/**" + "flake.lock" + ]; + + # Formatters + programs = { + alejandra.enable = true; + statix.enable = true; + shellcheck.enable = false; + stylua.enable = true; + prettier = { + enable = true; + settings.bracketSameLine = true; + + # Formatting Errors + excludes = [ + "site/templates/macros/edit.html" + "site/templates/macros/head.html" + "site/templates/macros/javascript.html" + "site/templates/macros/menu.html" + "site/templates/macros/posts.html" + "site/templates/tags/list.html" + ]; + }; + }; + }; + }; +} diff --git a/modules/nix/tools.nix b/modules/nix/tools.nix @@ -1,7 +0,0 @@ -[ - "alejandra" - "manix" - "prettier" - "shellcheck" - "statix" -] diff --git a/packages/overlays/miscellaneous.nix b/packages/overlays/miscellaneous.nix @@ -1,4 +0,0 @@ -final: prev: { - ## Miscellaneous Overlays ## - inherit (final.nodePackages) prettier; -} diff --git a/scripts/nixos.nix b/scripts/nixos.nix @@ -9,7 +9,7 @@ }: with files; let inherit (inputs) self; - inherit (util.map) array list; + inherit (util.map) list; inherit (lib) licenses recursiveUpdate; devShells = list self.devShells."${system}"; @@ -77,24 +77,23 @@ in }; } (pkgs.writeShellApplication { name = "nixos"; - runtimeInputs = with pkgs; - [ - cachix - coreutils - generators - git - gnupg - gnused - gparted - jq - nixFlakes - parted - sops - tree - wine.mkwindowsapp-tools - zfs - ] - ++ array (import ../modules/nix/tools.nix) pkgs; + runtimeInputs = with pkgs; [ + cachix + coreutils + generators + git + gnupg + gnused + gparted + jq + manix + nixFlakes + parted + sops + tree + wine.mkwindowsapp-tools + zfs + ]; text = '' set +eu diff --git a/shells/flake.nix b/shells/flake.nix @@ -1,19 +1,20 @@ -{util, ...}: let - inherit (util) map; -in { +{ + config, + util, + ... +}: { ## Developer Shells ## perSystem = { - self', + system, pkgs, ... }: { devShells = - map.modules' ./. (file: pkgs.mkShell (import file pkgs)) + util.map.modules' ./. (file: pkgs.mkShell (import file pkgs)) // { default = import ./. {inherit pkgs;}; website = import ../site/shell.nix {inherit pkgs;}; - commit = - pkgs.mkShell {inherit (self'.checks.commit) shellHook;}; + format = config.allSystems."${system}".treefmt.build.devShell; }; }; } diff --git a/shells/format.nix b/shells/format.nix @@ -1,5 +0,0 @@ -pkgs: { - name = "Formatter"; - shellHook = ''echo "## Formatting Shell ##"''; - packages = (import ../lib/map.nix {inherit (pkgs) lib;}).array (import ../modules/nix/tools.nix) pkgs; -} diff --git a/treefmt.toml b/treefmt.toml @@ -1,23 +0,0 @@ -[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", -]