{ description = "Rust flake"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; fenix = { url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { nixpkgs, flake-utils, fenix, ... }: let overlay = final: prev: let fenixPkgs = fenix.packages.${final.stdenv.hostPlatform.system}; in { rustToolchain = with fenixPkgs; combine ( with stable; [ clippy rustc cargo rustfmt rust-src ] ); }; in { overlays.default = overlay; } // flake-utils.lib.eachDefaultSystem ( system: let isDarwin = pkgs.stdenv.isDarwin; pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; }; commonBuildInputs = with pkgs; [ openssl ] ++ lib.optionals (!isDarwin) [ pkgs.udev ]; commonNativeBuildInputs = with pkgs; [ pkg-config ]; singerPackage = pkgs.rustPlatform.buildRustPackage { pname = "singer"; version = "0.1.0"; src = pkgs.lib.cleanSource ./.; cargoLock.lockFile = ./Cargo.lock; nativeBuildInputs = commonNativeBuildInputs; buildInputs = commonBuildInputs; }; in { packages = { singer = singerPackage; default = singerPackage; }; apps.default = { type = "app"; program = "${singerPackage}/bin/singer"; }; devShells.default = pkgs.mkShell { packages = (with pkgs; [ rustToolchain cargo-deny cargo-edit cargo-watch rust-analyzer ]) ++ commonBuildInputs ++ commonNativeBuildInputs; shellHook = '' export RUST_SRC_PATH="${pkgs.rustToolchain}/lib/rustlib/src/rust/library" ''; }; } ); }