on aa00a47 help sign in
helix/flake.nix
180 lines 5.3 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 nci = {
11 url = "github:yusdacra/nix-cargo-integration";
12 inputs.nixpkgs.follows = "nixpkgs";
13 inputs.rust-overlay.follows = "rust-overlay";
14 };
15 };
17 outputs = {
18 self,
19 nixpkgs,
20 nci,
21 ...
22 }: let
23 lib = nixpkgs.lib;
24 mkRootPath = rel:
25 builtins.path {
26 path = "${toString ./.}/${rel}";
27 name = rel;
28 };
29 outputs = nci.lib.makeOutputs {
30 root = ./.;
31 renameOutputs = {"helix-term" = "helix";};
32 # Set default app to hx (binary is from helix-term release build)
33 # Set default package to helix-term release build
34 defaultOutputs = {
35 app = "hx";
36 package = "helix";
37 };
38 overrides = {
39 cCompiler = common:
40 with common.pkgs;
41 if stdenv.isLinux
42 then gcc
43 else clang;
44 crateOverrides = common: _: {
45 helix-term = prev: {
46 src = builtins.path {
47 name = "helix-source";
48 path = toString ./.;
49 # filter out unneeded stuff that cause rebuilds
50 filter = path: type:
51 lib.all
52 (n: builtins.baseNameOf path != n)
53 [
54 ".envrc"
55 ".ignore"
56 ".github"
57 "runtime"
58 "screenshot.png"
59 "book"
60 "contrib"
61 "docs"
62 "README.md"
63 "shell.nix"
64 "default.nix"
65 "grammars.nix"
66 "flake.nix"
67 "flake.lock"
68 ];
69 };
71 # disable fetching and building of tree-sitter grammars in the helix-term build.rs
72 HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
74 buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
76 # link languages and theme toml files since helix-term expects them (for tests)
77 preConfigure = ''
78 ${prev.preConfigure or ""}
79 ${
80 lib.concatMapStringsSep
81 "\n"
82 (path: "ln -sf ${mkRootPath path} ..")
83 ["languages.toml" "theme.toml" "base16_theme.toml"]
84 }
85 '';
87 meta.mainProgram = "hx";
88 };
89 };
90 shell = common: prev: {
91 packages =
92 prev.packages
93 ++ (
94 with common.pkgs;
95 [lld_13 cargo-flamegraph rust-analyzer]
96 ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
97 ++ (lib.optional stdenv.isLinux lldb)
98 );
99 env =
100 prev.env
101 ++ [
102 {
103 name = "HELIX_RUNTIME";
104 eval = "$PWD/runtime";
105 }
106 {
107 name = "RUST_BACKTRACE";
108 value = "1";
109 }
110 {
111 name = "RUSTFLAGS";
112 value =
113 if common.pkgs.stdenv.isLinux
114 then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
115 else "";
116 }
117 ];
118 };
119 };
120 };
121 makeOverridableHelix = system: old: config: let
122 pkgs = nixpkgs.legacyPackages.${system};
123 grammars = pkgs.callPackage ./grammars.nix config;
124 runtimeDir = pkgs.runCommand "helix-runtime" {} ''
125 mkdir -p $out
126 ln -s ${mkRootPath "runtime"}/* $out
127 rm -r $out/grammars
128 ln -s ${grammars} $out/grammars
129 '';
130 helix-wrapped =
131 pkgs.runCommand "${old.name}-wrapped"
132 {
133 inherit (old) pname version meta;
135 nativeBuildInputs = [pkgs.makeWrapper];
136 makeWrapperArgs = config.makeWrapperArgs or [];
137 }
138 ''
139 mkdir -p $out
140 cp -r --no-preserve=mode,ownership ${old}/* $out/
141 chmod +x $out/bin/*
142 wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
143 '';
144 in
145 helix-wrapped
146 // {override = makeOverridableHelix system old;};
147 in
148 outputs
149 // {
150 apps =
151 lib.mapAttrs
152 (
153 system: apps: rec {
154 default = hx;
155 hx = {
156 type = "app";
157 program = lib.getExe self.${system}.packages.helix;
158 };
159 }
160 )
161 outputs.apps;
162 packages =
163 lib.mapAttrs
164 (
165 system: packages: rec {
166 default = helix;
167 helix = makeOverridableHelix system helix-unwrapped {};
168 helix-debug = makeOverridableHelix system helix-unwrapped-debug {};
169 helix-unwrapped = packages.helix;
170 helix-unwrapped-debug = packages.helix-debug;
171 }
172 )
173 outputs.packages;
174 };
176 nixConfig = {
177 extra-substituters = ["https://helix.cachix.org"];
178 extra-trusted-public-keys = ["helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="];
179 };