@@ -7,128 +7,169 @@
77 url = "github:oxalica/rust-overlay";
88 inputs.nixpkgs.follows = "nixpkgs";
99 };
10− nixCargoIntegration = {
10+ nci = {
1111 url = "github:yusdacra/nix-cargo-integration";
1212 inputs.nixpkgs.follows = "nixpkgs";
1313 inputs.rust-overlay.follows = "rust-overlay";
1414 };
1515 };
1616
17− outputs = inputs @ {
17+ outputs = {
18+ self,
1819 nixpkgs,
19− nixCargoIntegration,
20+ nci,
2021 ...
2122 }: 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];
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+ };
6470
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− ];
71+ # disable fetching and building of tree-sitter grammars in the helix-term build.rs
72+ HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
73+
74+ buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
75+
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+ '';
86+
87+ meta.mainProgram = "hx";
10688 };
10789 };
90+ shell = common: prev: {
91+ packages =
92+ prev.packages
93+ ++ (
94+ with common.pkgs;
95+ [lld_13 lldb cargo-flamegraph rust-analyzer]
96+ ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
97+ );
98+ env =
99+ prev.env
100+ ++ [
101+ {
102+ name = "HELIX_RUNTIME";
103+ eval = "$PWD/runtime";
104+ }
105+ {
106+ name = "RUST_BACKTRACE";
107+ value = "1";
108+ }
109+ {
110+ name = "RUSTFLAGS";
111+ value =
112+ if common.pkgs.stdenv.isLinux
113+ then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
114+ else "";
115+ }
116+ ];
117+ };
108118 };
109− defaultOutputs = outputs {};
110− makeOverridableHelix = system: old:
111− old
112− // {
113− override = args:
114− makeOverridableHelix
115− system
116− (outputs args).packages.${system}.helix;
117− };
119+ };
120+ makeOverridableHelix = system: old: config: let
121+ pkgs = nixpkgs.legacyPackages.${system};
122+ grammars = pkgs.callPackage ./grammars.nix config;
123+ runtimeDir = pkgs.runCommand "helix-runtime" {} ''
124+ mkdir -p $out
125+ ln -s ${mkRootPath "runtime"}/* $out
126+ rm -r $out/grammars
127+ ln -s ${grammars} $out/grammars
128+ '';
129+ helix-wrapped =
130+ pkgs.runCommand "${old.name}-wrapped"
131+ {
132+ inherit (old) pname version meta;
133+
134+ nativeBuildInputs = [pkgs.makeWrapper];
135+ makeWrapperArgs = config.makeWrapperArgs or [];
136+ }
137+ ''
138+ mkdir -p $out
139+ cp -r --no-preserve=mode,ownership ${old}/* $out/
140+ chmod +x $out/bin/*
141+ wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
142+ '';
143+ in
144+ helix-wrapped
145+ // {override = makeOverridableHelix system old;};
118146 in
119− defaultOutputs
147+ outputs
120148 // {
149+ apps =
150+ lib.mapAttrs
151+ (
152+ system: apps: rec {
153+ default = hx;
154+ hx = {
155+ type = "app";
156+ program = lib.getExe self.${system}.packages.helix;
157+ };
158+ }
159+ )
160+ outputs.apps;
121161 packages =
122− nixpkgs.lib.mapAttrs
162+ lib.mapAttrs
123163 (
124− system: packages:
125− packages
126− // rec {
127− default = helix;
128− helix = makeOverridableHelix system packages.helix;
129− }
164+ system: packages: rec {
165+ default = helix;
166+ helix = makeOverridableHelix system helix-unwrapped {};
167+ helix-debug = makeOverridableHelix system helix-unwrapped-debug {};
168+ helix-unwrapped = packages.helix;
169+ helix-unwrapped-debug = packages.helix-debug;
170+ }
130171 )
131− defaultOutputs.packages;
172+ outputs.packages;
132173 };
133174
134175 nixConfig = {