password-hash-self-service/flake.nix
2021-08-29 12:05:57 +02:00

94 lines
2.3 KiB
Nix

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
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.overlay
(final: prev: {
rustc = final.rust-bin.nightly.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; };
cargo = final.rust-bin.nightly.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-pack
(rust-bin.nightly.latest.default.override { targets = [ "wasm32-unknown-unknown" ]; })
];
};
apps = {
serve = {
type = "app";
program = toString (pkgs.writeShellScript "serve" ''
${pkgs.python3}/bin/python3 -m http.server
'');
};
};
});
}