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