flake.nix for @microcosm.blue/microcosm-rs
flake.nix
96 lines 3.1 kB view raw
1{ 2 description = "A flake for building the microcosm-rs project"; 3 4 inputs = { 5 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 6 flake-utils.url = "github:numtide/flake-utils"; 7 crane.url = "github:ipetkov/crane"; 8 rust-overlay.url = "github:oxalica/rust-overlay"; 9 }; 10 11 outputs = { self, nixpkgs, flake-utils, crane, rust-overlay }: 12 flake-utils.lib.eachDefaultSystem (system: 13 let 14 overlays = [ (import rust-overlay) ]; 15 pkgs = import nixpkgs { 16 inherit system overlays; 17 }; 18 # Use the latest stable toolchain 19 rustVersion = pkgs.rust-bin.stable.latest.default; 20 craneLib = (crane.mkLib pkgs).overrideToolchain rustVersion; 21 src = pkgs.lib.cleanSource ./.; 22 cargoArtifacts = craneLib.buildDepsOnly { 23 inherit src; 24 pname = "microcosm-rs-deps"; 25 nativeBuildInputs = with pkgs; [ 26 pkg-config 27 openssl 28 protobuf 29 ]; 30 }; 31 members = [ 32 "links" 33 "constellation" 34 "jetstream" 35 "ufos" 36 "ufos/fuzz" 37 "spacedust" 38 "who-am-i" 39 "slingshot" 40 "quasar" 41 "pocket" 42 "reflector" 43 ]; 44 buildPackage = member: 45 let 46 packageName = if member == "ufos/fuzz" then "ufos-fuzz" else member; 47 in 48 craneLib.buildPackage { 49 inherit src cargoArtifacts; 50 pname = packageName; 51 version = "0.1.0"; 52 cargoExtraArgs = "--package ${packageName}"; 53 nativeBuildInputs = with pkgs; [ 54 pkg-config 55 openssl 56 protobuf # for slingshot 57 ]; 58 buildInputs = with pkgs; [ 59 zstd # for jetstream, constellation 60 lz4 # for ufos 61 rocksdb # for constellation 62 ] ++ (pkgs.lib.optional (member == "pocket") sqlite); 63 }; 64 65 packages = pkgs.lib.genAttrs members (member: buildPackage member); 66 in 67 { 68 packages = packages // { 69 # Use the corrected package names for the link farm to avoid slashes in names 70 default = pkgs.linkFarm "microcosm-rs" (pkgs.lib.mapAttrsToList (name: value: 71 let 72 # Correct the link name here just like we did for the package name 73 linkName = if name == "ufos/fuzz" then "ufos-fuzz" else name; 74 in 75 { name = linkName; path = value; } 76 ) packages); # <-- THE FIX IS HERE 77 }; 78 devShell = pkgs.mkShell { 79 inputsFrom = builtins.attrValues self.packages.${system}; 80 nativeBuildInputs = with pkgs; [ 81 (rustVersion.override { 82 extensions = [ "rust-src" "rust-analyzer" ]; 83 }) 84 cargo 85 pkg-config 86 openssl 87 protobuf 88 zstd 89 lz4 90 rocksdb 91 sqlite 92 ]; 93 RUST_SRC_PATH = "${rustVersion}/lib/rustlib/src/rust/library"; 94 }; 95 }); 96}