diff --git a/.envrc b/.envrc index 29da48d46d02f..00cc6f20e1c84 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,5 @@ watch_file shell.nix -use flake +watch_file flake.lock + +# try to use flakes, if it fails use normal nix (ie. shell.nix) +use flake || use nix diff --git a/flake.lock b/flake.lock index 9b83910a15266..71b0d6a589a41 100644 --- a/flake.lock +++ b/flake.lock @@ -1,27 +1,43 @@ { "nodes": { - "flake-utils": { + "devshell": { "locked": { - "lastModified": 1620759905, - "narHash": "sha256-WiyWawrgmyN0EdmiHyG2V+fqReiVi8bM9cRdMaKQOFg=", + "lastModified": 1622711433, + "narHash": "sha256-rGjXz7FA7HImAT3TtoqwecByLO5yhVPSwPdaYPBFRQw=", "owner": "numtide", - "repo": "flake-utils", - "rev": "b543720b25df6ffdfcf9227afafc5b8c1fabfae8", + "repo": "devshell", + "rev": "1f4fb67b662b65fa7cfe696fc003fcc1e8f7cc36", "type": "github" }, "original": { "owner": "numtide", - "repo": "flake-utils", + "repo": "devshell", "type": "github" } }, - "flake-utils_2": { + "flakeCompat": { + "flake": false, "locked": { - "lastModified": 1614513358, - "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flakeUtils": { + "locked": { + "lastModified": 1622445595, + "narHash": "sha256-m+JRe6Wc5OZ/mKw2bB3+Tl0ZbtyxxxfnAWln8Q5qs+Y=", "owner": "numtide", "repo": "flake-utils", - "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", + "rev": "7d706970d94bc5559077eb1a6600afddcd25a7c8", "type": "github" }, "original": { @@ -33,59 +49,51 @@ "helix": { "flake": false, "locked": { - "lastModified": 1623200791, - "narHash": "sha256-kZKThNh1dBSCnISk9vwbqctk1+U0s8Lzasz/CVytJps=", + "lastModified": 1623416773, + "narHash": "sha256-4tyLChESv6M4odMBtw9QUf8mBodQvuiMedUrtBuu8iE=", "ref": "master", - "rev": "b20e4a108cd890afa6cdf83656856fc2157a8e84", - "revCount": 789, + "rev": "69fe46a122f728b4bb6cb218fd410544097b0dcd", + "revCount": 809, "submodules": true, "type": "git", - "url": "https://github.com/helix-editor/helix" + "url": "https://github.com/helix-editor/helix.git" }, "original": { "submodules": true, "type": "git", - "url": "https://github.com/helix-editor/helix" + "url": "https://github.com/helix-editor/helix.git" } }, - "naersk": { + "nixCargoIntegration": { "inputs": { - "nixpkgs": "nixpkgs" + "devshell": "devshell", + "flakeUtils": "flakeUtils", + "nixpkgs": [ + "nixpkgs" + ], + "rustOverlay": "rustOverlay" }, "locked": { - "lastModified": 1620316130, - "narHash": "sha256-sU0VS5oJS1FsHsZsLELAXc7G2eIelVuucRw+q5B1x9k=", - "owner": "nmattia", - "repo": "naersk", - "rev": "a3f40fe42cc6d267ff7518fa3199e99ff1444ac4", + "lastModified": 1623433292, + "narHash": "sha256-G9D7XNkjmPzx+wsiBwCodC3xiX1MjkDjP8VX+XJJuC8=", + "owner": "yusdacra", + "repo": "nix-cargo-integration", + "rev": "63360d6753f29f5c6ba26d056e411154f60329c0", "type": "github" }, "original": { - "owner": "nmattia", - "repo": "naersk", + "owner": "yusdacra", + "repo": "nix-cargo-integration", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1622059058, - "narHash": "sha256-t1/ZMtyxClVSfcV4Pt5C1YpkeJ/UwFF3oitLD7Ch/UA=", - "path": "/nix/store/2gam4i1fa1v19k3n5rc9vgvqac1c2xj5-source", - "rev": "84aa23742f6c72501f9cc209f29c438766f5352d", - "type": "path" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1622194753, - "narHash": "sha256-76qtvFp/vFEz46lz5iZMJ0mnsWQYmuGYlb0fHgKqqMg=", + "lastModified": 1622966049, + "narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "540dccb2aeaffa9dc69bfdc41c55abd7ccc6baa3", + "rev": "fbfb79400a08bf754e32b4d4fc3f7d8f8055cf94", "type": "github" }, "original": { @@ -95,41 +103,22 @@ "type": "github" } }, - "nixpkgs_3": { - "locked": { - "lastModified": 1617325113, - "narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "type": "github" - } - }, "root": { "inputs": { - "flake-utils": "flake-utils", + "flakeCompat": "flakeCompat", "helix": "helix", - "naersk": "naersk", - "nixpkgs": "nixpkgs_2", - "rust-overlay": "rust-overlay" + "nixCargoIntegration": "nixCargoIntegration", + "nixpkgs": "nixpkgs" } }, - "rust-overlay": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_3" - }, + "rustOverlay": { + "flake": false, "locked": { - "lastModified": 1622257069, - "narHash": "sha256-+QVnS/es9JCRZXphoHL0fOIUhpGqB4/wreBsXWArVck=", + "lastModified": 1623378256, + "narHash": "sha256-nlSwmn7ywh02EOkr+pnrq3yiD/Wq1GjAirEuHQLqbss=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "8aa5f93c0b665e5357af19c5631a3450bff4aba5", + "rev": "45fbdefb8cdd5f4e8e28e27ae1f2a90241e66529", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 82ee5073503d9..117d37aaaad4f 100644 --- a/flake.nix +++ b/flake.nix @@ -3,54 +3,57 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - rust-overlay.url = "github:oxalica/rust-overlay"; - naersk.url = "github:nmattia/naersk"; - helix = { + nixCargoIntegration = { + url = "github:yusdacra/nix-cargo-integration"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flakeCompat = { + url = "github:edolstra/flake-compat"; flake = false; - url = "https://github.com/helix-editor/helix"; + }; + helix = { + url = "https://github.com/helix-editor/helix.git"; type = "git"; + flake = false; submodules = true; }; }; - outputs = inputs@{ self, nixpkgs, naersk, rust-overlay, flake-utils, ... }: - let - rust = pkgs: - (pkgs.rustChannelOf { - date = "2021-05-01"; - channel = "nightly"; - }).minimal; # cargo, rustc and rust-std - - mkNaerskLib = system: pkgs: - naersk.lib."${system}".override { - # naersk can't build with stable?! - # inherit (pkgs.rust-bin.stable.latest) rustc cargo; - rustc = rust pkgs; - cargo = rust pkgs; + outputs = inputs@{ nixCargoIntegration, helix, ... }: + nixCargoIntegration.lib.makeOutputs { + root = ./.; + buildPlatform = "crate2nix"; + renameOutputs = { "helix-term" = "helix"; }; + defaultOutputs = { + app = "hx"; # Set default app to hx (binary is from helix-term release build) + package = "helix"; # Set default package to helix-term release build + }; + overrides = { + root = _: _: helix; + crateOverrides = common: _: { + helix-term = prev: { + buildInputs = (prev.buildInputs or [ ]) ++ [ common.cCompiler.cc.lib ]; + }; + helix-core = prev: { + # link runtime since helix-core expects it because of embed_runtime feature + preConfigure = "ln -s ${common.root + "/runtime"} ../runtime"; + }; + helix-view = prev: { + # link languages and theme toml files since helix-view expects them + preConfigure = "ln -s ${common.root}/{languages.toml,theme.toml} .."; + }; }; - - pkg = naerskLib: - naerskLib.buildPackage { - pname = "helix"; - root = inputs.helix; - cargoBuildOptions = self: self ++ [ ''--features "embed_runtime"'' ]; + shell = common: prev: { + packages = prev.packages ++ (with common.pkgs; [ lld_10 lldb ]); + env = prev.env ++ [ + { name = "HELIX_RUNTIME"; eval = "$PWD/runtime"; } + { name = "RUST_BACKTRACE"; value = "1"; } + { name = "RUSTFLAGS"; value = "-C link-arg=-fuse-ld=lld -C target-cpu=native"; } + ]; }; - - in flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlay ]; + build = _: prev: { + rootFeatures = prev.rootFeatures ++ [ "embed_runtime" ]; }; - naerskLib = mkNaerskLib system pkgs; - in rec { - packages.helix = pkg naerskLib; - defaultPackage = packages.helix; - devShell = pkgs.callPackage ./shell.nix { }; - }) // { - overlay = final: prev: - let naerskLib = mkNaerskLib prev.system final; - in (rust-overlay.overlay final prev) // { helix = pkg naerskLib; }; }; + }; } diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 75edd723169d0..13fa23bfc9aee 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -6,7 +6,9 @@ authors = ["Blaž Hrastnik "] edition = "2018" license = "MPL-2.0" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[package.metadata.nix] +build = true +app = true [features] embed_runtime = ["helix-core/embed_runtime"] diff --git a/shell.nix b/shell.nix index d6cb543ac8ee7..5c5a774e78d03 100644 --- a/shell.nix +++ b/shell.nix @@ -1,22 +1,6 @@ -{ lib, stdenv, pkgs }: - -pkgs.mkShell { - nativeBuildInputs = with pkgs; [ - (rust-bin.stable.latest.default.override { extensions = ["rust-src"]; }) - lld_10 - lldb - # pythonPackages.six - stdenv.cc.cc.lib - # pkg-config - ]; - RUSTFLAGS = "-C link-arg=-fuse-ld=lld -C target-cpu=native"; - RUST_BACKTRACE = "1"; - # https://github.com/rust-lang/rust/issues/55979 - LD_LIBRARY_PATH = lib.makeLibraryPath (with pkgs; [ - stdenv.cc.cc.lib - ]); - - shellHook = '' - export HELIX_RUNTIME=$PWD/runtime - ''; -} +# Flake's devShell for non-flake-enabled nix instances +let + src = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flakeCompat.locked; + compat = fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${src.rev}.tar.gz"; sha256 = src.narHash; }; +in +(import compat { src = ./.; }).shellNix.default