Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NixOS module tweaks #115

Merged
merged 11 commits into from
Aug 18, 2023
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
5 changes: 0 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
91 changes: 39 additions & 52 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./.;
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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 = ''
Expand All @@ -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 = ''
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
};
};
}
12 changes: 8 additions & 4 deletions nixos-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +52,7 @@ in {
};
port = lib.mkOption {
type = lib.types.port;
default = 3000;
default = 5432;
};
user = lib.mkOption {
type = lib.types.str;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{ }
}:
let
nodejs = pkgs.nodejs-16_x;
nodejs = pkgs.nodejs_18;
in
pkgs.stdenv.mkDerivation {
name = "blockfrost-backend";
Expand Down
Loading