@@ -3,166 +3,190 @@
5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+ flake-utils.url = "github:numtide/flake-utils";
6 rust-overlay = {
7 rust-overlay = {
7 url = "github:oxalica/rust-overlay";
8 url = "github:oxalica/rust-overlay";
8− inputs.nixpkgs.follows = "nixpkgs";
10+ nixpkgs.follows = "nixpkgs";
11+ flake-utils.follows = "flake-utils";
11− url = "github:yusdacra/nix-cargo-integration";
15+ url = "github:ipetkov/crane";
12− inputs.nixpkgs.follows = "nixpkgs";
13 inputs.rust-overlay.follows = "rust-overlay";
16 inputs.rust-overlay.follows = "rust-overlay";
17+ inputs.flake-utils.follows = "flake-utils";
18+ inputs.nixpkgs.follows = "nixpkgs";
15− parts.url = "github:hercules-ci/flake-parts";
18− outputs = inp: let
22+ outputs = {
19− mkRootPath = rel:
23+ self,
20− builtins.path {
24+ nixpkgs,
21− path = "${toString ./.}/${rel}";
25+ crane,
22− name = rel;
26+ flake-utils,
30+ flake-utils.lib.eachDefaultSystem (system: let
31+ pkgs = import nixpkgs {
33+ overlays = [(import rust-overlay)];
37+ path = "${toString ./.}/${rel}";
24− filteredSource = let
40+ filteredSource = let
25− pathsToIgnore = [
41+ pathsToIgnore = [
27− ".ignore"
43+ ".ignore"
28− ".github"
44+ ".github"
29− ".gitignore"
45+ ".gitignore"
30− "logo.svg"
46+ "logo.svg"
31− "logo_dark.svg"
47+ "logo_dark.svg"
32− "logo_light.svg"
48+ "logo_light.svg"
33− "rust-toolchain.toml"
49+ "rust-toolchain.toml"
34− "rustfmt.toml"
50+ "rustfmt.toml"
35− "runtime"
51+ "runtime"
36− "screenshot.png"
52+ "screenshot.png"
38− "contrib"
54+ "contrib"
40− "README.md"
56+ "README.md"
41− "CHANGELOG.md"
57+ "CHANGELOG.md"
42− "shell.nix"
58+ "shell.nix"
43− "default.nix"
59+ "default.nix"
44− "grammars.nix"
60+ "grammars.nix"
45− "flake.nix"
61+ "flake.nix"
46− "flake.lock"
62+ "flake.lock"
48− ignorePaths = path: type: let
64+ ignorePaths = path: type: let
49− inherit (inp.nixpkgs) lib;
65+ inherit (nixpkgs) lib;
50− # split the nix store path into its components
66+ # split the nix store path into its components
51− components = lib.splitString "/" path;
67+ components = lib.splitString "/" path;
52− # drop off the `/nix/hash-source` section from the path
68+ # drop off the `/nix/hash-source` section from the path
53− relPathComponents = lib.drop 4 components;
69+ relPathComponents = lib.drop 4 components;
54− # reassemble the path components
70+ # reassemble the path components
55− relPath = lib.concatStringsSep "/" relPathComponents;
71+ relPath = lib.concatStringsSep "/" relPathComponents;
57− lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
60− name = "helix-source";
62− # filter out unnecessary paths
63− filter = ignorePaths;
66− inp.parts.lib.mkFlake {inputs = inp;} {
67− imports = [inp.nci.flakeModule inp.parts.flakeModules.easyOverlay];
81− makeOverridableHelix = old: config: let
82− grammars = pkgs.callPackage ./grammars.nix config;
83− runtimeDir = pkgs.runCommand "helix-runtime" {} ''
85− ln -s ${mkRootPath "runtime"}/* $out
87− ln -s ${grammars} $out/grammars
93− inherit (old) pname version;
94− meta = old.meta or {};
100− nativeBuildInputs = [pkgs.makeWrapper];
101− makeWrapperArgs = config.makeWrapperArgs or [];
104− cp -rs --no-preserve=mode,ownership ${old} $out
105− wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
108− helix-wrapped
73+ lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
76+ name = "helix-source";
78+ # filter out unnecessary paths
79+ filter = ignorePaths;
110− override = makeOverridableHelix old;
81+ makeOverridableHelix = old: config: let
82+ grammars = pkgs.callPackage ./grammars.nix config;
83+ runtimeDir = pkgs.runCommand "helix-runtime" {} ''
85+ ln -s ${mkRootPath "runtime"}/* $out
87+ ln -s ${grammars} $out/grammars
93+ inherit (old) pname version;
94+ meta = old.meta or {};
111 passthru =
95 passthru =
112− helix-wrapped.passthru
96+ (old.passthru or {})
114− wrapper = old: makeOverridableHelix old config;
98+ unwrapped = old;
116− };
100+ nativeBuildInputs = [pkgs.makeWrapper];
117− stdenv =
101+ makeWrapperArgs = config.makeWrapperArgs or [];
118− if pkgs.stdenv.isLinux
102+ }
119− then pkgs.stdenv
103+ ''
120− else pkgs.clangStdenv;
104+ cp -rs --no-preserve=mode,ownership ${old} $out
121− rustFlagsEnv =
105+ wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
122− if stdenv.isLinux
106+ '';
123− then ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
126− nci.projects."helix-project".relPath = "";
108+ helix-wrapped
127− nci.crates."helix-term" = {
109+ // {
128− overrides = {
110+ override = makeOverridableHelix old;
129− add-meta.override = _: {meta.mainProgram = "hx";};
111+ passthru =
130− add-inputs.overrideAttrs = prev: {
112+ helix-wrapped.passthru
131− buildInputs = (prev.buildInputs or []) ++ [stdenv.cc.cc.lib];
113+ // {
132− };
114+ wrapper = old: makeOverridableHelix old config;
133− disable-grammar-builds = {
134− # disable fetching and building of tree-sitter grammars in the helix-term build.rs
135− HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
137− disable-tests = {checkPhase = ":";};
138− set-stdenv.override = _: {inherit stdenv;};
139− set-filtered-src.override = _: {src = filteredSource;};
118+ if pkgs.stdenv.isLinux
120+ else pkgs.clangStdenv;
123+ then ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
125+ rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
126+ craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
130+ src = filteredSource;
131+ # disable fetching and building of tree-sitter grammars in the helix-term build.rs
132+ HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
133+ buildInputs = [stdenv.cc.cc.lib];
136+ meta.mainProgram = "hx";
138+ // craneLib.crateNameFromCargoToml {cargoToml = ./helix-term/Cargo.toml;};
139+ cargoArtifacts = craneLib.buildDepsOnly commonArgs;
142+ helix-unwrapped = craneLib.buildPackage (commonArgs
144+ inherit cargoArtifacts;
146+ helix = makeOverridableHelix self.packages.${system}.helix-unwrapped {};
147+ default = self.packages.${system}.helix;
143− packages.helix-unwrapped = config.nci.outputs."helix-term".packages.release;
150+ checks = {
144− packages.helix-unwrapped-dev = config.nci.outputs."helix-term".packages.dev;
151+ # Build the crate itself
145− packages.helix = makeOverridableHelix config.packages.helix-unwrapped {};
152+ inherit (self.packages.${system}) helix;
146− packages.helix-dev = makeOverridableHelix config.packages.helix-unwrapped-dev {};
147− packages.default = config.packages.helix;
149− overlayAttrs = {
154+ clippy = craneLib.cargoClippy (commonArgs
150− inherit (config.packages) helix;
155+ // {
156+ inherit cargoArtifacts;
157+ cargoClippyExtraArgs = "--all-targets -- --deny warnings";
153− devShells.default = config.nci.outputs."helix-project".devShell.overrideAttrs (old: {
160+ fmt = craneLib.cargoFmt commonArgs;
154− nativeBuildInputs =
161+
162+ doc = craneLib.cargoDoc (commonArgs
164+ inherit cargoArtifacts;
167+ test = craneLib.cargoTest (commonArgs
169+ inherit cargoArtifacts;
173+ devShells.default = pkgs.mkShell {
174+ inputsFrom = builtins.attrValues self.checks.${system};
155− (old.nativeBuildInputs or [])
175+ nativeBuildInputs = with pkgs;
156− ++ (with pkgs; [lld_13 cargo-flamegraph rust-analyzer])
176+ [lld_13 cargo-flamegraph rust-analyzer]
157− ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) pkgs.cargo-tarpaulin)
177+ ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) pkgs.cargo-tarpaulin)
158− ++ (lib.optional stdenv.isLinux pkgs.lldb)
178+ ++ (lib.optional stdenv.isLinux pkgs.lldb)
159− ++ (lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreFoundation);
179+ ++ (lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreFoundation);
160− shellHook = ''
180+ shellHook = ''
161− export HELIX_RUNTIME="$PWD/runtime"
181+ export HELIX_RUNTIME="$PWD/runtime"
162− export RUST_BACKTRACE="1"
182+ export RUST_BACKTRACE="1"
163− export RUSTFLAGS="${rustFlagsEnv}"
183+ export RUSTFLAGS="${rustFlagsEnv}"
188+ overlays.default = final: prev: {
189+ inherit (self.packages.${final.system}) helix;