Skip to content

Commit

Permalink
Merge pull request #555 from hensg/nix-flake
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow authored Oct 3, 2024
2 parents cfc71fe + 4bef527 commit 25da553
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN yarn build
FROM base AS runner
WORKDIR /app

# note: remember to make changes to the installPhase in flake.nix as well
COPY --from=installer /app/apps/router/build build
COPY scripts/replace-react-env.js scripts/replace-react-env.js
COPY scripts/write-config-from-env.js scripts/write-config-from-env.js
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 34 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
fedimint = {
# master on 09/30/2024
url =
"github:fedimint/fedimint?rev=e8e3e6d84c223c3b90d7cf8d5fd5f346a7443e66";
};
fedimint.url =
"github:fedimint/fedimint?ref=refs/tags/v0.4.3";
};
outputs = { self, flake-utils, fedimint }:
flake-utils.lib.eachDefaultSystem (system:
Expand All @@ -17,11 +14,24 @@
};
fmLib = fedimint.lib.${system};


# When `yarn.lock` changes, follow these steps to update the `sha256` hash:
# 1. Remove the existing `sha256` hash.*
# 2. Rebuild the Nix derivation** by executing:
# nix build .#guardian-ui
# 3. Obtain the new `sha256` hash** from the build error message.
# 4. Update the `sha256` value** below with the newly copied hash.
#
# **Important:**
# Keeping the `sha256` hash in sync with `yarn.lock` is essential. An outdated or incorrect hash
# will cause the Nix package to become out-of-sync with Yarn dependencies, potentially leading
# to build failures or inconsistent behavior.
yarnOfflineCache = pkgs.fetchYarnDeps {
yarnLock = ./yarn.lock;
hash = "sha256-lJcqjTwC5C+4rvug6RYg8Ees4SzNTD+HazfACz1EaSQ=";
hash = "sha256-a1YeZYvxstAqDCgK2qrlylkKYhIX1Xo28tCKt46hxrE=";
};
in {
in
{
devShells = fmLib.devShells // {
default = fmLib.devShells.default.overrideAttrs (prev: {
nativeBuildInputs = [
Expand All @@ -40,19 +50,28 @@

packages.guardian-ui = pkgs.stdenv.mkDerivation {
pname = "guardian-ui";
version = "0.3.0";
version = "0.4.3";
src = ./.;

nativeBuildInputs = with pkgs; [
nodejs
yarn
cacert
yarn2nix-moretea.fixup_yarn_lock
];

configurePhase = ''
export HOME=$(mktemp -d)
'';

# NixOS is introducing `yarnBuildHook`, `yarnConfigHook`, and `yarnInstallHook`,
# which could simplify the current complex `buildPhase` that uses `fixup_yarn_lock`
# and the `installPhase`.
# 1. [JavaScript Frameworks Documentation](https://github.com/NixOS/nixpkgs/blob/ab4dc6ca78809a367aba6fb2813a15116560e2a9/doc/languages-frameworks/javascript.section.md)
# 2. [Nixpkgs Issue #324246](https://github.com/NixOS/nixpkgs/issues/324246)
#
# Additionally, avoid using `pkgs.mkYarnPackage` as it is slated for deprecation.

buildPhase = ''
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
fixup_yarn_lock yarn.lock
Expand All @@ -62,12 +81,16 @@
--ignore-engines --ignore-scripts
patchShebangs .
yarn build:guardian-ui
yarn build
'';

# should be similar to the installer in the Dockerfile
installPhase = ''
mkdir -p $out
cp -R apps/guardian-ui/build/* $out
mkdir -p $out/scripts
cp -r apps/router/build/* $out/
cp -r scripts/replace-react-env.js $out/scripts/replace-react-env.js
cp -r scripts/write-config-from-env.js $out/scripts/write-config-from-env.js
'';
};
});
Expand Down

0 comments on commit 25da553

Please sign in to comment.