on 0b8a00a help sign in
helix/flake.nix
99 lines 3.1 kB history raw
1{
2 description = "A post-modern text editor.";
4 inputs = {
5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6 rust-overlay = {
7 url = "github:oxalica/rust-overlay";
8 inputs.nixpkgs.follows = "nixpkgs";
9 };
10 nixCargoIntegration = {
11 url = "github:yusdacra/nix-cargo-integration";
12 inputs.nixpkgs.follows = "nixpkgs";
13 inputs.rustOverlay.follows = "rust-overlay";
14 };
15 };
17 outputs = inputs @ {
18 nixpkgs,
19 nixCargoIntegration,
20 ...
21 }:
22 nixCargoIntegration.lib.makeOutputs {
23 root = ./.;
24 renameOutputs = {"helix-term" = "helix";};
25 # Set default app to hx (binary is from helix-term release build)
26 # Set default package to helix-term release build
27 defaultOutputs = {
28 app = "hx";
29 package = "helix";
30 };
31 overrides = {
32 cCompiler = common:
33 with common.pkgs;
34 if stdenv.isLinux
35 then gcc
36 else clang;
37 crateOverrides = common: _: {
38 helix-term = prev: let
39 inherit (common) pkgs;
40 mkRootPath = rel:
41 builtins.path {
42 path = "${common.root}/${rel}";
43 name = rel;
44 };
45 grammars = pkgs.callPackage ./grammars.nix {};
46 runtimeDir = pkgs.runCommandNoCC "helix-runtime" {} ''
47 mkdir -p $out
48 ln -s ${mkRootPath "runtime"}/* $out
49 rm -r $out/grammars
50 ln -s ${grammars} $out/grammars
51 '';
52 in {
53 # disable fetching and building of tree-sitter grammars in the helix-term build.rs
54 HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
55 # link languages and theme toml files since helix-term expects them (for tests)
56 preConfigure =
57 pkgs.lib.concatMapStringsSep
58 "\n"
59 (path: "ln -sf ${mkRootPath path} ..")
60 ["languages.toml" "theme.toml" "base16_theme.toml"];
61 buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
62 nativeBuildInputs = [pkgs.makeWrapper];
64 postFixup = ''
65 if [ -f "$out/bin/hx" ]; then
66 wrapProgram "$out/bin/hx" --set HELIX_RUNTIME "${runtimeDir}"
67 fi
68 '';
69 };
70 };
71 shell = common: prev: {
72 packages =
73 prev.packages
74 ++ (
75 with common.pkgs; [lld_13 lldb cargo-tarpaulin cargo-flamegraph rust-analyzer]
76 );
77 env =
78 prev.env
79 ++ [
80 {
81 name = "HELIX_RUNTIME";
82 eval = "$PWD/runtime";
83 }
84 {
85 name = "RUST_BACKTRACE";
86 value = "1";
87 }
88 {
89 name = "RUSTFLAGS";
90 value =
91 if common.pkgs.stdenv.isLinux
92 then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
93 else "";
94 }
95 ];
96 };
97 };
98 };