# Copyright (c) 2022 Espresso Systems (espressosys.com) # This file is part of the Tide Disco library. # # This program is free software: you can redistribute it and/or modify it under the terms of the GNU # General Public License as published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License along with this program. If not, # see . { description = "Development shell for Tide Disco"; nixConfig = { extra-substituters = [ "https://espresso-systems-private.cachix.org" "https://nixpkgs-cross-overlay.cachix.org" ]; extra-trusted-public-keys = [ "espresso-systems-private.cachix.org-1:LHYk03zKQCeZ4dvg3NctyCq88e44oBZVug5LpYKjPRI=" "nixpkgs-cross-overlay.cachix.org-1:TjKExGN4ys960TlsGqNOI/NBdoz2Jdr2ow1VybWV5JM=" ]; }; inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-compat.url = "github:edolstra/flake-compat"; inputs.flake-compat.flake = false; inputs.rust-overlay.url = "github:oxalica/rust-overlay"; inputs.fenix.url = "github:nix-community/fenix"; inputs.fenix.inputs.nixpkgs.follows = "nixpkgs"; outputs = { self, nixpkgs, flake-utils, rust-overlay, fenix, ... }: flake-utils.lib.eachDefaultSystem (system: let info = builtins.split "\([a-zA-Z0-9_]+\)" system; arch = (builtins.elemAt (builtins.elemAt info 1) 0); os = (builtins.elemAt (builtins.elemAt info 3) 0); overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; rustToolchain = pkgs.rust-bin.stable.latest.minimal.override { extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ]; }; rustDeps = with pkgs; [ pkg-config openssl curl cargo-edit cargo-udeps cargo-sort ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security darwin.apple_sdk.frameworks.CoreFoundation darwin.apple_sdk.frameworks.SystemConfiguration # https://github.com/NixOS/nixpkgs/issues/126182 libiconv ] ++ lib.optionals (!stdenv.isDarwin) [ cargo-watch # broken: https://github.com/NixOS/nixpkgs/issues/146349 ]; # nixWithFlakes allows pre v2.4 nix installations to use # flake commands (like `nix flake update`) nixWithFlakes = pkgs.writeShellScriptBin "nix" '' exec ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes" "$@" ''; in { devShell = pkgs.mkShell { shellHook = '' # Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts with rustup # installations. export CARGO_HOME=$HOME/.cargo-nix ''; buildInputs = with pkgs; [ fenix.packages.${system}.rust-analyzer nixWithFlakes nixpkgs-fmt rustToolchain ] ++ rustDeps; # Use a distinct target dir for builds from within nix shells. CARGO_TARGET_DIR = "target/nix"; RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; RUST_BACKTRACE = 1; RUST_LOG = "info"; RUSTFLAGS = "--cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\""; }; }); }