From 6b6eb40b7380b9dd5b756edb2748ab836656af6f Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 28 May 2024 00:00:00 +0000 Subject: [PATCH] =?UTF-8?q?flake:=20=F0=9F=A5=90=20add=20nix=20development?= =?UTF-8?q?=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.lock | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 56 ++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..21eac4f --- /dev/null +++ b/flake.lock @@ -0,0 +1,106 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716745752, + "narHash": "sha256-8K1R9Yg4r08rYk86Yq+lu3E9L3uRUb4xMqYHgl0VGS0=", + "owner": "ipetkov", + "repo": "crane", + "rev": "19ca94ec2d288de334ae932107816b4a97736cd8", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716509168, + "narHash": "sha256-4zSIhSRRIoEBwjbPm3YiGtbd8HDWzFxJjw5DYSDy1n8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfb7a882678e518398ce9a31a881538679f6f092", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716862669, + "narHash": "sha256-7oTPM9lcdwiI1cpRC313B+lHawocgpY5F07N+Rbm5Uk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "47b2d15658b37716393b2463a019000dbd6ce4bc", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1222bac --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + description = "A nix development shell and build environment for galileo"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + crane = { + url = "github:ipetkov/crane"; + inputs = { nixpkgs.follows = "nixpkgs"; }; + }; + }; + + outputs = { nixpkgs, flake-utils, rust-overlay, crane, ... }: + flake-utils.lib.eachDefaultSystem + (system: + let + # Set up for Rust builds, pinned to the Rust toolchain version in the Penumbra repository + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + src = craneLib.cleanCargoSource (craneLib.path ./.); + # Important environment variables so that the build can find the necessary libraries + PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig"; + LIBCLANG_PATH="${pkgs.libclang.lib}/lib"; + in with pkgs; with pkgs.lib; let + galileo = (craneLib.buildPackage { + inherit src system PKG_CONFIG_PATH LIBCLANG_PATH; + pname = "galileo"; + version = "0.1.0"; + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ clang openssl ]; + # A lockfile is not used in this repository. + cargoVendorDir = null; + }).overrideAttrs (_: { doCheck = false; }); # Disable tests to improve build times + in { + inherit galileo; + devShells.default = craneLib.devShell { + inherit LIBCLANG_PATH; + inputsFrom = [ galileo ]; + packages = [ cargo-watch cargo-nextest ]; + shellHook = '' + export LIBCLANG_PATH=${LIBCLANG_PATH} + export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer + ''; + }; + } + ); +}