Skip to content

Instantly share code, notes, and snippets.

@p1xelHer0
Created January 22, 2024 17:50
Show Gist options
  • Save p1xelHer0/1ac12f659ab38436a5cbaffe0a5f4d4a to your computer and use it in GitHub Desktop.
Save p1xelHer0/1ac12f659ab38436a5cbaffe0a5f4d4a to your computer and use it in GitHub Desktop.
macOS Nix flake for https://hands-on-rust.com/
{
description = "dungeoncrawler";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
binName = "dungeoncrawl";
inherit (pkgs.lib) optionals;
inherit (pkgs.stdenv) isDarwin;
inherit (pkgs.darwin.apple_sdk.frameworks) AppKit CoreVideo;
rustVersion =
pkgs.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.default.override {
extensions = [ "rust-src" "rust-analyzer" "rustfmt" "clippy" ];
});
rustPlatform = pkgs.makeRustPlatform {
cargo = rustVersion;
rustc = rustVersion;
};
buildInputs = with pkgs; [ ] ++ optionals isDarwin [ AppKit CoreVideo ];
in
with pkgs;
{
defaultPackage =
rustPlatform.buildRustPackage {
pname = binName;
version = "0.1.0";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
inherit buildInputs;
nativeBuildInputs = [ ];
postInstall = ''
cp -r resources $out/bin/
'';
};
devShells.default = mkShell {
inherit buildInputs;
nativeBuildInputs = [
rustVersion
cargo-watch
cargo-nextest
];
shellHook = ''
export CARGO_MANIFEST_DIR=$(pwd)
'';
};
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment