on master help sign in
build(nix): update nci, refactor flake, seperate wrapping, add source filtering (#3657)
commite917a8e0be29aa3f8aaa537e0aa88e6df8ce974e authorYusuf Bera Ertan <y.bera003.06@protonmail.com> dateSat 3 Sep 2022, 01:54 (4 years ago) parent3c38fe9
3 files changed+177−140
.github/workflows/cachix.yml+1−1 flake.lock+31−35 flake.nix+145−104
.github/workflows/cachix.yml+1−1
@@ -23,4 +23,4 @@ jobs:
2323 authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
2424
2525 - name: Build nix flake
26− run: nix build
26+ run: nix build -L
flake.lock+31−35
@@ -3,11 +3,11 @@
33 "crane": {
44 "flake": false,
55 "locked": {
6− "lastModified": 1654444508,
7− "narHash": "sha256-4OBvQ4V7jyt7afs6iKUvRzJ1u/9eYnKzVQbeQdiamuY=",
6+ "lastModified": 1661875961,
7+ "narHash": "sha256-f1h/2c6Teeu1ofAHWzrS8TwBPcnN+EEu+z1sRVmMQTk=",
88 "owner": "ipetkov",
99 "repo": "crane",
10− "rev": "db5482bf225acc3160899124a1df5a617cfa27b5",
10+ "rev": "d9f394e4e20e97c2a60c3ad82c2b6ef99be19e24",
1111 "type": "github"
1212 },
1313 "original": {
@@ -19,11 +19,11 @@
1919 "devshell": {
2020 "flake": false,
2121 "locked": {
22− "lastModified": 1655976588,
23− "narHash": "sha256-VreHyH6ITkf/1EX/8h15UqhddJnUleb0HgbC3gMkAEQ=",
22+ "lastModified": 1660811669,
23+ "narHash": "sha256-V6lmsaLNFz41myppL0yxglta92ijkSvpZ+XVygAh+bU=",
2424 "owner": "numtide",
2525 "repo": "devshell",
26− "rev": "899ca4629020592a13a46783587f6e674179d1db",
26+ "rev": "c2feacb46ee69949124c835419861143c4016fb5",
2727 "type": "github"
2828 },
2929 "original": {
@@ -35,49 +35,45 @@
3535 "dream2nix": {
3636 "inputs": {
3737 "alejandra": [
38− "nixCargoIntegration",
38+ "nci",
3939 "nixpkgs"
4040 ],
4141 "crane": "crane",
4242 "devshell": [
43− "nixCargoIntegration",
43+ "nci",
4444 "devshell"
4545 ],
4646 "flake-utils-pre-commit": [
47− "nixCargoIntegration",
47+ "nci",
4848 "nixpkgs"
4949 ],
5050 "gomod2nix": [
51− "nixCargoIntegration",
51+ "nci",
5252 "nixpkgs"
5353 ],
5454 "mach-nix": [
55− "nixCargoIntegration",
55+ "nci",
5656 "nixpkgs"
5757 ],
5858 "nixpkgs": [
59− "nixCargoIntegration",
60− "nixpkgs"
61− ],
62− "node2nix": [
63− "nixCargoIntegration",
59+ "nci",
6460 "nixpkgs"
6561 ],
6662 "poetry2nix": [
67− "nixCargoIntegration",
63+ "nci",
6864 "nixpkgs"
6965 ],
7066 "pre-commit-hooks": [
71− "nixCargoIntegration",
67+ "nci",
7268 "nixpkgs"
7369 ]
7470 },
7571 "locked": {
76− "lastModified": 1655975833,
77− "narHash": "sha256-g8sdfuglIZ24oWVbntVzniNTJW+Z3n9DNL9w9Tt+UCE=",
72+ "lastModified": 1662083074,
73+ "narHash": "sha256-GL4/CLKPYUzkKD1l7oi2XB+vi3z4xGpCVLDdG3tRqvs=",
7874 "owner": "nix-community",
7975 "repo": "dream2nix",
80− "rev": "4e75e665ec3a1cddae5266bed0dd72fce0b74a23",
76+ "rev": "c6c039fcc6abdf4d828b940b576944a224cf8622",
8177 "type": "github"
8278 },
8379 "original": {
@@ -88,11 +84,11 @@
8884 },
8985 "flake-utils": {
9086 "locked": {
91− "lastModified": 1637014545,
92− "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
87+ "lastModified": 1656928814,
88+ "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
9389 "owner": "numtide",
9490 "repo": "flake-utils",
95− "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
91+ "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
9692 "type": "github"
9793 },
9894 "original": {
@@ -101,7 +97,7 @@
10197 "type": "github"
10298 }
10399 },
104− "nixCargoIntegration": {
100+ "nci": {
105101 "inputs": {
106102 "devshell": "devshell",
107103 "dream2nix": "dream2nix",
@@ -113,11 +109,11 @@
113109 ]
114110 },
115111 "locked": {
116− "lastModified": 1656453541,
117− "narHash": "sha256-ZCPVnS6zJOZJvIlwU3rKR8MBVm6A3F4/0mA7G1lQ3D0=",
112+ "lastModified": 1662143940,
113+ "narHash": "sha256-3eJfehnZLWJGXylfpAMeLR0Q3sx8pAjGiHBQPqOH9+U=",
118114 "owner": "yusdacra",
119115 "repo": "nix-cargo-integration",
120− "rev": "9eb74345b30cd2e536d9dac9d4435d3c475605c7",
116+ "rev": "e83f2598aecbe1114783ff9bdae0b85939de35a3",
121117 "type": "github"
122118 },
123119 "original": {
@@ -128,11 +124,11 @@
128124 },
129125 "nixpkgs": {
130126 "locked": {
131− "lastModified": 1655624069,
132− "narHash": "sha256-7g1zwTdp35GMTERnSzZMWJ7PG3QdDE8VOX3WsnOkAtM=",
127+ "lastModified": 1662019588,
128+ "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=",
133129 "owner": "nixos",
134130 "repo": "nixpkgs",
135− "rev": "0d68d7c857fe301d49cdcd56130e0beea4ecd5aa",
131+ "rev": "2da64a81275b68fdad38af669afeda43d401e94b",
136132 "type": "github"
137133 },
138134 "original": {
@@ -144,7 +140,7 @@
144140 },
145141 "root": {
146142 "inputs": {
147− "nixCargoIntegration": "nixCargoIntegration",
143+ "nci": "nci",
148144 "nixpkgs": "nixpkgs",
149145 "rust-overlay": "rust-overlay"
150146 }
@@ -157,11 +153,11 @@
157153 ]
158154 },
159155 "locked": {
160− "lastModified": 1655779671,
161− "narHash": "sha256-6feeiGa6fb7ZPVHR71uswkmN1701TAJpwYQA8QffmRk=",
156+ "lastModified": 1662087605,
157+ "narHash": "sha256-Gpf2gp2JenKGf+TylX/YJpttY2bzsnvAMLdLaxoZRyU=",
162158 "owner": "oxalica",
163159 "repo": "rust-overlay",
164− "rev": "8159585609a772b041cce6019d5c21d240709244",
160+ "rev": "60c2cfaa8b90ed8cebd18b214fac8682dcf222dd",
165161 "type": "github"
166162 },
167163 "original": {
flake.nix+145−104
@@ -7,128 +7,169 @@
77 url = "github:oxalica/rust-overlay";
88 inputs.nixpkgs.follows = "nixpkgs";
99 };
10− nixCargoIntegration = {
10+ nci = {
1111 url = "github:yusdacra/nix-cargo-integration";
1212 inputs.nixpkgs.follows = "nixpkgs";
1313 inputs.rust-overlay.follows = "rust-overlay";
1414 };
1515 };
1616
17− outputs = inputs @ {
17+ outputs = {
18+ self,
1819 nixpkgs,
19− nixCargoIntegration,
20+ nci,
2021 ...
2122 }: let
22− outputs = config:
23− nixCargoIntegration.lib.makeOutputs {
24− root = ./.;
25− renameOutputs = {"helix-term" = "helix";};
26− # Set default app to hx (binary is from helix-term release build)
27− # Set default package to helix-term release build
28− defaultOutputs = {
29− app = "hx";
30− package = "helix";
31− };
32− overrides = {
33− cCompiler = common:
34− with common.pkgs;
35− if stdenv.isLinux
36− then gcc
37− else clang;
38− crateOverrides = common: _: {
39− helix-term = prev: let
40− inherit (common) pkgs;
41− mkRootPath = rel:
42− builtins.path {
43− path = "${common.root}/${rel}";
44− name = rel;
45− };
46− grammars = pkgs.callPackage ./grammars.nix config;
47− runtimeDir = pkgs.runCommandNoCC "helix-runtime" {} ''
48− mkdir -p $out
49− ln -s ${mkRootPath "runtime"}/* $out
50− rm -r $out/grammars
51− ln -s ${grammars} $out/grammars
52− '';
53− overridedAttrs = {
54− # disable fetching and building of tree-sitter grammars in the helix-term build.rs
55− HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
56− # link languages and theme toml files since helix-term expects them (for tests)
57− preConfigure =
58− pkgs.lib.concatMapStringsSep
59− "\n"
60− (path: "ln -sf ${mkRootPath path} ..")
61− ["languages.toml" "theme.toml" "base16_theme.toml"];
62− buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
63− nativeBuildInputs = [pkgs.makeWrapper];
23+ lib = nixpkgs.lib;
24+ mkRootPath = rel:
25+ builtins.path {
26+ path = "${toString ./.}/${rel}";
27+ name = rel;
28+ };
29+ outputs = nci.lib.makeOutputs {
30+ root = ./.;
31+ renameOutputs = {"helix-term" = "helix";};
32+ # Set default app to hx (binary is from helix-term release build)
33+ # Set default package to helix-term release build
34+ defaultOutputs = {
35+ app = "hx";
36+ package = "helix";
37+ };
38+ overrides = {
39+ cCompiler = common:
40+ with common.pkgs;
41+ if stdenv.isLinux
42+ then gcc
43+ else clang;
44+ crateOverrides = common: _: {
45+ helix-term = prev: {
46+ src = builtins.path {
47+ name = "helix-source";
48+ path = toString ./.;
49+ # filter out unneeded stuff that cause rebuilds
50+ filter = path: type:
51+ lib.all
52+ (n: builtins.baseNameOf path != n)
53+ [
54+ ".envrc"
55+ ".ignore"
56+ ".github"
57+ "runtime"
58+ "screenshot.png"
59+ "book"
60+ "contrib"
61+ "docs"
62+ "README.md"
63+ "shell.nix"
64+ "default.nix"
65+ "grammars.nix"
66+ "flake.nix"
67+ "flake.lock"
68+ ];
69+ };
6470
65− postFixup = ''
66− if [ -f "$out/bin/hx" ]; then
67− wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
68− fi
69− '';
70− };
71− in
72− overridedAttrs
73− // (
74− pkgs.lib.optionalAttrs
75− (config ? makeWrapperArgs)
76− {inherit (config) makeWrapperArgs;}
77− );
78− };
79− shell = common: prev: {
80− packages =
81− prev.packages
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− ];
71+ # disable fetching and building of tree-sitter grammars in the helix-term build.rs
72+ HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
73+
74+ buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
75+
76+ # link languages and theme toml files since helix-term expects them (for tests)
77+ preConfigure = ''
78+ ${prev.preConfigure or ""}
79+ ${
80+ lib.concatMapStringsSep
81+ "\n"
82+ (path: "ln -sf ${mkRootPath path} ..")
83+ ["languages.toml" "theme.toml" "base16_theme.toml"]
84+ }
85+ '';
86+
87+ meta.mainProgram = "hx";
10688 };
10789 };
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+ };
108118 };
109− defaultOutputs = outputs {};
110− makeOverridableHelix = system: old:
111− old
112− // {
113− override = args:
114− makeOverridableHelix
115− system
116− (outputs args).packages.${system}.helix;
117− };
119+ };
120+ makeOverridableHelix = system: old: config: let
121+ pkgs = nixpkgs.legacyPackages.${system};
122+ grammars = pkgs.callPackage ./grammars.nix config;
123+ runtimeDir = pkgs.runCommand "helix-runtime" {} ''
124+ mkdir -p $out
125+ ln -s ${mkRootPath "runtime"}/* $out
126+ rm -r $out/grammars
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;};
118146 in
119− defaultOutputs
147+ outputs
120148 // {
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;
121161 packages =
122− nixpkgs.lib.mapAttrs
162+ lib.mapAttrs
123163 (
124− system: packages:
125− packages
126− // rec {
127− default = helix;
128− helix = makeOverridableHelix system packages.helix;
129− }
164+ system: packages: rec {
165+ default = 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;
170+ }
130171 )
131− defaultOutputs.packages;
172+ outputs.packages;
132173 };
133174
134175 nixConfig = {