mi/default.nix

48 lines
1.2 KiB
Nix
Raw Normal View History

2020-11-07 17:29:47 +00:00
{ sources ? import ./nix/sources.nix, pkgs ? import sources.nixpkgs { } }:
with pkgs;
let
backend = callPackage ./backend { inherit sources pkgs; };
frontend = callPackage ./sina { inherit sources pkgs; };
gruvbox = callPackage sources.gruvbox-css { };
2020-11-07 17:29:47 +00:00
composite = stdenv.mkDerivation {
pname = "mi";
version = "${backend.version}";
phases = "installPhase";
2020-11-07 17:29:47 +00:00
installPhase = ''
# service binary
mkdir -p $out/bin
2020-11-07 17:29:47 +00:00
for file in ${backend}/bin/*; do
ln -s ${backend}/bin/$(basename $file) $out/bin/$(basename $file)
done
2020-11-07 17:29:47 +00:00
# static files
mkdir -p $out/public/
cp -vrf ${./static}/* $out/public
2020-11-07 17:29:47 +00:00
# frontend JS
2020-11-17 19:54:31 +00:00
rm $out/public/elm.js ||:
ln -s ${frontend}/Main.min.js $out/public/elm.js
'';
};
wrapper = writeScriptBin "mi-backend" ''
#!${pkgs.stdenv.shell}
set -e
set -x
export RUST_LOG=info
export DATABASE_URL=./mi.db
export ROCKET_DATABASES='{ main_data = { url = "./mi.db" } }';
${composite}/bin/migrate_database
${composite}/bin/bridgy_migrate || true
export ROCKET_ASSET_PATH=${composite}/public
exec ${composite}/bin/mi
2020-11-07 17:29:47 +00:00
'';
in symlinkJoin {
name = "mi";
paths = [ wrapper composite ];
2020-11-07 17:29:47 +00:00
}