Skip to content

Commit

Permalink
nix: fix garnix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Jan 2, 2025
1 parent 82ae303 commit 7092f02
Show file tree
Hide file tree
Showing 5 changed files with 10,459 additions and 38 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
frontend = frontend.devShell;
# shell with js dependencies only if yarn.lock is broken and needs fixed
js = defaultPkgs.mkShell {
buildInputs = [ nodePkgs.nodejs_18 nodePkgs.yarn ];
buildInputs = [ nodePkgs.nodejs_20 ];
};
};
});
Expand Down
9 changes: 8 additions & 1 deletion govtool/frontend/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ if [[ "${CARDANO_NETWORK}" = "mainnet" ]]; then
else
export VITE_NETWORK_FLAG=0
fi
export VITE_APP_ENV="development"
export VITE_BASE_URL=http://localhost:9999
export VITE_IS_DEV=true
export VITE_METADATA_API_URL=http://localhost:3000
export VITE_GTM_ID="${GTM_ID}"
export VITE_IS_DEV=true
export VITE_SENTRY_DSN="${SENTRY_DSN}"
export VITE_USERSNAP_SPACE_API_KEY=""
export VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED=true
export VITE_PDF_API_URL=""
export VITE_IPFS_GATEWAY=https://ipfs.io/ipfs/
export VITE_IPFS_PROJECT_ID=""

use flake --extra-experimental-features nix-command --extra-experimental-features flakes ../..#frontend
34 changes: 5 additions & 29 deletions govtool/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Installed on your machine:

1. Node.js >= 18 ([official website](https://nodejs.org/en))
2. npm or yarn (recommended) - for package management
2. npm - for package management

Clone the project

Expand All @@ -25,24 +25,12 @@ Install dependencies
npm install
```

or (recommended)

```bash
yarn install
```

Start the server

```bash
npm run dev
```

or (recommended)

```bash
yarn dev
```

## Developing

### Frontend Built With
Expand Down Expand Up @@ -94,24 +82,12 @@ To automatically set correct node version:
npm install
```

or (recommended)

```bash
yarn install
```

2. Launch Server

```bash
npm run dev
```

or (recommended)

```bash
yarn dev
```

#### Using Nix and Direnv

1. Get [Nix](https://nixos.org/download).
Expand All @@ -135,10 +111,10 @@ direnv allow
5. Run project

```sh
yarn dev
npm run dev
```

_To update the yarn.lock file after changes are made, run `nix develop .#js` for a developer shell with correct yarn/nodejs versions_
_To update the package-lock.json file after changes are made, run `nix develop .#js` for a developer shell with correct nodejs version_

## After development

Expand All @@ -152,7 +128,7 @@ We distinguish two types of users:
#### without a connected wallet who can:

1. See the governance actions along with their details and the number of votes
<!-- 2. See the list of DReps. -->
2. See the list of DReps.

#### with connected wallet who can:

Expand All @@ -162,4 +138,4 @@ We distinguish two types of users:
4. Register as DRrep or Direct Voter.
5. Vote for the Governance Actions of his or her choice (if the user is registered).
6. Create their own Governance Action.
<!-- 7. See the list of DReps from which they can submit their vote. -->
7. See the list of DReps from which they can submit their vote.
26 changes: 19 additions & 7 deletions govtool/frontend/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{ pkgs ? import <nixpkgs> {}
, incl
, VITE_APP_ENV ? "development"
, VITE_BASE_URL ? "http://localhost"
, VITE_IS_DEV ? "true"
, VITE_METADATA_API_URL ? "http://localhost"
, VITE_GTM_ID ? ""
, VITE_IS_DEV ? "true"
, VITE_NETWORK_FLAG ? "0"
, VITE_SENTRY_DSN ? ""
, VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED ? ""
, VITE_USERSNAP_SPACE_API_KEY ? ""
, VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED ? "true"
, VITE_PDF_API_URL ? ""
, VITE_IPFS_GATEWAY ? "https://ipfs.io/ipfs/"
, VITE_IPFS_PROJECT_ID ? ""
, CARDANO_NETWORK ? "sanchonet"
}:

let
VITE_NETWORK_FLAG = if CARDANO_NETWORK == "mainnet" then "1" else "0";
frontendSrc = incl ./. [
Expand All @@ -25,16 +32,19 @@ let
src = frontendSrc;
packageJSON = ./package.json;
yarnLock = ./yarn.lock;
nodejs = pkgs.nodejs_18;
nodejs = pkgs.nodejs_20;
};

staticSite = pkgs.stdenv.mkDerivation {
name = "govtool-website";
src = frontendSrc;
buildInputs = [(pkgs.yarn.override { nodejs = pkgs.nodejs_18;}) nodeModules];
inherit VITE_BASE_URL VITE_IS_DEV VITE_GTM_ID VITE_SENTRY_DSN VITE_NETWORK_FLAG VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED VITE_PDF_API_URL;
buildInputs = [ (pkgs.yarn.override { nodejs = pkgs.nodejs_20;}) nodeModules ];
inherit VITE_APP_ENV VITE_BASE_URL VITE_METADATA_API_URL VITE_GTM_ID VITE_NETWORK_FLAG VITE_SENTRY_DSN VITE_USERSNAP_SPACE_API_KEY VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED VITE_PDF_API_URL VITE_IPFS_GATEWAY VITE_IPFS_PROJECT_ID;
buildPhase = ''
cp -R ${nodeModules}/libexec/@govtool/frontend/node_modules node_modules
yarn postinstall
# Yarn links a vite transitive dependency version to
# `node_modules/.bin` rather than the dev declared vite version which then breaks
# the build if we don't do this.
Expand All @@ -47,6 +57,7 @@ let
mv dist $out
'';
};

webserver = { staticSiteRoot ? staticSite, backendUrl ? "http://localhost:9999" }: let
nginxConfig = pkgs.writeText "govtool-nginx.conf" ''
daemon off;
Expand All @@ -72,8 +83,9 @@ let
echo "Starting nginx from site root ${staticSiteRoot}... at http://localhost:8081"
${pkgs.nginx}/bin/nginx -c ${nginxConfig} -e /dev/stderr
'';

devShell = pkgs.mkShell {
buildInputs = [pkgs.nodejs_18 pkgs.yarn];
buildInputs = [ pkgs.nodejs_20 pkgs.yarn ];
shellHook = ''
function warn() { tput setaf $2; echo "$1"; tput sgr0; }
Expand All @@ -82,7 +94,7 @@ let
warn "This is a frontend development shell." 4
warn "Read the ${./README.md} to get more info about this module." 8
rm -rf ./node_modules
ln -s ${nodeModules.out}/libexec/@govtool/frontend/node_modules ./node_modules
ln -s ${nodeModules.out}/node_modules ./node_modules
'';
};
in staticSite // { inherit nodeModules devShell staticSite webserver; }
Loading

0 comments on commit 7092f02

Please sign in to comment.