templates/flakes/rust/flake.nix

58 lines
1.6 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
let
inherit (builtins) fromTOML readFile substring;
cargoToml = fromTOML (readFile ./Cargo.toml);
version = "${cargoToml.package.version}+${substring 0 8 self.lastModifiedDate}_${self.shortRev or "dirty"}";
# FIXME: rename mkHello
mkHello = { lib, rustPlatform, ... }:
rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
inherit version;
src = lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock;
doCheck = true;
};
in
{
# FIXME: rename hello overlay with package name
overlays.hello = final: prev: {
hello = prev.callPackage mkHello;
};
overlays.default = self.overlays.hello;
}
//
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
# FIXME: rename hello
hello = pkgs.callPackage mkHello { };
in
{
packages = {
inherit hello;
default = hello;
};
# FIXME: rename hello app with program path
apps.hello = {
type = "app";
program = "${hello}/bin/hello";
};
apps.default = self.apps.${system}.hello;
devShell = pkgs.mkShell {
packages = with pkgs; [ cargo rustc rustfmt clippy rust-analyzer ];
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
};
});
}