aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: cbbc315687f0aba9c590f17dd1dfb365e466a385 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
  description = "A post-modern text editor.";

  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 = {
      flake = false;
      url = "https://github.com/helix-editor/helix";
      type = "git";
      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;
        };

      pkg = naerskLib:
        naerskLib.buildPackage {
          pname = "helix";
          root = inputs.helix;
        };

    in flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ rust-overlay.overlay ];
        };
        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; };
      };
}