website/flake.nix

78 lines
2 KiB
Nix

{
description = "Flake for mc rust proxy";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
rust-overlay,
}: let
# rust-overlay = import rust-overlay;
system = "x86_64-linux";
pkgs =
import nixpkgs
{
inherit system;
overlays = [rust-overlay.overlays.default];
};
in {
devShells.${system}.default = pkgs.mkShell {
buildInputs = with pkgs; [
rust-bin.nightly.latest.default
rust-analyzer
];
# shellHook = ''
# echo "Hello from nix dev shell"
# '';
};
formatter.${system} = pkgs.alejandra;
packages.${system}.default = pkgs.rustPlatform.buildRustPackage rec {
pname = "webbisitey-${version}";
version = "0.1.0";
src = ./src/..;
runtime = ./public;
# Cargo cant download dependencies at build time, so this downloads them through nix
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = "${src}/Cargo.lock";
};
# we need rust to compile
nativeBuildInputs = [
pkgs.makeWrapper
pkgs.rust-bin.nightly.latest.default
];
# build the thing
buildPhase = ''
runHook preBuild
cargo build -r
mkdir -p $out/bin
cp target/release/webbisitey $out/bin
runHook postBuild
'';
# move the files
installPhase = ''
makeWrapper $out/bin/webbisitey $out/bin/webbisitey-wrapped --run 'cd $(dirname $0)'; # im too lazy to add a path argument so cd into the correct folder so it can serve files.
cp -r $runtime $out/bin/public
'';
meta = {
description = "Website server backend";
license = pkgs.lib.licenses.mit;
mainProgram = "webbisitey-wrapped"; # we want to run the wrapped version
};
};
};
}