on master help sign in
build(nix): update flake to use flake-parts and nci flake-parts module
commite5af0f1d49547295be796a600c0841135f331618 authorYusuf Bera Ertan <y.bera003.06@protonmail.com> dateSat 25 Feb 2023, 06:27 (4 years ago) parent621ab0e
3 files changed+180−173
flake.lock+80−52 flake.nix+100−117 helix-term/Cargo.toml−4
flake.lock+80−52
@@ -16,22 +16,6 @@
1616 "type": "github"
1717 }
1818 },
19− "devshell": {
20− "flake": false,
21− "locked": {
22− "lastModified": 1667210711,
23− "narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=",
24− "owner": "numtide",
25− "repo": "devshell",
26− "rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7",
27− "type": "github"
28− },
29− "original": {
30− "owner": "numtide",
31− "repo": "devshell",
32− "type": "github"
33− }
34− },
3519 "dream2nix": {
3620 "inputs": {
3721 "alejandra": [
@@ -42,10 +26,12 @@
4226 ],
4327 "crane": "crane",
4428 "devshell": [
29+ "nci"
30+ ],
31+ "flake-parts": [
4532 "nci",
46− "devshell"
33+ "parts"
4734 ],
48− "flake-parts": "flake-parts",
4935 "flake-utils-pre-commit": [
5036 "nci"
5137 ],
@@ -70,14 +56,17 @@
7056 ],
7157 "pre-commit-hooks": [
7258 "nci"
59+ ],
60+ "pruned-racket-catalog": [
61+ "nci"
7362 ]
7463 },
7564 "locked": {
76− "lastModified": 1671323629,
77− "narHash": "sha256-9KHTPjIDjfnzZ4NjpE3gGIVHVHopy6weRDYO/7Y3hF8=",
65+ "lastModified": 1677289985,
66+ "narHash": "sha256-lUp06cTTlWubeBGMZqPl9jODM99LpWMcwxRiscFAUJg=",
7867 "owner": "nix-community",
7968 "repo": "dream2nix",
80− "rev": "2d7d68505c8619410df2c6b6463985f97cbcba6e",
69+ "rev": "28b973a8d4c30cc1cbb3377ea2023a76bc3fb889",
8170 "type": "github"
8271 },
8372 "original": {
@@ -86,24 +75,6 @@
8675 "type": "github"
8776 }
8877 },
89− "flake-parts": {
90− "inputs": {
91− "nixpkgs-lib": "nixpkgs-lib"
92− },
93− "locked": {
94− "lastModified": 1668450977,
95− "narHash": "sha256-cfLhMhnvXn6x1vPm+Jow3RiFAUSCw/l1utktCw5rVA4=",
96− "owner": "hercules-ci",
97− "repo": "flake-parts",
98− "rev": "d591857e9d7dd9ddbfba0ea02b43b927c3c0f1fa",
99− "type": "github"
100− },
101− "original": {
102− "owner": "hercules-ci",
103− "repo": "flake-parts",
104− "type": "github"
105− }
106− },
10778 "flake-utils": {
10879 "locked": {
10980 "lastModified": 1659877975,
@@ -119,23 +90,40 @@
11990 "type": "github"
12091 }
12192 },
93+ "mk-naked-shell": {
94+ "flake": false,
95+ "locked": {
96+ "lastModified": 1676572903,
97+ "narHash": "sha256-oQoDHHUTxNVSURfkFcYLuAK+btjs30T4rbEUtCUyKy8=",
98+ "owner": "yusdacra",
99+ "repo": "mk-naked-shell",
100+ "rev": "aeca9f8aa592f5e8f71f407d081cb26fd30c5a57",
101+ "type": "github"
102+ },
103+ "original": {
104+ "owner": "yusdacra",
105+ "repo": "mk-naked-shell",
106+ "type": "github"
107+ }
108+ },
122109 "nci": {
123110 "inputs": {
124− "devshell": "devshell",
125111 "dream2nix": "dream2nix",
112+ "mk-naked-shell": "mk-naked-shell",
126113 "nixpkgs": [
127114 "nixpkgs"
128115 ],
116+ "parts": "parts",
129117 "rust-overlay": [
130118 "rust-overlay"
131119 ]
132120 },
133121 "locked": {
134− "lastModified": 1671430291,
135− "narHash": "sha256-UIc7H8F3N8rK72J/Vj5YJdV72tvDvYjH+UPsOFvlcsE=",
122+ "lastModified": 1677294491,
123+ "narHash": "sha256-p09IOJqhUOM6egRJe4Ou1EXdTs/I9Pmm8e7pMYDlIWM=",
136124 "owner": "yusdacra",
137125 "repo": "nix-cargo-integration",
138− "rev": "b1b0d38b8c3b0d0e6a38638d5bbe10b0bc67522c",
126+ "rev": "a525ed36c440854f296cd958f4ebf574f0ebe22c",
139127 "type": "github"
140128 },
141129 "original": {
@@ -146,11 +134,11 @@
146134 },
147135 "nixpkgs": {
148136 "locked": {
149− "lastModified": 1671359686,
150− "narHash": "sha256-3MpC6yZo+Xn9cPordGz2/ii6IJpP2n8LE8e/ebUXLrs=",
137+ "lastModified": 1677063315,
138+ "narHash": "sha256-qiB4ajTeAOVnVSAwCNEEkoybrAlA+cpeiBxLobHndE8=",
151139 "owner": "nixos",
152140 "repo": "nixpkgs",
153− "rev": "04f574a1c0fde90b51bf68198e2297ca4e7cccf4",
141+ "rev": "988cc958c57ce4350ec248d2d53087777f9e1949",
154142 "type": "github"
155143 },
156144 "original": {
@@ -163,11 +151,11 @@
163151 "nixpkgs-lib": {
164152 "locked": {
165153 "dir": "lib",
166− "lastModified": 1665349835,
167− "narHash": "sha256-UK4urM3iN80UXQ7EaOappDzcisYIuEURFRoGQ/yPkug=",
154+ "lastModified": 1675183161,
155+ "narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=",
168156 "owner": "NixOS",
169157 "repo": "nixpkgs",
170− "rev": "34c5293a71ffdb2fe054eb5288adc1882c1eb0b1",
158+ "rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e",
171159 "type": "github"
172160 },
173161 "original": {
@@ -178,10 +166,50 @@
178166 "type": "github"
179167 }
180168 },
169+ "parts": {
170+ "inputs": {
171+ "nixpkgs-lib": [
172+ "nci",
173+ "nixpkgs"
174+ ]
175+ },
176+ "locked": {
177+ "lastModified": 1675933616,
178+ "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
179+ "owner": "hercules-ci",
180+ "repo": "flake-parts",
181+ "rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
182+ "type": "github"
183+ },
184+ "original": {
185+ "owner": "hercules-ci",
186+ "repo": "flake-parts",
187+ "type": "github"
188+ }
189+ },
190+ "parts_2": {
191+ "inputs": {
192+ "nixpkgs-lib": "nixpkgs-lib"
193+ },
194+ "locked": {
195+ "lastModified": 1675933616,
196+ "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
197+ "owner": "hercules-ci",
198+ "repo": "flake-parts",
199+ "rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
200+ "type": "github"
201+ },
202+ "original": {
203+ "owner": "hercules-ci",
204+ "repo": "flake-parts",
205+ "type": "github"
206+ }
207+ },
181208 "root": {
182209 "inputs": {
183210 "nci": "nci",
184211 "nixpkgs": "nixpkgs",
212+ "parts": "parts_2",
185213 "rust-overlay": "rust-overlay"
186214 }
187215 },
@@ -193,11 +221,11 @@
193221 ]
194222 },
195223 "locked": {
196− "lastModified": 1671416426,
197− "narHash": "sha256-kpSH1Jrxfk2qd0pRPJn1eQdIOseGv5JuE+YaOrqU9s4=",
224+ "lastModified": 1677292251,
225+ "narHash": "sha256-D+6q5Z2MQn3UFJtqsM5/AvVHi3NXKZTIMZt1JGq/spA=",
198226 "owner": "oxalica",
199227 "repo": "rust-overlay",
200− "rev": "fbaaff24f375ac25ec64268b0a0d63f91e474b7d",
228+ "rev": "34cdbf6ad480ce13a6a526f57d8b9e609f3d65dc",
201229 "type": "github"
202230 },
203231 "original": {
flake.nix+100−117
@@ -12,16 +12,10 @@
1212 inputs.nixpkgs.follows = "nixpkgs";
1313 inputs.rust-overlay.follows = "rust-overlay";
1414 };
15+ parts.url = "github:hercules-ci/flake-parts";
1516 };
1617
17− outputs = {
18− self,
19− nixpkgs,
20− nci,
21− ...
22− }: let
23− lib = nixpkgs.lib;
24− ncl = nci.lib.nci-lib;
18+ outputs = inp: let
2519 mkRootPath = rel:
2620 builtins.path {
2721 path = "${toString ./.}/${rel}";
@@ -32,6 +26,12 @@
3226 ".envrc"
3327 ".ignore"
3428 ".github"
29+ ".gitignore"
30+ "logo.svg"
31+ "logo_dark.svg"
32+ "logo_light.svg"
33+ "rust-toolchain.toml"
34+ "rustfmt.toml"
3535 "runtime"
3636 "screenshot.png"
3737 "book"
@@ -46,6 +46,7 @@
4646 "flake.lock"
4747 ];
4848 ignorePaths = path: type: let
49+ inherit (inp.nixpkgs) lib;
4950 # split the nix store path into its components
5051 components = lib.splitString "/" path;
5152 # drop off the `/nix/hash-source` section from the path
@@ -61,123 +62,105 @@
6162 # filter out unnecessary paths
6263 filter = ignorePaths;
6364 };
64− outputs = nci.lib.makeOutputs {
65− root = ./.;
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− ++ (lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.CoreFoundation);
87− env = [
88− {
89− name = "HELIX_RUNTIME";
90− eval = "$PWD/runtime";
91− }
92− {
93− name = "RUST_BACKTRACE";
94− value = "1";
95− }
65+ in
66+ inp.parts.lib.mkFlake {inputs = inp;} {
67+ imports = [inp.nci.flakeModule];
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
9692 {
97− name = "RUSTFLAGS";
98− eval =
99− if common.pkgs.stdenv.isLinux
100− then "$RUSTFLAGS\" -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment\""
101− else "$RUSTFLAGS";
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 [];
102102 }
103− ];
104− };
105− };
106− pkgConfig = common: {
107− helix-term = let
108− # Wrap helix with runtime
109− wrapper = _: old: let
110− inherit (common) pkgs;
111− makeOverridableHelix = old: config: let
112− grammars = pkgs.callPackage ./grammars.nix config;
113− runtimeDir = pkgs.runCommand "helix-runtime" {} ''
114− mkdir -p $out
115− ln -s ${mkRootPath "runtime"}/* $out
116− rm -r $out/grammars
117− ln -s ${grammars} $out/grammars
118− '';
119− helix-wrapped =
120− common.internal.pkgsSet.utils.wrapDerivation old
121− {
122− nativeBuildInputs = [pkgs.makeWrapper];
123− makeWrapperArgs = config.makeWrapperArgs or [];
124− }
125− ''
126− rm -rf $out/bin
127− mkdir -p $out/bin
128− ln -sf ${old}/bin/* $out/bin/
129− wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
130− '';
131− in
132− helix-wrapped
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
133113 // {
134− override = makeOverridableHelix old;
135− passthru = helix-wrapped.passthru // {wrapper = wrapper {};};
114+ wrapper = old: makeOverridableHelix old config;
136115 };
137− in
138− makeOverridableHelix old {};
139− in {
140− inherit wrapper;
141− overrides.fix-build.overrideAttrs = prev: {
142− src = filteredSource;
143−
144− # disable fetching and building of tree-sitter grammars in the helix-term build.rs
145− HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
146−
147− buildInputs = ncl.addBuildInputs prev [common.config.cCompiler.package.cc.lib];
148−
149− # link languages and theme toml files since helix-term expects them (for tests)
150− preConfigure = ''
151− ${prev.preConfigure or ""}
152− ${
153− lib.concatMapStringsSep
154− "\n"
155− (path: "ln -sf ${mkRootPath path} ..")
156− ["languages.toml" "theme.toml" "base16_theme.toml"]
157− }
158− '';
159− checkPhase = ":";
160−
161− meta.mainProgram = "hx";
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";
136+ };
137+ disable-tests = {checkPhase = ":";};
138+ set-stdenv.override = _: {inherit stdenv;};
139+ set-filtered-src.override = _: {src = filteredSource;};
162140 };
163141 };
142+
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;
148+
149+ devShells.default = config.nci.outputs."helix-project".devShell.overrideAttrs (old: {
150+ nativeBuildInputs =
151+ (old.nativeBuildInputs or [])
152+ ++ (with pkgs; [lld_13 cargo-flamegraph rust-analyzer])
153+ ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) pkgs.cargo-tarpaulin)
154+ ++ (lib.optional stdenv.isLinux pkgs.lldb)
155+ ++ (lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreFoundation);
156+ shellHook = ''
157+ export HELIX_RUNTIME="$PWD/runtime"
158+ export RUST_BACKTRACE="1"
159+ export RUSTFLAGS="${rustFlagsEnv}"
160+ '';
161+ });
164162 };
165163 };
166− in
167− outputs
168− // {
169− packages =
170− lib.mapAttrs
171− (
172− system: packages:
173− packages
174− // {
175− helix-unwrapped = packages.helix.passthru.unwrapped;
176− helix-unwrapped-dev = packages.helix-dev.passthru.unwrapped;
177− }
178− )
179− outputs.packages;
180− };
181164
182165 nixConfig = {
183166 extra-substituters = ["https://helix.cachix.org"];
helix-term/Cargo.toml−4
@@ -12,10 +12,6 @@ include = ["src/**/*", "README.md"]
1212default-run = "hx"
1313rust-version = "1.57"
1414
15−[package.metadata.nix]
16−build = true
17−app = true
18−
1915[features]
2016default = ["git"]
2117unicode-lines = ["helix-core/unicode-lines"]