mascully_website/flake.nix
2025-07-27 00:53:52 +03:00

137 lines
5.2 KiB
Nix

{
description = "Flake for building mascully with Crane";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
nixConfig = { };
outputs =
inputs@{
flake-parts,
nixpkgs,
fenix,
crane,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
debug = true;
systems = nixpkgs.lib.systems.flakeExposed;
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
rustToolchain = fenix.packages.${system}.combine ([
(fenix.packages.${system}.complete.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
])
fenix.packages.${system}.complete.rust-analyzer
fenix.packages.${system}.targets.wasm32-unknown-unknown.latest.rust-std
]);
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# extraPackages = with pkgs; [
# cargo-leptos
# binaryen
# leptosfmt
# ];
commonArgs = {
# src = craneLib.cleanCargoSource ./.;
src = ./.;
strictDeps = true;
buildInputs = with pkgs; [
cargo-leptos
leptosfmt
binaryen
];
nativeBuildInputs = with pkgs; [
cargo-leptos
leptosfmt
binaryen
];
};
leptosOptions = builtins.elemAt (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.metadata.leptos 0;
# --profile=${leptosOptions.lib-profile-release}
cargoArtifacts = craneLib.buildDepsOnly (
commonArgs
// {
# if work is duplicated by the `mascullyWebsiteServer` package, update these
# commands from the logs of `cargo leptos build --release -vvv`
buildPhaseCargoCommand = ''
cargo build --package=${leptosOptions.lib-package} --lib --target-dir=/build/source/target/front --target=wasm32-unknown-unknown --no-default-features
cargo build --package=${leptosOptions.bin-package} --no-default-features --release
'';
}
);
mascullyWebsiteServer = craneLib.buildPackage (
commonArgs
// {
pname = "mascully_website_server";
version = "0.1.0";
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ pkgs.makeWrapper ];
buildPhaseCargoCommand = ''
RUST_BACKTRACE=full cargo-leptos build --release -vvv
'';
installPhaseCommand = ''
mkdir -p $out/bin
ls target/
pwd
cp target/server/release/mascully_website_server $out/bin/
# cp target/release/hash.txt $out/bin/
cp -r target/site $out/bin/
wrapProgram $out/bin/mascully_website_server --set LEPTOS_SITE_ROOT $out/bin/site
'';
doCheck = false;
doNotPostBuildInstallCargoBinaries = true;
cargoArtifacts = cargoArtifacts;
}
);
in
{
packages = rec {
inherit mascullyWebsiteServer;
default = mascullyWebsiteServer;
};
devShells.default = craneLib.devShell {
inputsFrom = [ mascullyWebsiteServer ];
# packages = extraPackages;
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
};
};
}