@@ -21,57 +21,124 @@
2121 ...
2222 }: let
2323 lib = nixpkgs.lib;
24+ ncl = nci.lib.nci-lib;
2425 mkRootPath = rel:
2526 builtins.path {
2627 path = "${toString ./.}/${rel}";
2728 name = rel;
2829 };
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+ };
2964 outputs = nci.lib.makeOutputs {
3065 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";
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+ };
37104 };
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− };
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;
70137
71138 # disable fetching and building of tree-sitter grammars in the helix-term build.rs
72139 HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
73140
74− buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
141+ buildInputs = ncl.addBuildInputs prev [common.config.cCompiler.package.cc.lib];
75142
76143 # link languages and theme toml files since helix-term expects them (for tests)
77144 preConfigure = ''
@@ -87,88 +154,20 @@
87154 meta.mainProgram = "hx";
88155 };
89156 };
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− };
119157 };
120158 };
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;
134−
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;};
147159 in
148160 outputs
149161 // {
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;
162162 packages =
163163 lib.mapAttrs
164164 (
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− }
165+ system: packages:
166+ packages
167+ // {
168+ helix-unwrapped = packages.helix.passthru.unwrapped;
169+ helix-unwrapped-debug = packages.helix-debug.passthru.unwrapped;
170+ }
172171 )
173172 outputs.packages;
174173 };