From 1d56c54f90600e33be8f1d146ace9922f8095eec Mon Sep 17 00:00:00 2001 From: karitham Date: Sat, 3 Oct 2026 11:28:49 +0200 Subject: [PATCH] nix: optimize eval time --- flake-parts.nix | 25 +++++--- modules/dev/editor/helix.nix | 111 ++++++++++++++++++----------------- 2 files changed, 72 insertions(+), 64 deletions(-) diff --git a/flake-parts.nix b/flake-parts.nix index b6ff421..26bfdb6 100644 --- a/flake-parts.nix +++ b/flake-parts.nix @@ -53,20 +53,27 @@ hosts = import ./systems/hosts.nix; homeHosts = lib.filterAttrs (_: h: h.class == "desktop" || h.class == "wsl") hosts; + # One nixpkgs instantiation per arch, shared by every standalone home + # config, instead of re-importing (and re-evaluating) it per host. + # Matches the NixOS `nixpkgs.config` (modules/nix.nix) so unfree packages + # resolve the same way under `useGlobalPkgs`. + pkgsByArch = lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] ( + system: + import inputs.nixpkgs { + inherit system; + config = { + allowUnfree = true; + input-fonts.acceptLicense = true; + }; + } + ); + mkHome = name: host: withSystem "${host.arch}-linux" ( { self', inputs', ... }: let - # Match the NixOS `nixpkgs.config` (modules/nix.nix) so unfree - # packages resolve the same way under `useGlobalPkgs`. - pkgs = import inputs.nixpkgs { - system = "${host.arch}-linux"; - config = { - allowUnfree = true; - input-fonts.acceptLicense = true; - }; - }; + pkgs = pkgsByArch."${host.arch}-linux"; in inputs.home-manager.lib.homeManagerConfiguration { inherit pkgs; diff --git a/modules/dev/editor/helix.nix b/modules/dev/editor/helix.nix index 686f21a..a037c2a 100644 --- a/modules/dev/editor/helix.nix +++ b/modules/dev/editor/helix.nix @@ -22,24 +22,6 @@ let pkgs.nufmt self'.packages.gotools ]; - - tree-sitter-prr = pkgs.stdenv.mkDerivation { - pname = "tree-sitter-prr"; - version = "unstable-2026-04-02"; - src = pkgs.fetchFromGitHub { - owner = "colinmarc"; - repo = "tree-sitter-prr"; - rev = "a0c26e79b038940e5e7030209985bfc103ebd8ef"; - hash = "sha256-iZg/TFAHph49ojTkNCCORIr2B/fAjPOL99FLpmdJBYo="; - }; - buildPhase = '' - $CC -fPIC -Isrc -c src/parser.c -o parser.o - $CC -shared -o prr.so parser.o - ''; - installPhase = '' - install -Dm755 prr.so $out/lib/prr.so - ''; - }; in lib.mkIf config.dev.enable { home.packages = global-tools; @@ -48,43 +30,68 @@ lib.mkIf config.dev.enable { (require "plugins.scm") ''; - xdg.configFile."helix/runtime/grammars/prr.so".source = "${tree-sitter-prr}/lib/prr.so"; - xdg.configFile."helix/runtime/queries/prr/highlights.scm".text = '' - (file_header) @namespace - (index_line) @comment - (old_file) @comment - (new_file) @comment - (hunk_header) @function - (addition) @diff.plus - (deletion) @diff.minus - (tag_name) @keyword - (tag_value) @string - (comment) @comment - ''; - programs.helix = { enable = true; defaultEditor = true; package = (inputs'.helix.packages.helix.override { - # The pinned rev for tree-sitter-rpmspec in helix's languages.toml no - # longer resolves on the upstream repo, and the latest revs moved - # parser.c into a rpmspec/ subdir that the helix grammar build - # doesn't understand. Pin to the last rev with the original layout. - grammarOverlays = [ - (final: prev: { - rpmspec = prev.rpmspec.overrideAttrs (_: { - src = fetchTree { - type = "git"; - url = "https://gitlab.com/cryptomilk/tree-sitter-rpmspec"; - rev = "7510373ef3384af3d083cdbed93c930bd8b77541"; - ref = "HEAD"; - shallow = true; - }; - }); - }) - ]; + # The fork otherwise evaluates and git-fetches all ~295 tree-sitter + # grammars on every eval (~24% of a full-system eval). Keep only the + # languages actually used; add here if a file stops highlighting. + includeGrammarIf = + grammar: + builtins.elem grammar.name [ + "bash" + "c" + "cmake" + "comment" + "cpp" + "css" + "diff" + "dockerfile" + "elixir" + "fish" + "git-attributes" + "git-commit" + "git-config" + "git-ignore" + "git-rebase" + "gleam" + "go" + "gomod" + "gotmpl" + "gowork" + "graphql" + "helm" + "html" + "ini" + "javascript" + "json" + "json5" + "jsonc" + "lua" + "make" + "markdown" + "nickel" + "nix" + "nu" + "proto" + "protobuf" + "python" + "regex" + "ruby" + "rust" + "scheme" + "sql" + "textproto" + "thrift" + "toml" + "tsx" + "typst" + "typescript" + "yaml" + ]; }).overrideAttrs { pname = "helix-steel"; @@ -553,12 +560,6 @@ lib.mkIf config.dev.enable { name = "thrift"; language-servers = [ "thrift-ls" ]; } - { - name = "prr"; - scope = "source.prr"; - file-types = [ "prr" ]; - grammar = "prr"; - } ] ++ map (name: { inherit name; }) [ "git-attributes" -- 2.51.2