on aef00a3 help sign in
helix/flake.nix
138 lines 4.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 nixCargoIntegration = {
11 url = "github:yusdacra/nix-cargo-integration";
12 inputs.nixpkgs.follows = "nixpkgs";
13 inputs.rust-overlay.follows = "rust-overlay";
14 };
15 };
17 outputs = inputs @ {
18 nixpkgs,
19 nixCargoIntegration,
20 ...
21 }: let
22 outputs = config:
23 nixCargoIntegration.lib.makeOutputs {
24 root = ./.;
25 renameOutputs = {"helix-term" = "helix";};
26 # Set default app to hx (binary is from helix-term release build)
27 # Set default package to helix-term release build
28 defaultOutputs = {
29 app = "hx";
30 package = "helix";
31 };
32 overrides = {
33 cCompiler = common:
34 with common.pkgs;
35 if stdenv.isLinux
36 then gcc
37 else clang;
38 crateOverrides = common: _: {
39 helix-term = prev: let
40 inherit (common) pkgs;
41 mkRootPath = rel:
42 builtins.path {
43 path = "${common.root}/${rel}";
44 name = rel;
45 };
46 grammars = pkgs.callPackage ./grammars.nix config;
47 runtimeDir = pkgs.runCommandNoCC "helix-runtime" {} ''
48 mkdir -p $out
49 ln -s ${mkRootPath "runtime"}/* $out
50 rm -r $out/grammars
51 ln -s ${grammars} $out/grammars
52 '';
53 overridedAttrs = {
54 # disable fetching and building of tree-sitter grammars in the helix-term build.rs
55 HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
56 # link languages and theme toml files since helix-term expects them (for tests)
57 preConfigure =
58 pkgs.lib.concatMapStringsSep
59 "\n"
60 (path: "ln -sf ${mkRootPath path} ..")
61 ["languages.toml" "theme.toml" "base16_theme.toml"];
62 buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
63 nativeBuildInputs = [pkgs.makeWrapper];
65 postFixup = ''
66 if [ -f "$out/bin/hx" ]; then
67 wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
68 fi
69 '';
70 };
71 in
72 overridedAttrs
73 // (
74 pkgs.lib.optionalAttrs
75 (config ? makeWrapperArgs)
76 {inherit (config) makeWrapperArgs;}
77 );
78 };
79 shell = common: prev: {
80 packages =
81 prev.packages
82 ++ (
83 with common.pkgs;
84 [lld_13 lldb cargo-flamegraph rust-analyzer] ++
85 (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
86 );
87 env =
88 prev.env
89 ++ [
90 {
91 name = "HELIX_RUNTIME";
92 eval = "$PWD/runtime";
93 }
94 {
95 name = "RUST_BACKTRACE";
96 value = "1";
97 }
98 {
99 name = "RUSTFLAGS";
100 value =
101 if common.pkgs.stdenv.isLinux
102 then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
103 else "";
104 }
105 ];
106 };
107 };
108 };
109 defaultOutputs = outputs {};
110 makeOverridableHelix = system: old:
111 old
112 // {
113 override = args:
114 makeOverridableHelix
115 system
116 (outputs args).packages.${system}.helix;
117 };
118 in
119 defaultOutputs
120 // {
121 packages =
122 nixpkgs.lib.mapAttrs
123 (
124 system: packages:
125 packages
126 // rec {
127 default = helix;
128 helix = makeOverridableHelix system packages.helix;
129 }
130 )
131 defaultOutputs.packages;
132 };
134 nixConfig = {
135 extra-substituters = ["https://helix.cachix.org"];
136 extra-trusted-public-keys = ["helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="];
137 };