Skip to content

Commit

Permalink
Add frontend nix package
Browse files Browse the repository at this point in the history
  • Loading branch information
fugidev committed Jan 12, 2024
1 parent cec50aa commit e451506
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ yarn-error.log*

.idea
.vscode/

result
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let pkgs = nixpkgs.legacyPackages.${system};
in {
packages = {
# exam-poll-frontend = pkgs.callPackage ./frontend { };
exam-poll-frontend = pkgs.callPackage ./frontend { };
exam-poll-backend = pkgs.callPackage ./backend { };
};

Expand All @@ -18,7 +18,7 @@
) // {
overlays.default = (_: prev: {
inherit (self.packages.${prev.system})
exam-poll-backend;
exam-poll-frontend exam-poll-backend;
});

nixosModules.default = {
Expand Down
72 changes: 72 additions & 0 deletions frontend/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{ lib
, fetchYarnDeps
, mkYarnPackage
, nodejs
, makeWrapper
, localApiBaseUrl ? null
, publicApiBaseUrl ? null
}:

mkYarnPackage rec {
pname = "exam-poll-frontend";
version = "0.1.0";
src = ./.;

yarnLock = ./yarn.lock;
packageJSON = ./package.json;

offlineCache = fetchYarnDeps {
inherit yarnLock;
hash = "sha256-qyo62/Apld/JslCshF6iSwegbfBl41zpYHabj5/0ARs=";
};

NODE_ENV = "production";
API_BASEURL = localApiBaseUrl;
NEXT_PUBLIC_API_BASEURL = publicApiBaseUrl;

nativeBuildInputs = [ makeWrapper ];

configurePhase = ''
runHook preConfigure
ln -s $node_modules node_modules
runHook postConfigure
'';

buildPhase = ''
runHook preBuild
export HOME=$(mktemp -d)
# pipe to cat to disable fancy progress indicators cluttering the log
yarn --offline run build | cat
runHook postBuild
'';

installPhase = ''
runHook preInstall
export OUT_LIBEXEC="$out/libexec/${pname}"
mkdir -p $out $OUT_LIBEXEC
# copy compiled files
cp -r .next/standalone/. $OUT_LIBEXEC
# copy static files too
cp -r .next/static $OUT_LIBEXEC/.next/static
cp -r public $OUT_LIBEXEC/public
# server wrapper
makeWrapper '${nodejs}/bin/node' "$out/bin/${pname}" \
--add-flags "$OUT_LIBEXEC/server.js"
runHook postInstall
'';

dontFixup = true;
doDist = false;

meta = {
license = lib.licenses.gpl3Plus;
maintainers = with lib.maintainers; [ fugi ];
mainProgram = pname;
};
}
1 change: 1 addition & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
module.exports = {
output: 'standalone',
reactStrictMode: true,
i18n: {
// https://nextjs.org/docs/advanced-features/i18n-routing
Expand Down

0 comments on commit e451506

Please sign in to comment.