fork/helix

git clone https://git.julia.blue/fork/helix

Zhaith Izalielfix: fix support for grammar overlays and include predicate (#13603) (#13613)12523cd1

25.07
2.5 KiB85 linesraw
1{
2  lib,
3  rustPlatform,
4  callPackage,
5  runCommand,
6  installShellFiles,
7  git,
8  gitRev ? null,
9  grammarOverlays ? [],
10  includeGrammarIf ? _: true,
11}: let
12  fs = lib.fileset;
13
14  src = fs.difference (fs.gitTracked ./.) (fs.unions [
15    ./.envrc
16    ./rustfmt.toml
17    ./screenshot.png
18    ./book
19    ./docs
20    ./runtime
21    ./flake.lock
22    (fs.fileFilter (file: lib.strings.hasInfix ".git" file.name) ./.)
23    (fs.fileFilter (file: file.hasExt "svg") ./.)
24    (fs.fileFilter (file: file.hasExt "md") ./.)
25    (fs.fileFilter (file: file.hasExt "nix") ./.)
26  ]);
27
28  # Next we actually need to build the grammars and the runtime directory
29  # that they reside in. It is built by calling the derivation in the
30  # grammars.nix file, then taking the runtime directory in the git repo
31  # and hooking symlinks up to it.
32  grammars = callPackage ./grammars.nix {inherit grammarOverlays includeGrammarIf;};
33  runtimeDir = runCommand "helix-runtime" {} ''
34    mkdir -p $out
35    ln -s ${./runtime}/* $out
36    rm -r $out/grammars
37    ln -s ${grammars} $out/grammars
38  '';
39in
40  rustPlatform.buildRustPackage (self: {
41    cargoLock = {
42      lockFile = ./Cargo.lock;
43      # This is not allowed in nixpkgs but is very convenient here: it allows us to
44      # avoid specifying `outputHashes` here for any git dependencies we might take
45      # on temporarily.
46      allowBuiltinFetchGit = true;
47    };
48
49    nativeBuildInputs = [
50      installShellFiles
51      git
52    ];
53
54    buildType = "release";
55
56    name = with builtins; (fromTOML (readFile ./helix-term/Cargo.toml)).package.name;
57    src = fs.toSource {
58      root = ./.;
59      fileset = src;
60    };
61
62    # Helix attempts to reach out to the network and get the grammars. Nix doesn't allow this.
63    HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
64
65    # So Helix knows what rev it is.
66    HELIX_NIX_BUILD_REV = gitRev;
67
68    doCheck = false;
69    strictDeps = true;
70
71    # Sets the Helix runtime dir to the grammars
72    env.HELIX_DEFAULT_RUNTIME = "${runtimeDir}";
73
74    # Get all the application stuff in the output directory.
75    postInstall = ''
76      mkdir -p $out/lib
77      installShellCompletion ${./contrib/completion}/hx.{bash,fish,zsh}
78      mkdir -p $out/share/{applications,icons/hicolor/{256x256,scalable}/apps}
79      cp ${./contrib/Helix.desktop} $out/share/applications/Helix.desktop
80      cp ${./logo.svg} $out/share/icons/hicolor/scalable/apps/helix.svg
81      cp ${./contrib/helix.png} $out/share/icons/hicolor/256x256/apps/helix.png
82    '';
83
84    meta.mainProgram = "hx";
85  })