feat: rust template #26

Open
liketechnik wants to merge 6 commits from liketechnik/feat/rust-template into main
Showing only changes of commit 6c25032fcd - Show all commits

View file

@ -35,50 +35,62 @@
overlays = [ (final: prev: { ${packageName} = self.packages.${system}.${packageName}; }) ]; overlays = [ (final: prev: { ${packageName} = self.packages.${system}.${packageName}; }) ];
}; };
fenix-pkgs = fenix.packages.${system}; fenixPkgsFor = pkgs: fenix.packages.${pkgs.system};
fenix-channel = fenix-pkgs.toolchainOf { fenixChannelFor =
channel = "nightly"; pkgs:
date = (fenixPkgsFor pkgs).toolchainOf {
builtins.replaceStrings [ "nightly-" ] [ "" ] channel = "nightly";
(builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel; date =
sha256 = "sha256-SzEeSoO54GiBQ2kfANPhWrt0EDRxqEvhIbTt2uJt/TQ="; builtins.replaceStrings [ "nightly-" ] [ "" ]
}; (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
sha256 = "sha256-SzEeSoO54GiBQ2kfANPhWrt0EDRxqEvhIbTt2uJt/TQ=";
};
makeCrossPackage = toolchainFor =
packageName: pkgsCross: pkgs:
let let
pkgs = builtins.throw "defining cross pkg, accessing pkgs is a bug"; fenix-pkgs = fenixPkgsFor pkgs;
in
with fenix-pkgs;
combine [
minimal.cargo
minimal.rustc
targets.${pkgs.rust.lib.toRustTarget pkgs.stdenv.targetPlatform}.latest.rust-std
];
rustPlatformFor =
pkgs:
let
toolchain = toolchainFor pkgs;
in
pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
crossPackageFor =
pkgs:
let
rustPlatform = rustPlatformFor pkgs;
in in
{ {
"${packageName}-cross-${pkgsCross.stdenv.hostPlatform.config}${ "${packageName}-cross-${pkgs.stdenv.hostPlatform.config}${
if pkgsCross.stdenv.hostPlatform.isStatic then "-static" else "" if pkgs.stdenv.hostPlatform.isStatic then "-static" else ""
}" = }" = pkgs.callPackage (./. + "/nix/packages/${packageName}.nix") {
let inherit cargoMeta rustPlatform;
toolchain = flake-self = self;
with fenix-pkgs; };
combine [
minimal.cargo
minimal.rustc
targets.${pkgsCross.rust.lib.toRustTarget pkgsCross.stdenv.targetPlatform}.latest.rust-std
];
in
pkgsCross.callPackage (./. + "/nix/packages/${packageName}.nix") {
inherit cargoMeta;
flake-self = self;
rustPlatform = pkgsCross.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
};
}; };
in in
function { function {
inherit inherit
system system
pkgs pkgs
fenix-pkgs fenixPkgsFor
fenix-channel fenixChannelFor
makeCrossPackage toolchainFor
rustPlatformFor
crossPackageFor
; ;
} }
); );
@ -89,11 +101,14 @@
packages = forSystems ( packages = forSystems (
{ {
pkgs, pkgs,
fenix-channel, fenixChannelFor,
system, system,
makeCrossPackage, crossPackageFor,
... ...
}: }:
let
fenix-channel = fenixChannelFor pkgs;
in
{ {
${packageName} = pkgs.callPackage (./. + "/nix/packages/${packageName}.nix") { ${packageName} = pkgs.callPackage (./. + "/nix/packages/${packageName}.nix") {
inherit cargoMeta; inherit cargoMeta;
@ -105,21 +120,17 @@
}; };
default = self.packages.${system}.${packageName}; default = self.packages.${system}.${packageName};
} }
// makeCrossPackage packageName pkgs.pkgsCross.musl64.pkgsStatic // crossPackageFor pkgs.pkgsCross.musl64.pkgsStatic
// makeCrossPackage packageName pkgs.pkgsCross.musl32.pkgsStatic // crossPackageFor pkgs.pkgsCross.musl32.pkgsStatic
// makeCrossPackage packageName pkgs.pkgsCross.aarch64-multiplatform-musl.pkgsStatic // crossPackageFor pkgs.pkgsCross.aarch64-multiplatform-musl.pkgsStatic
// makeCrossPackage packageName pkgs.pkgsCross.armv7l-hf-multiplatform.pkgsStatic // crossPackageFor pkgs.pkgsCross.armv7l-hf-multiplatform.pkgsStatic
// makeCrossPackage packageName pkgs.pkgsCross.mingwW64.pkgsStatic // crossPackageFor pkgs.pkgsCross.mingwW64.pkgsStatic
); );
devShells = forSystems ( devShells = forSystems (
{ { pkgs, fenixChannelFor, ... }:
pkgs,
fenix-pkgs,
fenix-channel,
...
}:
let let
fenix-channel = fenixChannelFor pkgs;
fenixRustToolchain = fenix-channel.withComponents [ fenixRustToolchain = fenix-channel.withComponents [
"cargo" "cargo"
"clippy-preview" "clippy-preview"