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 }} 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/CHANGELOG.md b/CHANGELOG.md index 62b511dc..a7b40d33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Flake now exports NixOS module + +### Changed - support defining a postgres password in config or env ### Fixed -- 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 diff --git a/default.nix b/default.nix index 4e28fd87..f1b37a0d 100644 --- a/default.nix +++ b/default.nix @@ -11,26 +11,11 @@ , 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); - # 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 = '' 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 ]; }; }; } diff --git a/nixos-module.nix b/nixos-module.nix index cca3d62d..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; @@ -51,7 +52,7 @@ in { }; port = lib.mkOption { type = lib.types.port; - default = 3000; + default = 5432; }; user = lib.mkOption { type = lib.types.str; @@ -110,13 +111,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 = { + 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; 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";