on master help sign in
Refactor Nix flake to use crane (#7763)
d6856cfMichael Davis
flake.lock+25−218
@@ -1,110 +1,29 @@
1{
1{
2 "nodes": {
2 "nodes": {
3 "crane": {
3 "crane": {
4− "flake": false,
5− "locked": {
6− "lastModified": 1681175776,
7− "narHash": "sha256-7SsUy9114fryHAZ8p1L6G6YSu7jjz55FddEwa2U8XZc=",
8− "owner": "ipetkov",
9− "repo": "crane",
10− "rev": "445a3d222947632b5593112bb817850e8a9cf737",
11− "type": "github"
12− },
13− "original": {
14− "owner": "ipetkov",
15− "ref": "v0.12.1",
16− "repo": "crane",
17− "type": "github"
18− }
19− },
20− "dream2nix": {
21 "inputs": {
4 "inputs": {
22− "all-cabal-json": [
23− "nci"
24− ],
25− "crane": "crane",
26− "devshell": [
27− "nci"
28− ],
29− "drv-parts": "drv-parts",
30 "flake-compat": "flake-compat",
5 "flake-compat": "flake-compat",
31− "flake-parts": [
6+ "flake-utils": [
32− "nci",
33− "parts"
34− ],
35− "flake-utils-pre-commit": [
36− "nci"
37− ],
38− "ghc-utils": [
7+ "flake-utils"
39− "nci"
40− ],
41− "gomod2nix": [
42− "nci"
43− ],
44− "mach-nix": [
45− "nci"
46− ],
47− "nix-pypi-fetcher": [
48− "nci"
49 ],
8 ],
50 "nixpkgs": [
9 "nixpkgs": [
51− "nci",
52 "nixpkgs"
10 "nixpkgs"
53 ],
11 ],
54− "nixpkgsV1": "nixpkgsV1",
12+ "rust-overlay": [
55− "poetry2nix": [
13+ "rust-overlay"
56− "nci"
57− ],
58− "pre-commit-hooks": [
59− "nci"
60− ],
61− "pruned-racket-catalog": [
62− "nci"
63− ]
64− },
65− "locked": {
66− "lastModified": 1683212002,
67− "narHash": "sha256-EObtqyQsv9v+inieRY5cvyCMCUI5zuU5qu+1axlJCPM=",
68− "owner": "nix-community",
69− "repo": "dream2nix",
70− "rev": "fbfb09d2ab5ff761d822dd40b4a1def81651d096",
71− "type": "github"
72− },
73− "original": {
74− "owner": "nix-community",
75− "repo": "dream2nix",
76− "type": "github"
77− }
78− },
79− "drv-parts": {
80− "inputs": {
81− "flake-compat": [
82− "nci",
83− "dream2nix",
84− "flake-compat"
85− ],
86− "flake-parts": [
87− "nci",
88− "dream2nix",
89− "flake-parts"
90− ],
91− "nixpkgs": [
92− "nci",
93− "dream2nix",
94− "nixpkgs"
95 ]
14 ]
96 },
15 },
97 "locked": {
16 "locked": {
98− "lastModified": 1680698112,
17+ "lastModified": 1688772518,
99− "narHash": "sha256-FgnobN/DvCjEsc0UAZEAdPLkL4IZi2ZMnu2K2bUaElc=",
18+ "narHash": "sha256-ol7gZxwvgLnxNSZwFTDJJ49xVY5teaSvF7lzlo3YQfM=",
100− "owner": "davhau",
19+ "owner": "ipetkov",
101− "repo": "drv-parts",
20+ "repo": "crane",
102− "rev": "e8c2ec1157dc1edb002989669a0dbd935f430201",
21+ "rev": "8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e",
103 "type": "github"
22 "type": "github"
104 },
23 },
105 "original": {
24 "original": {
106− "owner": "davhau",
25+ "owner": "ipetkov",
107− "repo": "drv-parts",
26+ "repo": "crane",
108 "type": "github"
27 "type": "github"
109 }
28 }
110 },
29 },
@@ -129,11 +48,11 @@
129 "systems": "systems"
48 "systems": "systems"
130 },
49 },
131 "locked": {
50 "locked": {
132− "lastModified": 1681202837,
51+ "lastModified": 1689068808,
133− "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
52+ "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
134 "owner": "numtide",
53 "owner": "numtide",
135 "repo": "flake-utils",
54 "repo": "flake-utils",
136− "rev": "cfacdce06f30d2b68473a46042957675eebb3401",
55+ "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
137 "type": "github"
56 "type": "github"
138 },
57 },
139 "original": {
58 "original": {
@@ -142,55 +61,13 @@
142 "type": "github"
61 "type": "github"
143 }
62 }
144 },
63 },
145− "mk-naked-shell": {
146− "flake": false,
147− "locked": {
148− "lastModified": 1681286841,
149− "narHash": "sha256-3XlJrwlR0nBiREnuogoa5i1b4+w/XPe0z8bbrJASw0g=",
150− "owner": "yusdacra",
151− "repo": "mk-naked-shell",
152− "rev": "7612f828dd6f22b7fb332cc69440e839d7ffe6bd",
153− "type": "github"
154− },
155− "original": {
156− "owner": "yusdacra",
157− "repo": "mk-naked-shell",
158− "type": "github"
159− }
160− },
161− "nci": {
162− "inputs": {
163− "dream2nix": "dream2nix",
164− "mk-naked-shell": "mk-naked-shell",
165− "nixpkgs": [
166− "nixpkgs"
167− ],
168− "parts": "parts",
169− "rust-overlay": [
170− "rust-overlay"
171− ]
172− },
173− "locked": {
174− "lastModified": 1683699050,
175− "narHash": "sha256-UWKQpzVcSshB+sU2O8CCHjOSTQrNS7Kk9V3+UeBsJpg=",
176− "owner": "yusdacra",
177− "repo": "nix-cargo-integration",
178− "rev": "ed27173cd1b223f598343ea3c15aacb1d140feac",
179− "type": "github"
180− },
181− "original": {
182− "owner": "yusdacra",
183− "repo": "nix-cargo-integration",
184− "type": "github"
185− }
186− },
187 "nixpkgs": {
64 "nixpkgs": {
188 "locked": {
65 "locked": {
189− "lastModified": 1683408522,
66+ "lastModified": 1690272529,
190− "narHash": "sha256-9kcPh6Uxo17a3kK3XCHhcWiV1Yu1kYj22RHiymUhMkU=",
67+ "narHash": "sha256-MakzcKXEdv/I4qJUtq/k/eG+rVmyOZLnYNC2w1mB59Y=",
191 "owner": "nixos",
68 "owner": "nixos",
192 "repo": "nixpkgs",
69 "repo": "nixpkgs",
193− "rev": "897876e4c484f1e8f92009fd11b7d988a121a4e7",
70+ "rev": "ef99fa5c5ed624460217c31ac4271cfb5cb2502c",
194 "type": "github"
71 "type": "github"
195 },
72 },
196 "original": {
73 "original": {
@@ -200,99 +77,29 @@
200 "type": "github"
77 "type": "github"
201 }
78 }
202 },
79 },
203− "nixpkgs-lib": {
204− "locked": {
205− "dir": "lib",
206− "lastModified": 1682879489,
207− "narHash": "sha256-sASwo8gBt7JDnOOstnps90K1wxmVfyhsTPPNTGBPjjg=",
208− "owner": "NixOS",
209− "repo": "nixpkgs",
210− "rev": "da45bf6ec7bbcc5d1e14d3795c025199f28e0de0",
211− "type": "github"
212− },
213− "original": {
214− "dir": "lib",
215− "owner": "NixOS",
216− "ref": "nixos-unstable",
217− "repo": "nixpkgs",
218− "type": "github"
219− }
220− },
221− "nixpkgsV1": {
222− "locked": {
223− "lastModified": 1678500271,
224− "narHash": "sha256-tRBLElf6f02HJGG0ZR7znMNFv/Uf7b2fFInpTHiHaSE=",
225− "owner": "NixOS",
226− "repo": "nixpkgs",
227− "rev": "5eb98948b66de29f899c7fe27ae112a47964baf8",
228− "type": "github"
229− },
230− "original": {
231− "id": "nixpkgs",
232− "ref": "nixos-22.11",
233− "type": "indirect"
234− }
235− },
236− "parts": {
237− "inputs": {
238− "nixpkgs-lib": [
239− "nci",
240− "nixpkgs"
241− ]
242− },
243− "locked": {
244− "lastModified": 1683560683,
245− "narHash": "sha256-XAygPMN5Xnk/W2c1aW0jyEa6lfMDZWlQgiNtmHXytPc=",
246− "owner": "hercules-ci",
247− "repo": "flake-parts",
248− "rev": "006c75898cf814ef9497252b022e91c946ba8e17",
249− "type": "github"
250− },
251− "original": {
252− "owner": "hercules-ci",
253− "repo": "flake-parts",
254− "type": "github"
255− }
256− },
257− "parts_2": {
258− "inputs": {
259− "nixpkgs-lib": "nixpkgs-lib"
260− },
261− "locked": {
262− "lastModified": 1683560683,
263− "narHash": "sha256-XAygPMN5Xnk/W2c1aW0jyEa6lfMDZWlQgiNtmHXytPc=",
264− "owner": "hercules-ci",
265− "repo": "flake-parts",
266− "rev": "006c75898cf814ef9497252b022e91c946ba8e17",
267− "type": "github"
268− },
269− "original": {
270− "owner": "hercules-ci",
271− "repo": "flake-parts",
272− "type": "github"
273− }
274− },
275 "root": {
80 "root": {
276 "inputs": {
81 "inputs": {
277− "nci": "nci",
82+ "crane": "crane",
83+ "flake-utils": "flake-utils",
278 "nixpkgs": "nixpkgs",
84 "nixpkgs": "nixpkgs",
279− "parts": "parts_2",
280 "rust-overlay": "rust-overlay"
85 "rust-overlay": "rust-overlay"
281 }
86 }
282 },
87 },
283 "rust-overlay": {
88 "rust-overlay": {
284 "inputs": {
89 "inputs": {
285− "flake-utils": "flake-utils",
90+ "flake-utils": [
91+ "flake-utils"
92+ ],
286 "nixpkgs": [
93 "nixpkgs": [
287 "nixpkgs"
94 "nixpkgs"
288 ]
95 ]
289 },
96 },
290 "locked": {
97 "locked": {
291− "lastModified": 1683771545,
98+ "lastModified": 1690424156,
292− "narHash": "sha256-we0GYcKTo2jRQGmUGrzQ9VH0OYAUsJMCsK8UkF+vZUA=",
99+ "narHash": "sha256-Bpml+L280tHTQpwpC5/BJbU4HSvEzMvW8IZ4gAXimhE=",
293 "owner": "oxalica",
100 "owner": "oxalica",
294 "repo": "rust-overlay",
101 "repo": "rust-overlay",
295− "rev": "c57e210faf68e5d5386f18f1b17ad8365d25e4ed",
102+ "rev": "f335a0213504c7e6481c359dc1009be9cf34432c",
296 "type": "github"
103 "type": "github"
297 },
104 },
298 "original": {
105 "original": {
flake.nix+167−143
@@ -3,166 +3,190 @@
3
3
4 inputs = {
4 inputs = {
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";
9+ inputs = {
8− inputs.nixpkgs.follows = "nixpkgs";
10+ nixpkgs.follows = "nixpkgs";
11+ flake-utils.follows = "flake-utils";
12+ };
9 };
13 };
10− nci = {
14+ crane = {
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";
14 };
19 };
15− parts.url = "github:hercules-ci/flake-parts";
16 };
20 };
17
21
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,
27+ rust-overlay,
28+ ...
29+ }:
30+ flake-utils.lib.eachDefaultSystem (system: let
31+ pkgs = import nixpkgs {
32+ inherit system;
33+ overlays = [(import rust-overlay)];
23 };
34 };
35+ mkRootPath = rel:
36+ builtins.path {
37+ path = "${toString ./.}/${rel}";
38+ name = rel;
39+ };
24− filteredSource = let
40+ filteredSource = let
25− pathsToIgnore = [
41+ pathsToIgnore = [
26− ".envrc"
42+ ".envrc"
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"
37− "book"
53+ "book"
38− "contrib"
54+ "contrib"
39− "docs"
55+ "docs"
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"
47− ];
63+ ];
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;
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− '';
107 in
72 in
108− helix-wrapped
73+ lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
109− // {
74+ in
75+ builtins.path {
76+ name = "helix-source";
77+ path = toString ./.;
78+ # filter out unnecessary paths
79+ filter = ignorePaths;
80+ };
110− override = makeOverridableHelix old;
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 {};
111 passthru =
95 passthru =
112− helix-wrapped.passthru
96+ (old.passthru or {})
113 // {
97 // {
114− wrapper = old: makeOverridableHelix old config;
98+ unwrapped = old;
115 };
99 };
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''
124− else "$RUSTFLAGS";
125− in {
107+ in
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";
136 };
115 };
137− disable-tests = {checkPhase = ":";};
138− set-stdenv.override = _: {inherit stdenv;};
139− set-filtered-src.override = _: {src = filteredSource;};
140− };
141 };
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+ 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+ };
142
149
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;
148
153
149− overlayAttrs = {
154+ clippy = craneLib.cargoClippy (commonArgs
150− inherit (config.packages) helix;
155+ // {
156+ inherit cargoArtifacts;
157+ cargoClippyExtraArgs = "--all-targets -- --deny warnings";
151− };
158+ });
152
159
153− devShells.default = config.nci.outputs."helix-project".devShell.overrideAttrs (old: {
160+ fmt = craneLib.cargoFmt commonArgs;
154− nativeBuildInputs =
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};
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}"
164− '';
184+ '';
165− });
185+ };
186+ })
187+ // {
188+ overlays.default = final: prev: {
189+ inherit (self.packages.${final.system}) helix;
166 };
190 };
167 };
191 };
168
192