# Either have nixpkgs and fenix in your channels
# Or build it using flakes, flake way is more recommended!
{
pkgs ? let
lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked;
nixpkgs = fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz";
sha256 = lock.narHash;
};
in
import nixpkgs {overlays = [];},
...
}: let
# Helpful nix function
lib = pkgs.lib;
getLibFolder = pkg: "${pkg}/lib";
# Manifest via Cargo.toml
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
in
pkgs.rustPlatform.buildRustPackage {
# Package related things automatically
# obtained from Cargo.toml, so you don't
# have to do everything manually
pname = manifest.name;
version = manifest.version;
# Your govnocodes
src = pkgs.lib.cleanSource ./.;
cargoLock = {
lockFile = ./Cargo.lock;
# Use this if you have dependencies from git instead
# of crates.io in your Cargo.toml
# outputHashes = {
# # Sha256 of the git repository, doesn't matter if it's monorepo
# "example-0.1.0" = "sha256-80EwvwMPY+rYyti8DMG4hGEpz/8Pya5TGjsbOBF0P0c=";
# };
};
# Compile time dependencies
nativeBuildInputs = with pkgs; [
# GCC toolchain
pkg-config
# Other compile time dependencies
# here
openssl
];
# Runtime dependencies which will be shipped
# with nix package
buildInputs = with pkgs; [
openssl
# libressl
];
# Set Environment Variables
RUST_BACKTRACE = 1;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
# Compiler LD variables
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.gcc
pkgs.libiconv
pkgs.llvmPackages.llvm
];
meta = with lib; {
homepage = manifest.homepage;
description = manifest.description;
license = with lib.licenses; [asl20 mit];
platforms = with platforms; linux ++ darwin;
maintainers = with lib.maintainers; [orzklv];
};
}