97 lines
2.5 KiB
Nix
97 lines
2.5 KiB
Nix
{
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
|
rust-overlay.inputs.flake-utils.follows = "flake-utils";
|
|
|
|
naersk.url = "github:nmattia/naersk";
|
|
naersk.inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, rust-overlay, flake-utils, naersk }: flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
overlays = [
|
|
rust-overlay.overlays.default
|
|
(final: prev: {
|
|
rustc = final.rust-bin.stable.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; };
|
|
cargo = final.rust-bin.stable.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; };
|
|
})
|
|
];
|
|
pkgs = import nixpkgs { inherit system overlays; };
|
|
naerskLib = pkgs.callPackage naersk { };
|
|
in
|
|
rec {
|
|
packages = {
|
|
backend = naerskLib.buildPackage {
|
|
src = ./backend;
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
wasm-bindgen-cli
|
|
wasm-pack
|
|
];
|
|
|
|
overrideMain = (o: o // {
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
wasm-pack build --target web --release --mode no-install -- --offline
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
cp -r pkg $out
|
|
runHook postInstall
|
|
'';
|
|
});
|
|
};
|
|
|
|
frontend = pkgs.stdenvNoCC.mkDerivation {
|
|
name = "password-hash-self-service";
|
|
|
|
src = self;
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
mkdir $out
|
|
cp \
|
|
index.html \
|
|
style.css \
|
|
app.js \
|
|
$out
|
|
|
|
mkdir $out/backend
|
|
ln -s ${packages.backend} $out/backend/pkg
|
|
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
};
|
|
|
|
defaultPackage = packages.frontend;
|
|
|
|
devShell = pkgs.mkShell {
|
|
buildInputs = with pkgs; [
|
|
wasm-bindgen-cli
|
|
wasm-pack
|
|
(rust-bin.stable.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; })
|
|
];
|
|
};
|
|
|
|
apps = {
|
|
serve = {
|
|
type = "app";
|
|
program = toString (pkgs.writeShellScript "serve" ''
|
|
${pkgs.python3}/bin/python3 -m http.server
|
|
'');
|
|
};
|
|
};
|
|
});
|
|
}
|