A post-modern development environment.
1{
2 description = "A post-modern text editor.";
3
4 inputs = {
5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6 rust-overlay = {
7 url = "github:oxalica/rust-overlay";
8 inputs.nixpkgs.follows = "nixpkgs";
9 };
10 };
11
12 outputs = {
13 self,
14 nixpkgs,
15 rust-overlay,
16 ...
17 }: let
18 inherit (nixpkgs) lib;
19 eachSystem = lib.genAttrs lib.systems.flakeExposed;
20 pkgsFor = eachSystem (system:
21 import nixpkgs {
22 localSystem.system = system;
23 overlays = [(import rust-overlay) self.overlays.helix];
24 });
25 gitRev = self.rev or self.dirtyRev or null;
26 in {
27 packages = eachSystem (system: {
28 inherit (pkgsFor.${system}) helix;
29 /*
30 The default Helix build. Uses the latest stable Rust toolchain, and unstable
31 nixpkgs.
32
33 The build inputs can be overridden with the following:
34
35 packages.${system}.default.override { rustPlatform = newPlatform; };
36
37 Overriding a derivation attribute can be done as well:
38
39 packages.${system}.default.overrideAttrs { buildType = "debug"; };
40 */
41 default = self.packages.${system}.helix;
42 });
43 checks =
44 lib.mapAttrs (system: pkgs: let
45 # Get Helix's MSRV toolchain to build with by default.
46 msrvToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
47 msrvPlatform = pkgs.makeRustPlatform {
48 cargo = msrvToolchain;
49 rustc = msrvToolchain;
50 };
51 in {
52 helix = self.packages.${system}.helix.override {
53 rustPlatform = msrvPlatform;
54 };
55 })
56 pkgsFor;
57
58 # Devshell behavior is preserved.
59 devShells =
60 lib.mapAttrs (system: pkgs: {
61 default = let
62 commonRustFlagsEnv = "-C link-arg=-fuse-ld=lld -C target-cpu=native --cfg tokio_unstable";
63 platformRustFlagsEnv = lib.optionalString pkgs.stdenv.isLinux "-Clink-arg=-Wl,--no-rosegment";
64 in
65 pkgs.mkShell {
66 inputsFrom = [
67 (self.checks.${system}.helix.override {
68 includeGrammarIf = _: false;
69 })
70 ];
71 nativeBuildInputs = with pkgs;
72 [
73 lld
74 cargo-flamegraph
75 rust-bin.nightly.latest.rust-analyzer
76 mdbook
77 ]
78 ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin)
79 ++ (lib.optional stdenv.isLinux lldb);
80 shellHook = ''
81 export RUST_BACKTRACE="1"
82 export RUSTFLAGS="''${RUSTFLAGS:-""} ${commonRustFlagsEnv} ${platformRustFlagsEnv}"
83 '';
84 };
85 })
86 pkgsFor;
87
88 overlays = {
89 helix = final: prev: {
90 helix = final.callPackage ./default.nix {inherit gitRev;};
91 };
92
93 default = self.overlays.helix;
94 };
95 };
96 nixConfig = {
97 extra-substituters = ["https://helix.cachix.org"];
98 extra-trusted-public-keys = ["helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="];
99 };
100}