on 4ef6621 help sign in
helix/flake.nix
180 lines 5.4 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 ncl = nci.lib.nci-lib;
25 mkRootPath = rel:
26 builtins.path {
27 path = "${toString ./.}/${rel}";
28 name = rel;
29 };
30 filteredSource = let
31 pathsToIgnore = [
32 ".envrc"
33 ".ignore"
34 ".github"
35 "runtime"
36 "screenshot.png"
37 "book"
38 "contrib"
39 "docs"
40 "README.md"
41 "CHANGELOG.md"
42 "shell.nix"
43 "default.nix"
44 "grammars.nix"
45 "flake.nix"
46 "flake.lock"
47 ];
48 ignorePaths = path: type: let
49 # split the nix store path into its components
50 components = lib.splitString "/" path;
51 # drop off the `/nix/hash-source` section from the path
52 relPathComponents = lib.drop 4 components;
53 # reassemble the path components
54 relPath = lib.concatStringsSep "/" relPathComponents;
55 in
56 lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
57 in
58 builtins.path {
59 name = "helix-source";
60 path = toString ./.;
61 # filter out unnecessary paths
62 filter = ignorePaths;
63 };
64 outputs = nci.lib.makeOutputs {
65 root = ./.;
66 config = common: {
67 outputs = {
68 # rename helix-term to helix since it's our main package
69 rename = {"helix-term" = "helix";};
70 # Set default app to hx (binary is from helix-term release build)
71 # Set default package to helix-term release build
72 defaults = {
73 app = "hx";
74 package = "helix";
75 };
76 };
77 cCompiler.package = with common.pkgs;
78 if stdenv.isLinux
79 then gcc
80 else clang;
81 shell = {
82 packages = with common.pkgs;
83 [lld_13 cargo-flamegraph rust-analyzer]
84 ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
85 ++ (lib.optional stdenv.isLinux lldb);
86 env = [
87 {
88 name = "HELIX_RUNTIME";
89 eval = "$PWD/runtime";
90 }
91 {
92 name = "RUST_BACKTRACE";
93 value = "1";
94 }
95 {
96 name = "RUSTFLAGS";
97 value =
98 if common.pkgs.stdenv.isLinux
99 then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
100 else "";
101 }
102 ];
103 };
104 };
105 pkgConfig = common: {
106 helix-term = {
107 # Wrap helix with runtime
108 wrapper = _: old: let
109 inherit (common) pkgs;
110 makeOverridableHelix = old: config: let
111 grammars = pkgs.callPackage ./grammars.nix config;
112 runtimeDir = pkgs.runCommand "helix-runtime" {} ''
113 mkdir -p $out
114 ln -s ${mkRootPath "runtime"}/* $out
115 rm -r $out/grammars
116 ln -s ${grammars} $out/grammars
117 '';
118 helix-wrapped =
119 common.internal.pkgsSet.utils.wrapDerivation old
120 {
121 nativeBuildInputs = [pkgs.makeWrapper];
122 makeWrapperArgs = config.makeWrapperArgs or [];
123 }
124 ''
125 rm -rf $out/bin
126 mkdir -p $out/bin
127 ln -sf ${old}/bin/* $out/bin/
128 wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
129 '';
130 in
131 helix-wrapped
132 // {override = makeOverridableHelix old;};
133 in
134 makeOverridableHelix old {};
135 overrides.fix-build.overrideAttrs = prev: {
136 src = filteredSource;
138 # disable fetching and building of tree-sitter grammars in the helix-term build.rs
139 HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
141 buildInputs = ncl.addBuildInputs prev [common.config.cCompiler.package.cc.lib];
143 # link languages and theme toml files since helix-term expects them (for tests)
144 preConfigure = ''
145 ${prev.preConfigure or ""}
146 ${
147 lib.concatMapStringsSep
148 "\n"
149 (path: "ln -sf ${mkRootPath path} ..")
150 ["languages.toml" "theme.toml" "base16_theme.toml"]
151 }
152 '';
153 checkPhase = ":";
155 meta.mainProgram = "hx";
156 };
157 };
158 };
159 };
160 in
161 outputs
162 // {
163 packages =
164 lib.mapAttrs
165 (
166 system: packages:
167 packages
168 // {
169 helix-unwrapped = packages.helix.passthru.unwrapped;
170 helix-unwrapped-dev = packages.helix-dev.passthru.unwrapped;
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 };