fork/helix

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

Gabor Pihajfix: add runtimeDir as propagated build input (#14247)b6ccbddc

master
2.5 KiB87 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    propagatedBuildInputs = [ runtimeDir ];
50    
51    nativeBuildInputs = [
52      installShellFiles
53      git
54    ];
55
56    buildType = "release";
57
58    name = with builtins; (fromTOML (readFile ./helix-term/Cargo.toml)).package.name;
59    src = fs.toSource {
60      root = ./.;
61      fileset = src;
62    };
63
64    # Helix attempts to reach out to the network and get the grammars. Nix doesn't allow this.
65    HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
66
67    # So Helix knows what rev it is.
68    HELIX_NIX_BUILD_REV = gitRev;
69
70    doCheck = false;
71    strictDeps = true;
72
73    # Sets the Helix runtime dir to the grammars
74    env.HELIX_DEFAULT_RUNTIME = "${runtimeDir}";
75
76    # Get all the application stuff in the output directory.
77    postInstall = ''
78      mkdir -p $out/lib
79      installShellCompletion ${./contrib/completion}/hx.{bash,fish,zsh}
80      mkdir -p $out/share/{applications,icons/hicolor/{256x256,scalable}/apps}
81      cp ${./contrib/Helix.desktop} $out/share/applications/Helix.desktop
82      cp ${./logo.svg} $out/share/icons/hicolor/scalable/apps/helix.svg
83      cp ${./contrib/helix.png} $out/share/icons/hicolor/256x256/apps/helix.png
84    '';
85
86    meta.mainProgram = "hx";
87  })