on master help sign in
build(nix): update nci, refactor flake, seperate wrapping, add source filtering (#3657)
e917a8eYusuf Bera Ertan
.github/workflows/cachix.yml+1−1
@@ -23,4 +23,4 @@ jobs:
23 authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
23 authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
24
24
25 - name: Build nix flake
25 - name: Build nix flake
26− run: nix build
26+ run: nix build -L
flake.lock+31−35
@@ -3,11 +3,11 @@
3 "crane": {
3 "crane": {
4 "flake": false,
4 "flake": false,
5 "locked": {
5 "locked": {
6− "lastModified": 1654444508,
6+ "lastModified": 1661875961,
7− "narHash": "sha256-4OBvQ4V7jyt7afs6iKUvRzJ1u/9eYnKzVQbeQdiamuY=",
7+ "narHash": "sha256-f1h/2c6Teeu1ofAHWzrS8TwBPcnN+EEu+z1sRVmMQTk=",
8 "owner": "ipetkov",
8 "owner": "ipetkov",
9 "repo": "crane",
9 "repo": "crane",
10− "rev": "db5482bf225acc3160899124a1df5a617cfa27b5",
10+ "rev": "d9f394e4e20e97c2a60c3ad82c2b6ef99be19e24",
11 "type": "github"
11 "type": "github"
12 },
12 },
13 "original": {
13 "original": {
@@ -19,11 +19,11 @@
19 "devshell": {
19 "devshell": {
20 "flake": false,
20 "flake": false,
21 "locked": {
21 "locked": {
22− "lastModified": 1655976588,
22+ "lastModified": 1660811669,
23− "narHash": "sha256-VreHyH6ITkf/1EX/8h15UqhddJnUleb0HgbC3gMkAEQ=",
23+ "narHash": "sha256-V6lmsaLNFz41myppL0yxglta92ijkSvpZ+XVygAh+bU=",
24 "owner": "numtide",
24 "owner": "numtide",
25 "repo": "devshell",
25 "repo": "devshell",
26− "rev": "899ca4629020592a13a46783587f6e674179d1db",
26+ "rev": "c2feacb46ee69949124c835419861143c4016fb5",
27 "type": "github"
27 "type": "github"
28 },
28 },
29 "original": {
29 "original": {
@@ -35,49 +35,45 @@
35 "dream2nix": {
35 "dream2nix": {
36 "inputs": {
36 "inputs": {
37 "alejandra": [
37 "alejandra": [
38− "nixCargoIntegration",
38+ "nci",
39 "nixpkgs"
39 "nixpkgs"
40 ],
40 ],
41 "crane": "crane",
41 "crane": "crane",
42 "devshell": [
42 "devshell": [
43− "nixCargoIntegration",
43+ "nci",
44 "devshell"
44 "devshell"
45 ],
45 ],
46 "flake-utils-pre-commit": [
46 "flake-utils-pre-commit": [
47− "nixCargoIntegration",
47+ "nci",
48 "nixpkgs"
48 "nixpkgs"
49 ],
49 ],
50 "gomod2nix": [
50 "gomod2nix": [
51− "nixCargoIntegration",
51+ "nci",
52 "nixpkgs"
52 "nixpkgs"
53 ],
53 ],
54 "mach-nix": [
54 "mach-nix": [
55− "nixCargoIntegration",
55+ "nci",
56 "nixpkgs"
56 "nixpkgs"
57 ],
57 ],
58 "nixpkgs": [
58 "nixpkgs": [
59− "nixCargoIntegration",
59+ "nci",
60− "nixpkgs"
61− ],
62− "node2nix": [
63− "nixCargoIntegration",
64 "nixpkgs"
60 "nixpkgs"
65 ],
61 ],
66 "poetry2nix": [
62 "poetry2nix": [
67− "nixCargoIntegration",
63+ "nci",
68 "nixpkgs"
64 "nixpkgs"
69 ],
65 ],
70 "pre-commit-hooks": [
66 "pre-commit-hooks": [
71− "nixCargoIntegration",
67+ "nci",
72 "nixpkgs"
68 "nixpkgs"
73 ]
69 ]
74 },
70 },
75 "locked": {
71 "locked": {
76− "lastModified": 1655975833,
72+ "lastModified": 1662083074,
77− "narHash": "sha256-g8sdfuglIZ24oWVbntVzniNTJW+Z3n9DNL9w9Tt+UCE=",
73+ "narHash": "sha256-GL4/CLKPYUzkKD1l7oi2XB+vi3z4xGpCVLDdG3tRqvs=",
78 "owner": "nix-community",
74 "owner": "nix-community",
79 "repo": "dream2nix",
75 "repo": "dream2nix",
80− "rev": "4e75e665ec3a1cddae5266bed0dd72fce0b74a23",
76+ "rev": "c6c039fcc6abdf4d828b940b576944a224cf8622",
81 "type": "github"
77 "type": "github"
82 },
78 },
83 "original": {
79 "original": {
@@ -88,11 +84,11 @@
88 },
84 },
89 "flake-utils": {
85 "flake-utils": {
90 "locked": {
86 "locked": {
91− "lastModified": 1637014545,
87+ "lastModified": 1656928814,
92− "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
88+ "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
93 "owner": "numtide",
89 "owner": "numtide",
94 "repo": "flake-utils",
90 "repo": "flake-utils",
95− "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
91+ "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
96 "type": "github"
92 "type": "github"
97 },
93 },
98 "original": {
94 "original": {
@@ -101,7 +97,7 @@
101 "type": "github"
97 "type": "github"
102 }
98 }
103 },
99 },
104− "nixCargoIntegration": {
100+ "nci": {
105 "inputs": {
101 "inputs": {
106 "devshell": "devshell",
102 "devshell": "devshell",
107 "dream2nix": "dream2nix",
103 "dream2nix": "dream2nix",
@@ -113,11 +109,11 @@
113 ]
109 ]
114 },
110 },
115 "locked": {
111 "locked": {
116− "lastModified": 1656453541,
112+ "lastModified": 1662143940,
117− "narHash": "sha256-ZCPVnS6zJOZJvIlwU3rKR8MBVm6A3F4/0mA7G1lQ3D0=",
113+ "narHash": "sha256-3eJfehnZLWJGXylfpAMeLR0Q3sx8pAjGiHBQPqOH9+U=",
118 "owner": "yusdacra",
114 "owner": "yusdacra",
119 "repo": "nix-cargo-integration",
115 "repo": "nix-cargo-integration",
120− "rev": "9eb74345b30cd2e536d9dac9d4435d3c475605c7",
116+ "rev": "e83f2598aecbe1114783ff9bdae0b85939de35a3",
121 "type": "github"
117 "type": "github"
122 },
118 },
123 "original": {
119 "original": {
@@ -128,11 +124,11 @@
128 },
124 },
129 "nixpkgs": {
125 "nixpkgs": {
130 "locked": {
126 "locked": {
131− "lastModified": 1655624069,
127+ "lastModified": 1662019588,
132− "narHash": "sha256-7g1zwTdp35GMTERnSzZMWJ7PG3QdDE8VOX3WsnOkAtM=",
128+ "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=",
133 "owner": "nixos",
129 "owner": "nixos",
134 "repo": "nixpkgs",
130 "repo": "nixpkgs",
135− "rev": "0d68d7c857fe301d49cdcd56130e0beea4ecd5aa",
131+ "rev": "2da64a81275b68fdad38af669afeda43d401e94b",
136 "type": "github"
132 "type": "github"
137 },
133 },
138 "original": {
134 "original": {
@@ -144,7 +140,7 @@
144 },
140 },
145 "root": {
141 "root": {
146 "inputs": {
142 "inputs": {
147− "nixCargoIntegration": "nixCargoIntegration",
143+ "nci": "nci",
148 "nixpkgs": "nixpkgs",
144 "nixpkgs": "nixpkgs",
149 "rust-overlay": "rust-overlay"
145 "rust-overlay": "rust-overlay"
150 }
146 }
@@ -157,11 +153,11 @@
157 ]
153 ]
158 },
154 },
159 "locked": {
155 "locked": {
160− "lastModified": 1655779671,
156+ "lastModified": 1662087605,
161− "narHash": "sha256-6feeiGa6fb7ZPVHR71uswkmN1701TAJpwYQA8QffmRk=",
157+ "narHash": "sha256-Gpf2gp2JenKGf+TylX/YJpttY2bzsnvAMLdLaxoZRyU=",
162 "owner": "oxalica",
158 "owner": "oxalica",
163 "repo": "rust-overlay",
159 "repo": "rust-overlay",
164− "rev": "8159585609a772b041cce6019d5c21d240709244",
160+ "rev": "60c2cfaa8b90ed8cebd18b214fac8682dcf222dd",
165 "type": "github"
161 "type": "github"
166 },
162 },
167 "original": {
163 "original": {
flake.nix+145−104
@@ -7,128 +7,169 @@
7 url = "github:oxalica/rust-overlay";
7 url = "github:oxalica/rust-overlay";
8 inputs.nixpkgs.follows = "nixpkgs";
8 inputs.nixpkgs.follows = "nixpkgs";
9 };
9 };
10− nixCargoIntegration = {
10+ nci = {
11 url = "github:yusdacra/nix-cargo-integration";
11 url = "github:yusdacra/nix-cargo-integration";
12 inputs.nixpkgs.follows = "nixpkgs";
12 inputs.nixpkgs.follows = "nixpkgs";
13 inputs.rust-overlay.follows = "rust-overlay";
13 inputs.rust-overlay.follows = "rust-overlay";
14 };
14 };
15 };
15 };
16
16
17− outputs = inputs @ {
17+ outputs = {
18+ self,
18 nixpkgs,
19 nixpkgs,
19− nixCargoIntegration,
20+ nci,
20 ...
21 ...
21 }: let
22 }: let
22− outputs = config:
23+ lib = nixpkgs.lib;
24+ mkRootPath = rel:
25+ builtins.path {
26+ path = "${toString ./.}/${rel}";
27+ name = rel;
28+ };
23− nixCargoIntegration.lib.makeOutputs {
29+ outputs = nci.lib.makeOutputs {
24− root = ./.;
30+ root = ./.;
25− renameOutputs = {"helix-term" = "helix";};
31+ renameOutputs = {"helix-term" = "helix";};
26− # Set default app to hx (binary is from helix-term release build)
32+ # Set default app to hx (binary is from helix-term release build)
27− # Set default package to helix-term release build
33+ # Set default package to helix-term release build
28− defaultOutputs = {
34+ defaultOutputs = {
29− app = "hx";
35+ app = "hx";
30− package = "helix";
36+ package = "helix";
31− };
37+ };
32− overrides = {
38+ overrides = {
33− cCompiler = common:
39+ cCompiler = common:
34− with common.pkgs;
40+ with common.pkgs;
35− if stdenv.isLinux
41+ if stdenv.isLinux
36− then gcc
42+ then gcc
37− else clang;
43+ else clang;
38− crateOverrides = common: _: {
44+ crateOverrides = common: _: {
39− helix-term = prev: let
45+ helix-term = prev: {
40− inherit (common) pkgs;
41− mkRootPath = rel:
42− builtins.path {
46+ src = builtins.path {
43− path = "${common.root}/${rel}";
47+ name = "helix-source";
44− name = rel;
48+ path = toString ./.;
45− };
49+ # filter out unneeded stuff that cause rebuilds
46− grammars = pkgs.callPackage ./grammars.nix config;
50+ filter = path: type:
47− runtimeDir = pkgs.runCommandNoCC "helix-runtime" {} ''
51+ lib.all
48− mkdir -p $out
52+ (n: builtins.baseNameOf path != n)
49− ln -s ${mkRootPath "runtime"}/* $out
53+ [
50− rm -r $out/grammars
54+ ".envrc"
51− ln -s ${grammars} $out/grammars
55+ ".ignore"
52− '';
56+ ".github"
53− overridedAttrs = {
57+ "runtime"
54− # disable fetching and building of tree-sitter grammars in the helix-term build.rs
58+ "screenshot.png"
55− HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
59+ "book"
56− # link languages and theme toml files since helix-term expects them (for tests)
60+ "contrib"
57− preConfigure =
61+ "docs"
58− pkgs.lib.concatMapStringsSep
62+ "README.md"
59− "\n"
63+ "shell.nix"
60− (path: "ln -sf ${mkRootPath path} ..")
64+ "default.nix"
61− ["languages.toml" "theme.toml" "base16_theme.toml"];
65+ "grammars.nix"
62− buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
66+ "flake.nix"
63− nativeBuildInputs = [pkgs.makeWrapper];
67+ "flake.lock"
68+ ];
69+ };
64
70
65− postFixup = ''
71+ # disable fetching and building of tree-sitter grammars in the helix-term build.rs
66− if [ -f "$out/bin/hx" ]; then
72+ HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
67− wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
73+
68− fi
74+ buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
69− '';
75+
70− };
76+ # link languages and theme toml files since helix-term expects them (for tests)
71− in
77+ preConfigure = ''
72− overridedAttrs
78+ ${prev.preConfigure or ""}
73− // (
79+ ${
74− pkgs.lib.optionalAttrs
80+ lib.concatMapStringsSep
75− (config ? makeWrapperArgs)
81+ "\n"
76− {inherit (config) makeWrapperArgs;}
82+ (path: "ln -sf ${mkRootPath path} ..")
77− );
83+ ["languages.toml" "theme.toml" "base16_theme.toml"]
78− };
84+ }
79− shell = common: prev: {
85+ '';
80− packages =
86+
81− prev.packages
87+ meta.mainProgram = "hx";
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− ];
106 };
88 };
107 };
89 };
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+ };
108 };
118 };
109− defaultOutputs = outputs {};
119+ };
110− makeOverridableHelix = system: old:
120+ makeOverridableHelix = system: old: config: let
111− old
121+ pkgs = nixpkgs.legacyPackages.${system};
112− // {
122+ grammars = pkgs.callPackage ./grammars.nix config;
113− override = args:
123+ runtimeDir = pkgs.runCommand "helix-runtime" {} ''
114− makeOverridableHelix
124+ mkdir -p $out
115− system
125+ ln -s ${mkRootPath "runtime"}/* $out
116− (outputs args).packages.${system}.helix;
126+ rm -r $out/grammars
117− };
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;};
118 in
146 in
119− defaultOutputs
147+ outputs
120 // {
148 // {
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;
121 packages =
161 packages =
122− nixpkgs.lib.mapAttrs
162+ lib.mapAttrs
123 (
163 (
124− system: packages:
164+ system: packages: rec {
125− packages
126− // rec {
127− default = helix;
165+ default = helix;
128− helix = makeOverridableHelix system packages.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;
129− }
170+ }
130 )
171 )
131− defaultOutputs.packages;
172+ outputs.packages;
132 };
173 };
133
174
134 nixConfig = {
175 nixConfig = {