|
| 1 | +{ |
| 2 | + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
| 3 | + inputs.nixpkgs-mozilla.url = "github:mozilla/nixpkgs-mozilla/master"; |
| 4 | + outputs = { self, nixpkgs, nixpkgs-mozilla, ... } @ inputs: |
| 5 | + { |
| 6 | + devShells.x86_64-linux.default = |
| 7 | + let pkgs = import nixpkgs { |
| 8 | + system = "x86_64-linux"; |
| 9 | + overlays = [ (import (nixpkgs-mozilla + "/rust-overlay.nix")) ]; |
| 10 | + }; |
| 11 | + in with pkgs; let |
| 12 | + # Work around the nixpkgs-mozilla equivalent of |
| 13 | + # https://github.com/NixOS/nixpkgs/issues/278508 and an |
| 14 | + # incompatibility between nixpkgs-mozilla and makeRustPlatform |
| 15 | + rustChannelOf = args: let |
| 16 | + orig = pkgs.rustChannelOf args; |
| 17 | + patchRustPkg = pkg: (pkg.overrideAttrs (oA: { |
| 18 | + buildCommand = builtins.replaceStrings |
| 19 | + [ "rustc,rustdoc" ] |
| 20 | + [ "rustc,rustdoc,clippy-driver,cargo-clippy" ] |
| 21 | + oA.buildCommand; |
| 22 | + })) // { |
| 23 | + targetPlatforms = [ "x86_64-linux" ]; |
| 24 | + badTargetPlatforms = [ ]; |
| 25 | + }; |
| 26 | + overrideRustPkg = pkg: lib.makeOverridable (origArgs: |
| 27 | + patchRustPkg (pkg.override origArgs) |
| 28 | + ) {}; |
| 29 | + in builtins.mapAttrs (_: overrideRustPkg) orig; |
| 30 | + |
| 31 | + customisedRustChannelOf = args: |
| 32 | + lib.flip builtins.mapAttrs (rustChannelOf args) (_: pkg: pkg.override { |
| 33 | + targets = [ |
| 34 | + "x86_64-unknown-linux-gnu" |
| 35 | + "x86_64-pc-windows-msvc" "x86_64-unknown-none" |
| 36 | + "wasm32-wasip1" "wasm32-wasip2" "wasm32-unknown-unknown" |
| 37 | + ]; |
| 38 | + extensions = [ "rust-src" ]; |
| 39 | + }); |
| 40 | + |
| 41 | + # Hyperlight needs a variety of toolchains, since we use Nightly |
| 42 | + # for rustfmt and old toolchains to verify MSRV |
| 43 | + toolchains = lib.mapAttrs (_: customisedRustChannelOf) { |
| 44 | + stable = { |
| 45 | + # Stay on 1.87 for development due to the |
| 46 | + # quickly-reversed default enablement of |
| 47 | + # #[warn(clippy::uninlined_format_args)] |
| 48 | + date = "2025-05-15"; |
| 49 | + channel = "stable"; |
| 50 | + sha256 = "sha256-KUm16pHj+cRedf8vxs/Hd2YWxpOrWZ7UOrwhILdSJBU="; |
| 51 | + }; |
| 52 | + nightly = { |
| 53 | + date = "2025-07-29"; |
| 54 | + channel = "nightly"; |
| 55 | + sha256 = "sha256-6D2b7glWC3jpbIGCq6Ta59lGCKN9sTexhgixH4Y7Nng="; |
| 56 | + }; |
| 57 | + "1.85" = { |
| 58 | + date = "2025-02-20"; |
| 59 | + channel = "stable"; |
| 60 | + sha256 = "sha256-AJ6LX/Q/Er9kS15bn9iflkUwcgYqRQxiOIL2ToVAXaU="; |
| 61 | + }; |
| 62 | + }; |
| 63 | + |
| 64 | + rust-platform = makeRustPlatform { |
| 65 | + cargo = toolchains.stable.rust; |
| 66 | + rustc = toolchains.stable.rust; |
| 67 | + }; |
| 68 | + |
| 69 | + # Hyperlight scripts use cargo in a bunch of ways that don't |
| 70 | + # make sense for Nix cargo, including the `rustup +toolchain` |
| 71 | + # syntax to use a specific toolchain and `cargo install`, so we |
| 72 | + # build wrappers for rustc and cargo that enable this. The |
| 73 | + # scripts also use `rustup toolchain install` in some cases, in |
| 74 | + # order to work in CI, so we provide a fake rustup that does |
| 75 | + # nothing as well. |
| 76 | + rustup-like-wrapper = name: pkgs.writeShellScriptBin name |
| 77 | + (let |
| 78 | + clause = name: toolchain: |
| 79 | + "+${name}) base=\"${toolchain.rust}\"; shift 1; ;;"; |
| 80 | + clauses = lib.strings.concatStringsSep "\n" |
| 81 | + (lib.mapAttrsToList clause toolchains); |
| 82 | + in '' |
| 83 | + base="${toolchains.stable.rust}" |
| 84 | + case "$1" in |
| 85 | + ${clauses} |
| 86 | + install) exit 0; ;; |
| 87 | + esac |
| 88 | + export PATH="$base/bin:$PATH" |
| 89 | + exec "$base/bin/${name}" "$@" |
| 90 | + ''); |
| 91 | + fake-rustup = pkgs.symlinkJoin { |
| 92 | + name = "fake-rustup"; |
| 93 | + paths = [ |
| 94 | + (pkgs.writeShellScriptBin "rustup" "") |
| 95 | + (rustup-like-wrapper "rustc") |
| 96 | + (rustup-like-wrapper "cargo") |
| 97 | + ]; |
| 98 | + }; |
| 99 | + |
| 100 | + buildRustPackageClang = rust-platform.buildRustPackage.override { stdenv = clangStdenv; }; |
| 101 | + in (buildRustPackageClang rec { |
| 102 | + pname = "hyperlight"; |
| 103 | + version = "0.0.0"; |
| 104 | + src = lib.cleanSource ./.; |
| 105 | + cargoHash = "sha256-F8ntdieOstUyh7qKxENKOWYUyponFcMoeGBgeRpuCt0="; |
| 106 | + |
| 107 | + nativeBuildInputs = [ |
| 108 | + azure-cli |
| 109 | + just |
| 110 | + dotnet-sdk_9 |
| 111 | + llvmPackages_18.llvm |
| 112 | + gh |
| 113 | + lld |
| 114 | + valgrind |
| 115 | + pkg-config |
| 116 | + ffmpeg |
| 117 | + mkvtoolnix |
| 118 | + wasm-tools |
| 119 | + jq |
| 120 | + jaq |
| 121 | + gdb |
| 122 | + ]; |
| 123 | + buildInputs = [ |
| 124 | + pango |
| 125 | + cairo |
| 126 | + openssl |
| 127 | + ]; |
| 128 | + |
| 129 | + auditable = false; |
| 130 | + |
| 131 | + LIBCLANG_PATH = "${pkgs.llvmPackages_18.libclang.lib}/lib"; |
| 132 | + # Use unwrapped clang for compiling guests |
| 133 | + HYPERLIGHT_GUEST_clang = "${clang.cc}/bin/clang"; |
| 134 | + |
| 135 | + RUST_NIGHTLY = "${toolchains.nightly.rust}"; |
| 136 | + # Set this through shellHook rather than nativeBuildInputs to be |
| 137 | + # really sure that it overrides the real cargo. |
| 138 | + shellHook = '' |
| 139 | + export PATH="${fake-rustup}/bin:$PATH" |
| 140 | + ''; |
| 141 | + }).overrideAttrs(oA: { |
| 142 | + hardeningDisable = [ "all" ]; |
| 143 | + }); |
| 144 | + }; |
| 145 | +} |
0 commit comments