Skip to content

Commit

Permalink
Merge pull request #62 from EspressoSystems/feat/nix
Browse files Browse the repository at this point in the history
Set up Nix development
  • Loading branch information
jbearer authored Aug 10, 2022
2 parents 3841d98 + 940f1a7 commit ef9016c
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use nix
watch_file flake.nix
watch_file shell.nix
watch_file flake.lock
watch_file .envrc
150 changes: 150 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 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 <https://www.gnu.org/licenses/>.

{
description = "Development shell for Tide Disco";

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, flake-compat, 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;
[
pkgconfig
openssl
bash

curl

cargo-edit
cargo-udeps
cargo-sort
cmake
] ++ 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.system != "aarch64-darwin") [
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" "$@"
'';
shellHook = ''
# on mac os `bin/pwd -P` returns the canonical path on case insensitive file-systems
my_pwd=$(/bin/pwd -P 2> /dev/null || pwd)
export PATH=${pkgs.xdot}/bin:$PATH
export PATH=''${my_pwd}/bin:$PATH
'';
in {
devShell = pkgs.mkShell {
shellHook = shellHook;
buildInputs = with pkgs;
[
fenix.packages.${system}.rust-analyzer
nixWithFlakes
nixpkgs-fmt
git
mdbook # make-doc, documentation generation
rustToolchain
] ++ rustDeps;

RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
RUST_BACKTRACE = 1;
RUST_LOG = "info";
};
});
}
13 changes: 13 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}).shellNix

0 comments on commit ef9016c

Please sign in to comment.