on master help sign in
build(nix): use nix-cargo-integration, make shell.nix use flake devshell
commita3f01503e28ee3bcbfd14e9753a1c135bbba49e7 authorYusuf Bera Ertan <y.bera003.06@protonmail.com> dateSun 13 Jun 2021, 08:03 (5 years ago) parent9640ed1
5 files changed+99−137
.envrc+4−1 flake.lock+45−72 flake.nix+41−41 helix-term/Cargo.toml+3−1 shell.nix+6−22
.envrc+4−1
@@ -1,2 +1,5 @@
11watch_file shell.nix
2−use flake
2+watch_file flake.lock
3+
4+# try to use flakes, if it fails use normal nix (ie. shell.nix)
5+use flake || use nix
flake.lock+45−72
@@ -1,91 +1,83 @@
11{
22 "nodes": {
3− "flake-utils": {
3+ "devshell": {
44 "locked": {
5− "lastModified": 1620759905,
6− "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=",
5+ "lastModified": 1622711433,
6+ "narHash": "sha256-rGjXz7FA7HImAT3TtoqwecByLO5yhVPSwPdaYPBFRQw=",
77 "owner": "numtide",
8− "repo": "flake-utils",
9− "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8",
8+ "repo": "devshell",
9+ "rev": "1f4fb67b662b65fa7cfe696fc003fcc1e8f7cc36",
1010 "type": "github"
1111 },
1212 "original": {
1313 "owner": "numtide",
14− "repo": "flake-utils",
14+ "repo": "devshell",
1515 "type": "github"
1616 }
1717 },
18− "flake-utils_2": {
18+ "flakeCompat": {
19+ "flake": false,
1920 "locked": {
20− "lastModified": 1614513358,
21− "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
22− "owner": "numtide",
23− "repo": "flake-utils",
24− "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
21+ "lastModified": 1606424373,
22+ "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=",
23+ "owner": "edolstra",
24+ "repo": "flake-compat",
25+ "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf",
2526 "type": "github"
2627 },
2728 "original": {
28− "owner": "numtide",
29− "repo": "flake-utils",
29+ "owner": "edolstra",
30+ "repo": "flake-compat",
3031 "type": "github"
3132 }
3233 },
3334 "helix": {
3435 "flake": false,
3536 "locked": {
36− "lastModified": 1623200791,
37− "narHash": "sha256-kZKThNh1dBSCnISk9vwbqctk1+U0s8Lzasz/CVytJps=",
37+ "lastModified": 1623545930,
38+ "narHash": "sha256-14ASoYbxXHU/qPGctiUymb4fMRCoih9c7YujjxqEkdU=",
3839 "ref": "master",
39− "rev": "b20e4a108cd890afa6cdf83656856fc2157a8e84",
40− "revCount": 789,
40+ "rev": "9640ed1425f2db904fb42cd0c54dc6fbc05ca292",
41+ "revCount": 821,
4142 "submodules": true,
4243 "type": "git",
43− "url": "https://github.com/helix-editor/helix"
44+ "url": "https://github.com/helix-editor/helix.git"
4445 },
4546 "original": {
4647 "submodules": true,
4748 "type": "git",
48− "url": "https://github.com/helix-editor/helix"
49+ "url": "https://github.com/helix-editor/helix.git"
4950 }
5051 },
51− "naersk": {
52+ "nixCargoIntegration": {
5253 "inputs": {
53− "nixpkgs": "nixpkgs"
54+ "devshell": "devshell",
55+ "nixpkgs": [
56+ "nixpkgs"
57+ ],
58+ "rustOverlay": "rustOverlay"
5459 },
5560 "locked": {
56− "lastModified": 1620316130,
57− "narHash": "sha256-sU0VS5oJS1FsHsZsLELAXc7G2eIelVuucRw+q5B1x9k=",
58− "owner": "nmattia",
59− "repo": "naersk",
60− "rev": "a3f40fe42cc6d267ff7518fa3199e99ff1444ac4",
61+ "lastModified": 1623560601,
62+ "narHash": "sha256-H1Dq461b2m8v/FxmPphd8pOAx4pPja0UE/xvcMUYwwY=",
63+ "owner": "yusdacra",
64+ "repo": "nix-cargo-integration",
65+ "rev": "1238fd751e5d6eb030aee244da9fee6c3ad8b316",
6166 "type": "github"
6267 },
6368 "original": {
64− "owner": "nmattia",
65− "repo": "naersk",
69+ "owner": "yusdacra",
70+ "repo": "nix-cargo-integration",
6671 "type": "github"
6772 }
6873 },
6974 "nixpkgs": {
7075 "locked": {
71− "lastModified": 1622059058,
72− "narHash": "sha256-t1/ZMtyxClVSfcV4Pt5C1YpkeJ/UwFF3oitLD7Ch/UA=",
73− "path": "/nix/store/2gam4i1fa1v19k3n5rc9vgvqac1c2xj5-source",
74− "rev": "84aa23742f6c72501f9cc209f29c438766f5352d",
75− "type": "path"
76− },
77− "original": {
78− "id": "nixpkgs",
79− "type": "indirect"
80− }
81− },
82− "nixpkgs_2": {
83− "locked": {
84− "lastModified": 1622194753,
85− "narHash": "sha256-76qtvFp/vFEz46lz5iZMJ0mnsWQYmuGYlb0fHgKqqMg=",
76+ "lastModified": 1623324058,
77+ "narHash": "sha256-Jm9GUTXdjXz56gWDKy++EpFfjrBaxqXlLvTLfgEi8lo=",
8678 "owner": "nixos",
8779 "repo": "nixpkgs",
88− "rev": "540dccb2aeaffa9dc69bfdc41c55abd7ccc6baa3",
80+ "rev": "432fc2d9a67f92e05438dff5fdc2b39d33f77997",
8981 "type": "github"
9082 },
9183 "original": {
@@ -95,41 +87,22 @@
9587 "type": "github"
9688 }
9789 },
98− "nixpkgs_3": {
99− "locked": {
100− "lastModified": 1617325113,
101− "narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=",
102− "owner": "nixos",
103− "repo": "nixpkgs",
104− "rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb",
105− "type": "github"
106− },
107− "original": {
108− "owner": "NixOS",
109− "repo": "nixpkgs",
110− "type": "github"
111− }
112− },
11390 "root": {
11491 "inputs": {
115− "flake-utils": "flake-utils",
92+ "flakeCompat": "flakeCompat",
11693 "helix": "helix",
117− "naersk": "naersk",
118− "nixpkgs": "nixpkgs_2",
119− "rust-overlay": "rust-overlay"
94+ "nixCargoIntegration": "nixCargoIntegration",
95+ "nixpkgs": "nixpkgs"
12096 }
12197 },
122− "rust-overlay": {
123− "inputs": {
124− "flake-utils": "flake-utils_2",
125− "nixpkgs": "nixpkgs_3"
126− },
98+ "rustOverlay": {
99+ "flake": false,
127100 "locked": {
128− "lastModified": 1622257069,
129− "narHash": "sha256-+QVnS/es9JCRZXphoHL0fOIUhpGqB4/wreBsXWArVck=",
101+ "lastModified": 1623550815,
102+ "narHash": "sha256-RumRrkE6OTJDndHV4qZNZv8kUGnzwRHZQSyzx29r6/g=",
130103 "owner": "oxalica",
131104 "repo": "rust-overlay",
132− "rev": "8aa5f93c0b665e5357af19c5631a3450bff4aba5",
105+ "rev": "9824f142cbd7bc3e2a92eefbb79addfff8704cd3",
133106 "type": "github"
134107 },
135108 "original": {
flake.nix+41−41
@@ -3,54 +3,54 @@
33
44 inputs = {
55 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6− flake-utils.url = "github:numtide/flake-utils";
7− rust-overlay.url = "github:oxalica/rust-overlay";
8− naersk.url = "github:nmattia/naersk";
9− helix = {
6+ nixCargoIntegration = {
7+ url = "github:yusdacra/nix-cargo-integration";
8+ inputs.nixpkgs.follows = "nixpkgs";
9+ };
10+ flakeCompat = {
11+ url = "github:edolstra/flake-compat";
1012 flake = false;
11− url = "https://github.com/helix-editor/helix";
13+ };
14+ helix = {
15+ url = "https://github.com/helix-editor/helix.git";
1216 type = "git";
17+ flake = false;
1318 submodules = true;
1419 };
1520 };
1621
17− outputs = inputs@{ self, nixpkgs, naersk, rust-overlay, flake-utils, ... }:
18− let
19− rust = pkgs:
20− (pkgs.rustChannelOf {
21− date = "2021-05-01";
22− channel = "nightly";
23− }).minimal; # cargo, rustc and rust-std
24−
25− mkNaerskLib = system: pkgs:
26− naersk.lib."${system}".override {
27− # naersk can't build with stable?!
28− # inherit (pkgs.rust-bin.stable.latest) rustc cargo;
29− rustc = rust pkgs;
30− cargo = rust pkgs;
22+ outputs = inputs@{ nixCargoIntegration, helix, ... }:
23+ nixCargoIntegration.lib.makeOutputs {
24+ root = ./.;
25+ buildPlatform = "crate2nix";
26+ renameOutputs = { "helix-term" = "helix"; };
27+ # Set default app to hx (binary is from helix-term release build)
28+ # Set default package to helix-term release build
29+ defaultOutputs = { app = "hx"; package = "helix"; };
30+ overrides = {
31+ crateOverrides = common: _: {
32+ helix-term = prev: { buildInputs = (prev.buildInputs or [ ]) ++ [ common.cCompiler.cc.lib ]; };
33+ # link runtime since helix-core expects it because of embed_runtime feature
34+ helix-core = _: { preConfigure = "ln -s ${common.root + "/runtime"} ../runtime"; };
35+ # link languages and theme toml files since helix-view expects them
36+ helix-view = _: { preConfigure = "ln -s ${common.root}/{languages.toml,theme.toml} .."; };
37+ helix-syntax = prev: {
38+ src = common.pkgs.runCommand prev.src.name { } ''
39+ mkdir -p $out
40+ ln -s ${prev.src}/* $out
41+ ln -sf ${helix}/helix-syntax/languages $out
42+ '';
43+ };
3144 };
32−
33− pkg = naerskLib:
34− naerskLib.buildPackage {
35− pname = "helix";
36− root = inputs.helix;
37− cargoBuildOptions = self: self ++ [ ''--features "embed_runtime"'' ];
45+ shell = common: prev: {
46+ packages = prev.packages ++ (with common.pkgs; [ lld_10 lldb ]);
47+ env = prev.env ++ [
48+ { name = "HELIX_RUNTIME"; eval = "$PWD/runtime"; }
49+ { name = "RUST_BACKTRACE"; value = "1"; }
50+ { name = "RUSTFLAGS"; value = "-C link-arg=-fuse-ld=lld -C target-cpu=native"; }
51+ ];
3852 };
39−
40− in flake-utils.lib.eachDefaultSystem (system:
41− let
42− pkgs = import nixpkgs {
43− inherit system;
44− overlays = [ rust-overlay.overlay ];
45− };
46− naerskLib = mkNaerskLib system pkgs;
47− in rec {
48− packages.helix = pkg naerskLib;
49− defaultPackage = packages.helix;
50− devShell = pkgs.callPackage ./shell.nix { };
51− }) // {
52− overlay = final: prev:
53− let naerskLib = mkNaerskLib prev.system final;
54− in (rust-overlay.overlay final prev) // { helix = pkg naerskLib; };
53+ build = _: prev: { rootFeatures = prev.rootFeatures ++ [ "embed_runtime" ]; };
5554 };
55+ };
5656}
helix-term/Cargo.toml+3−1
@@ -6,7 +6,9 @@ authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
66edition = "2018"
77license = "MPL-2.0"
88
9−# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+[package.metadata.nix]
10+build = true
11+app = true
1012
1113[features]
1214embed_runtime = ["helix-core/embed_runtime"]
shell.nix+6−22
@@ -1,22 +1,6 @@
1−{ lib, stdenv, pkgs }:
2−
3−pkgs.mkShell {
4− nativeBuildInputs = with pkgs; [
5− (rust-bin.stable.latest.default.override { extensions = ["rust-src"]; })
6− lld_10
7− lldb
8− # pythonPackages.six
9− stdenv.cc.cc.lib
10− # pkg-config
11− ];
12− RUSTFLAGS = "-C link-arg=-fuse-ld=lld -C target-cpu=native";
13− RUST_BACKTRACE = "1";
14− # https://github.com/rust-lang/rust/issues/55979
15− LD_LIBRARY_PATH = lib.makeLibraryPath (with pkgs; [
16− stdenv.cc.cc.lib
17− ]);
18−
19− shellHook = ''
20− export HELIX_RUNTIME=$PWD/runtime
21− '';
22−}
1+# Flake's devShell for non-flake-enabled nix instances
2+let
3+ src = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flakeCompat.locked;
4+ compat = fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${src.rev}.tar.gz"; sha256 = src.narHash; };
5+in
6+(import compat { src = ./.; }).shellNix.default