2023-09-21 04:48:43 +00:00
|
|
|
{
|
|
|
|
description = "jolheiser helix derivation";
|
|
|
|
inputs = {
|
2024-10-31 01:07:26 +00:00
|
|
|
jolheiser.url = "git+https://git.jolheiser.com/nixpkgs.git";
|
|
|
|
nixpkgs.follows = "jolheiser/nixpkgs";
|
2023-09-21 04:48:43 +00:00
|
|
|
};
|
2024-10-31 01:07:26 +00:00
|
|
|
outputs =
|
|
|
|
{
|
|
|
|
nixpkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
config = import ./config.nix { pkgs = pkgs; };
|
|
|
|
buildGrammar =
|
|
|
|
grammar:
|
|
|
|
let
|
|
|
|
source = pkgs.fetchgit {
|
|
|
|
inherit (grammar) url rev sha256;
|
|
|
|
};
|
|
|
|
linkQueries = pkgs.lib.optionalString (builtins.hasAttr "queries" grammar) "cp -r ${source}/${grammar.queries} $out/queries";
|
|
|
|
in
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
pname = "helix-tree-sitter-grammar-${grammar.name}";
|
|
|
|
version = grammar.rev;
|
|
|
|
buildInputs = [
|
|
|
|
pkgs.helix
|
|
|
|
pkgs.git
|
|
|
|
];
|
|
|
|
src = source;
|
|
|
|
dontInstall = true;
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
mkdir .helix
|
|
|
|
cat << EOF > .helix/languages.toml
|
|
|
|
use-grammars = { only = ["${grammar.name}"] }
|
|
|
|
[[grammar]]
|
|
|
|
name = "${grammar.name}"
|
|
|
|
source = { git = "${grammar.url}", rev = "${grammar.rev}" }
|
|
|
|
EOF
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
mkdir -p runtime/grammars/sources
|
|
|
|
cp -r ${source} runtime/grammars/sources/${grammar.name}
|
|
|
|
export CARGO_MANIFEST_DIR=$(pwd)/.helix
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
#hx -g fetch
|
|
|
|
hx -g build
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
mkdir $out
|
|
|
|
cp runtime/grammars/${grammar.name}.so $out/${grammar.name}.so
|
|
|
|
${linkQueries}
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
builtGrammars = builtins.map (grammar: {
|
2023-09-21 04:48:43 +00:00
|
|
|
inherit (grammar) name;
|
|
|
|
artifact = buildGrammar grammar;
|
2024-10-31 01:07:26 +00:00
|
|
|
}) config.grammars;
|
|
|
|
ignoreFile = pkgs.writeText "ignore" (builtins.concatStringsSep "\n" config.ignore);
|
|
|
|
configFile = pkgs.writeText "config.toml" (
|
|
|
|
builtins.readFile (tomlFormat.generate "helix-config" config.settings)
|
|
|
|
);
|
|
|
|
languageFile = pkgs.writeText "languages.toml" (
|
|
|
|
builtins.readFile (tomlFormat.generate "helix-languages" config.languages)
|
|
|
|
);
|
|
|
|
themeFiles = pkgs.lib.mapAttrsToList (name: value: {
|
|
|
|
inherit name;
|
|
|
|
file = pkgs.writeText "${name}.toml" (
|
|
|
|
builtins.readFile (tomlFormat.generate "helix-theme-${name}" value)
|
|
|
|
);
|
|
|
|
}) config.themes;
|
|
|
|
themeLinks = builtins.map (
|
|
|
|
theme: "ln -s ${theme.file} $out/home/helix/themes/${theme.name}.toml"
|
|
|
|
) themeFiles;
|
|
|
|
grammarLinks = builtins.map (
|
|
|
|
grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/lib/runtime/grammars/${grammar.name}.so"
|
|
|
|
) builtGrammars;
|
|
|
|
queryLinks = builtins.map (
|
|
|
|
grammar: "ln -s ${grammar.artifact}/queries $out/lib/runtime/queries/${grammar.name}"
|
|
|
|
) builtGrammars;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.x86_64-linux.default =
|
|
|
|
pkgs.runCommand "hx"
|
|
|
|
{
|
|
|
|
buildInputs = [ pkgs.makeWrapper ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
mkdir $out
|
|
|
|
ln -s ${pkgs.helix}/* $out
|
|
|
|
rm $out/bin
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
rm $out/lib
|
|
|
|
mkdir -p $out/lib/runtime
|
|
|
|
ln -s ${pkgs.helix}/lib/runtime/* $out/lib/runtime
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
rm $out/lib/runtime/grammars
|
|
|
|
mkdir $out/lib/runtime/grammars
|
|
|
|
ln -s ${pkgs.helix}/lib/runtime/grammars/* $out/lib/runtime/grammars
|
|
|
|
${builtins.concatStringsSep "\n" grammarLinks}
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
rm $out/lib/runtime/queries
|
|
|
|
mkdir $out/lib/runtime/queries
|
|
|
|
ln -s ${pkgs.helix}/lib/runtime/queries/* $out/lib/runtime/queries
|
|
|
|
${builtins.concatStringsSep "\n" queryLinks}
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
mkdir -p $out/home/helix/themes
|
|
|
|
ln -s ${configFile} $out/home/helix/config.toml
|
|
|
|
ln -s ${languageFile} $out/home/helix/languages.toml
|
|
|
|
${builtins.concatStringsSep "\n" themeLinks}
|
2023-09-21 04:48:43 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
mkdir -p $out/home/git
|
|
|
|
ln -s ${ignoreFile} $out/home/git/ignore
|
2023-09-21 05:07:28 +00:00
|
|
|
|
2024-10-31 01:07:26 +00:00
|
|
|
makeWrapper ${pkgs.helix}/bin/hx $out/bin/hx --set HELIX_RUNTIME $out/lib/runtime --set XDG_CONFIG_HOME $out/home
|
|
|
|
'';
|
|
|
|
};
|
2023-09-21 04:48:43 +00:00
|
|
|
}
|