2024-06-25 19:25:45 +02:00
|
|
|
{
|
|
|
|
|
description = "A basic flake with a shell";
|
|
|
|
|
inputs = {
|
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
|
|
|
cargo-workspace.url = "github:Maix0/cargo-ws-flake";
|
|
|
|
|
cargo-semver-checks.url = "github:Maix0/cargo-semver-checks-flake";
|
2024-06-25 19:34:41 +02:00
|
|
|
naersk.url = "github:nix-community/naersk";
|
2024-06-25 19:25:45 +02:00
|
|
|
};
|
|
|
|
|
outputs = {
|
|
|
|
|
self,
|
|
|
|
|
nixpkgs,
|
|
|
|
|
flake-utils,
|
|
|
|
|
rust-overlay,
|
2024-06-25 19:34:41 +02:00
|
|
|
naersk,
|
2024-06-25 19:25:45 +02:00
|
|
|
...
|
|
|
|
|
} @ inputs:
|
|
|
|
|
flake-utils.lib.eachDefaultSystem (system: let
|
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
|
inherit system;
|
|
|
|
|
overlays = [(import rust-overlay)];
|
|
|
|
|
};
|
|
|
|
|
packageIf = name: packageDef:
|
|
|
|
|
if builtins.hasAttr name inputs
|
|
|
|
|
then [(packageDef inputs.${name})]
|
|
|
|
|
else [];
|
|
|
|
|
buildRustToolchain = toolchainDef:
|
|
|
|
|
if builtins.isString toolchainDef
|
|
|
|
|
then let
|
|
|
|
|
split = pkgs.lib.strings.splitString "/" toolchainDef;
|
|
|
|
|
toolchainType =
|
|
|
|
|
if (builtins.length split) > 3
|
|
|
|
|
then throw "You can only specify a single version using `{type}/{version}/{profile}`"
|
|
|
|
|
else if (builtins.length split) >= 1
|
|
|
|
|
then builtins.elemAt split 0
|
|
|
|
|
else throw "You must specify at least a toolchain version with this format `{type}/{version}/{profile}`";
|
|
|
|
|
toolchainVersion =
|
|
|
|
|
if (builtins.length split) > 3
|
|
|
|
|
then throw "You can only specify a single version using `{type}/{version}/{profile}`"
|
|
|
|
|
else if (builtins.length split) >= 2
|
|
|
|
|
then builtins.elemAt split 1
|
|
|
|
|
else "latest";
|
|
|
|
|
toolchainProfile =
|
|
|
|
|
if (builtins.length split) > 3
|
|
|
|
|
then throw "You can only specify a single version using `{type}/{version}/{profile}`"
|
|
|
|
|
else if (builtins.length split) >= 3
|
|
|
|
|
then builtins.elemAt split 2
|
|
|
|
|
else "default";
|
|
|
|
|
in
|
|
|
|
|
buildRustToolchain {
|
|
|
|
|
toolchain = toolchainType;
|
|
|
|
|
version = toolchainVersion;
|
|
|
|
|
profile = toolchainProfile;
|
|
|
|
|
}
|
|
|
|
|
else if builtins.isAttrs toolchainDef
|
|
|
|
|
then
|
|
|
|
|
if toolchainDef.toolchain == "stable"
|
|
|
|
|
then pkgs.rust-bin.stable.${toolchainDef.version}.${toolchainDef.profile}.override (builtins.removeAttrs toolchainDef ["toolchain" "version" "profile"])
|
|
|
|
|
else if toolchainDef.toolchain == "beta"
|
|
|
|
|
then pkgs.rust-bin.beta.${toolchainDef.version}.${toolchainDef.profile}.override (builtins.removeAttrs toolchainDef ["toolchain" "version" "profile"])
|
|
|
|
|
else if toolchainDef.toolchain == "nightly"
|
|
|
|
|
then
|
|
|
|
|
if toolchainDef.version == "latest"
|
|
|
|
|
then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.${toolchainDef.profile}.override (builtins.removeAttrs toolchainDef ["toolchain" "version" "profile"]))
|
|
|
|
|
else pkgs.rust-bin.nightly.${toolchainDef.version}.${toolchainDef.profile}.override (builtins.removeAttrs toolchainDef ["toolchain" "version" "profile"])
|
|
|
|
|
else throw "toolchain version isn't valid (not 'stable' or 'beta' or 'nightly')"
|
|
|
|
|
else throw "toolchainDef isn't a string or an attr describing the toolchain";
|
2024-06-25 19:34:41 +02:00
|
|
|
rust_dev = buildRustToolchain "stable/latest/default";
|
|
|
|
|
naersk' = pkgs.callPackage naersk {
|
|
|
|
|
cargo = rust_dev;
|
|
|
|
|
rustc = rust_dev;
|
|
|
|
|
};
|
2024-06-25 19:25:45 +02:00
|
|
|
in {
|
2024-06-25 19:34:41 +02:00
|
|
|
packages.default = naersk'.buildPackage {
|
|
|
|
|
src = ./.;
|
|
|
|
|
};
|
2024-06-25 19:25:45 +02:00
|
|
|
|
2024-06-25 19:34:41 +02:00
|
|
|
devShell = pkgs.mkShell {
|
|
|
|
|
packages = with pkgs;
|
|
|
|
|
[
|
|
|
|
|
rust_dev
|
|
|
|
|
mold
|
|
|
|
|
openssl
|
|
|
|
|
pkg-config
|
|
|
|
|
]
|
|
|
|
|
++ (packageIf "cargo-semver-checks" (p: p.packages.${system}.default))
|
|
|
|
|
++ (packageIf "cargo-workspace" (p: p.packages.${system}.default));
|
2024-06-25 19:25:45 +02:00
|
|
|
|
2024-06-25 19:34:41 +02:00
|
|
|
shellHook = ''
|
|
|
|
|
export RUST_STD="${rust_dev}/share/doc/rust/html/std/index.html"
|
|
|
|
|
|
|
|
|
|
if [ -z $CARGO_TARGET_DIR ] then
|
|
|
|
|
: "''${XDG_CACHE_HOME:="''$HOME/.cache"}"
|
|
|
|
|
local hash path
|
|
|
|
|
hash="$(sha1sum - <<< "$PWD" | head -c40)"
|
|
|
|
|
path="''${PWD//[^a-zA-Z0-9]/}"
|
|
|
|
|
export CARGO_TARGET_DIR="''${XDG_CACHE_HOME}/rust-targets/$hash-$path"
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-06-25 19:25:45 +02:00
|
|
|
});
|
|
|
|
|
}
|