From 91b04145b358b20785f4ef56ec4a7da8b39647c4 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:12:54 +0200 Subject: [PATCH 01/10] nixos-module: switch dbsync port from 3000 to 5432 --- nixos-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos-module.nix b/nixos-module.nix index cca3d62d..5ae0f47e 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -51,7 +51,7 @@ in { }; port = lib.mkOption { type = lib.types.port; - default = 3000; + default = 5432; }; user = lib.mkOption { type = lib.types.str; From 792df62a2c15c26953d3269626e75843ebfd2387 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:13:17 +0200 Subject: [PATCH 02/10] nixos-module: rename service to blockforst-backend-ryo --- nixos-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos-module.nix b/nixos-module.nix index 5ae0f47e..df7f5efa 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -113,7 +113,7 @@ in { "d /etc/pm2 770 ${cfg.user} ${cfg.group}" ]; - systemd.services.blockfrost = { + systemd.services.blockfrost-backend-ryo = { inherit (cfg) requires; wantedBy = [ "multi-user.target" ]; environment.NODE_CONFIG_RUNTIME_JSON = settingsFormat.generate "blockfrost-settings.json" cfg.settings; From 8f7373b486a5fc77a514050d8e3171adc3207ce1 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:16:15 +0200 Subject: [PATCH 03/10] nixos-module: set HOME to /var/lib/blockfrost-backend-ryo --- nixos-module.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nixos-module.nix b/nixos-module.nix index df7f5efa..9e5fd877 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -110,13 +110,16 @@ in { users.groups.blockfrost = lib.mkIf (cfg.group == "blockfrost") { }; systemd.tmpfiles.rules = [ - "d /etc/pm2 770 ${cfg.user} ${cfg.group}" + "d /var/lib/blockfrost-backend-ryo 770 ${cfg.user} ${cfg.group}" ]; systemd.services.blockfrost-backend-ryo = { inherit (cfg) requires; wantedBy = [ "multi-user.target" ]; - environment.NODE_CONFIG_RUNTIME_JSON = settingsFormat.generate "blockfrost-settings.json" cfg.settings; + environment = { + NODE_CONFIG_RUNTIME_JSON = settingsFormat.generate "blockfrost-settings.json" cfg.settings; + HOME = "/var/lib/blockfrost-backend-ryo"; + }; serviceConfig = { ExecStart = "${cfg.package}/bin/blockfrost-backend-ryo"; Group = cfg.group; From 54a6bcfcae63dbaa087b1b2243a805703ebebd7c Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:23:30 +0200 Subject: [PATCH 04/10] nixos-module: set default package --- nixos-module.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos-module.nix b/nixos-module.nix index 9e5fd877..07430514 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -7,6 +7,7 @@ in { enable = lib.mkEnableOption "Blockfrost"; package = lib.mkOption { type = lib.types.package; + default = pkgs.blockfrost-backend-ryo; }; stateDir = lib.mkOption { type = lib.types.path; From 3ab58e8657ae8b4eb644d13a56912d7d0f4c38da Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:24:22 +0200 Subject: [PATCH 05/10] chore(changelog): NixOS module, nixpkgs, nodejs --- CHANGELOG.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea719e5..6fe7b9d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Fixed +### Added + +- Flake now exports NixOS module + +### Changed -- bump blockfrost-utils to 2.6.2 +- nixpkgs updated to latest `nixos-23.05` +- NodeJS updated to `18.16.1` +- blockfrost-utils updated to `2.6.2` ## [1.6.0] - 2023-06-28 From c5600ca30c3e27e2c3b4fcb4983a51fb8afecd99 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:28:59 +0200 Subject: [PATCH 06/10] switch integration tests to use NixOS module --- .gitlab-ci.yml | 5 --- default.nix | 89 +++++++++++++++++++++----------------------------- 2 files changed, 38 insertions(+), 56 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4d149d1c..7677018d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,3 @@ -before_script: - - cp -v $BUILD_CONFIG_FILE_PREVIEW_YAML config/preview.yaml - - cp -v $BUILD_CONFIG_FILE_PREPROD_YAML config/preprod.yaml - - cp -v $BUILD_CONFIG_FILE_MAINNET_YAML config/mainnet.yaml - stages: - prebuild - build diff --git a/default.nix b/default.nix index 4e28fd87..2dd4a7e7 100644 --- a/default.nix +++ b/default.nix @@ -16,21 +16,6 @@ let testing = import (pkgs.path + "/nixos/lib/testing-python.nix") { inherit system; }; packageJSON = builtins.fromJSON (builtins.readFile ./package.json); - # Use this if you want to override config/default.yaml - /* - blockfrost-backend-test-config = pkgs.writeText "default.yaml" '' - server: - port: 3000 - debug: true - dbSync: - host: "cdbsync-testnet.mydomain.com" - user: "cexplorer" - database: "cdbsync" - network: "mainnet" - tokenRegistryUrl: "https://tokens.cardano.org" - ''; - */ - blockfrost-backend-ryo = let src = pkgs.lib.cleanSource ./.; @@ -77,23 +62,23 @@ in name = "blockfrost-backend-ryo-test-mainnet"; nodes.machine = { + imports = [ ./nixos-module.nix ]; # We have to increase memsize, otherwise we will get error: # "Kernel panic - not syncing: Out of memory: compulsory panic_on_oom" virtualisation.memorySize = 4096; - # Backend service - systemd.services.blockfrost-backend-ryo = { - wantedBy = [ "multi-user.target" ]; - script = "${blockfrost-backend-ryo}/bin/blockfrost-backend-ryo"; - environment = { - # Use config file from repository - NODE_CONFIG_RUNTIME_JSON = "${blockfrost-backend-ryo}/libexec/source/config/mainnet.yaml"; - /* - # Use this if you want to override config/default.yaml - NODE_CONFIG_RUNTIME_JSON = "${blockfrost-backend-test-config}"; - */ + + services.blockfrost = { + enable = true; + package = blockfrost-backend-ryo; + settings = { + dbSync = { + host = builtins.getEnv "DBSYNC_HOST_MAINNET"; + user = "csyncdb"; + database = "csyncdb"; + }; + tokenRegistryUrl = builtins.getEnv "TOKEN_REGISTRY_URL_MAINNET"; }; }; - }; testScript = '' @@ -112,23 +97,24 @@ in name = "blockfrost-backend-ryo-test-preview"; nodes.machine = { + imports = [ ./nixos-module.nix ]; # We have to increase memsize, otherwise we will get error: # "Kernel panic - not syncing: Out of memory: compulsory panic_on_oom" virtualisation.memorySize = 4096; - # Backend service - systemd.services.blockfrost-backend-ryo = { - wantedBy = [ "multi-user.target" ]; - script = "${blockfrost-backend-ryo}/bin/blockfrost-backend-ryo"; - environment = { - # Use config file from repository - NODE_CONFIG_RUNTIME_JSON = "${blockfrost-backend-ryo}/libexec/source/config/preview.yaml"; - /* - # Use this if you want to override config/default.yaml - NODE_CONFIG_RUNTIME_JSON = "${blockfrost-backend-test-config}"; - */ + + services.blockfrost = { + enable = true; + package = blockfrost-backend-ryo; + settings = { + dbSync = { + host = builtins.getEnv "DBSYNC_HOST_PREVIEW"; + user = "csyncdb"; + database = "csyncdb"; + }; + network = "preview"; + tokenRegistryUrl = builtins.getEnv "TOKEN_REGISTRY_URL_TESTNETS"; }; }; - }; testScript = '' @@ -147,23 +133,24 @@ in name = "blockfrost-backend-ryo-test-preprod"; nodes.machine = { + imports = [ ./nixos-module.nix ]; # We have to increase memsize, otherwise we will get error: # "Kernel panic - not syncing: Out of memory: compulsory panic_on_oom" virtualisation.memorySize = 4096; - # Backend service - systemd.services.blockfrost-backend-ryo = { - wantedBy = [ "multi-user.target" ]; - script = "${blockfrost-backend-ryo}/bin/blockfrost-backend-ryo"; - environment = { - # Use config file from repository - NODE_CONFIG_RUNTIME_JSON = "${blockfrost-backend-ryo}/libexec/source/config/preprod.yaml"; - /* - # Use this if you want to override config/default.yaml - NODE_CONFIG_RUNTIME_JSON = "${blockfrost-backend-test-config}"; - */ + + services.blockfrost = { + enable = true; + package = blockfrost-backend-ryo; + settings = { + dbSync = { + host = builtins.getEnv "DBSYNC_HOST_PREPROD"; + user = "csyncdb"; + database = "csyncdb"; + }; + network = "preprod"; + tokenRegistryUrl = builtins.getEnv "TOKEN_REGISTRY_URL_TESTNETS"; }; }; - }; testScript = '' From 4d7c27795fb56b68e3595ffc957c1c55f4b7fa1f Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 12:32:39 +0200 Subject: [PATCH 07/10] shell.nix: nodejs-18 --- shell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index cdfae985..14d73db1 100644 --- a/shell.nix +++ b/shell.nix @@ -10,7 +10,7 @@ { } }: let - nodejs = pkgs.nodejs-16_x; + nodejs = pkgs.nodejs_18; in pkgs.stdenv.mkDerivation { name = "blockfrost-backend"; From 0dafc719422adf1270a27e170ac028cf76c256e5 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 13:48:44 +0200 Subject: [PATCH 08/10] default.nix: nodejs-18_x -> nodejs_18 former is an alias. --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 2dd4a7e7..f1b37a0d 100644 --- a/default.nix +++ b/default.nix @@ -11,7 +11,7 @@ , system ? builtins.currentSystem }: let - nodejs = pkgs.nodejs-18_x; + nodejs = pkgs.nodejs_18; nodePackages = nodejs.pkgs; testing = import (pkgs.path + "/nixos/lib/testing-python.nix") { inherit system; }; packageJSON = builtins.fromJSON (builtins.readFile ./package.json); From 5be468485b484f634c1b7d5c65b3b6fa60a66c43 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Tue, 11 Jul 2023 17:13:06 +0200 Subject: [PATCH 09/10] ci: bump node-version to 18.x --- .github/workflows/CI.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 6c33fc93..9bc818b2 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x] + node-version: [18.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From 4c62fe3761c1323f8ad81ca509ea706c35c4cb4e Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Fri, 14 Jul 2023 13:06:54 +0200 Subject: [PATCH 10/10] flake: pass overlay instead of setting package --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 3fc59d63..92e7ce26 100644 --- a/flake.nix +++ b/flake.nix @@ -60,7 +60,7 @@ }; nixosModules.default = {pkgs, ...}: { imports = [ ./nixos-module.nix ]; - services.blockfrost.package = self.packages.${pkgs.system}.blockfrost-backend-ryo; + nixpkgs.overlays = [ self.overlays.default ]; }; }; }