Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Initial version of the faucet #1

Merged
merged 2 commits into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions default.nix
@@ -0,0 +1 @@
let pkgs = import ./nix {}; in pkgs.packages
25 changes: 25 additions & 0 deletions jormugandr_api.js
@@ -0,0 +1,25 @@
const axios = require("axios");

async function getAccountStatus(hostUrl, accountId) {
const response = await axios.get(`${hostUrl}/account/${accountId}`);
return response.data;
}

async function getNodeSettings(hostUrl) {
const response = await axios.get(`${hostUrl}/settings`);
return response.data;
}

async function postMsg(hostUrl, msg) {
axios.post(`${hostUrl}/message`, msg, {
headers: {
"content-type": "application/octet-stream"
}
});
}

module.exports = {
getAccountStatus,
getNodeSettings,
postMsg
};
23 changes: 23 additions & 0 deletions nix/default.nix
@@ -0,0 +1,23 @@
{ sources ? import ./sources.nix }:
with {
mozilla-overlay = import sources.nixpkgs-mozilla;

overlay = self: super: {
inherit (import sources.niv { }) niv;
nodejs = super.nodejs-slim-11_x;
inherit (import sources.yarn2nix { pkgs = self; }) mkYarnPackage yarn2nix;
packages = self.callPackages ./packages.nix { };
iohkNix = import sources.iohk-nix {
application = "jormungandr-faucet";
nixpkgsOverride = self;
};

rustc = super.latest.rustChannels.stable.rust.override {
targets = [ "wasm32-unknown-unknown" ];
};
};
};
import sources.nixpkgs {
overlays = [ mozilla-overlay overlay ];
config = { };
}
3 changes: 3 additions & 0 deletions nix/nixos/default.nix
@@ -0,0 +1,3 @@
{
imports = import ./module-list.nix;
}
38 changes: 38 additions & 0 deletions nix/nixos/jormungandr-faucet-options.nix
@@ -0,0 +1,38 @@
{ config, lib, pkgs, ... }:

let
jormungandr-faucet = (import ../. { }).packages.jormungandr-faucet;
cfg = config.services.jormungandr-faucet;
inherit (lib) mkOption types;
in {
options.services.jormungandr-faucet = {
package = mkOption {
type = types.package;
default = (import ../. {}).packages.jormungandr-faucet-js;
defaultText = "jormungandr-faucet";
description = ''
The jormungandr-faucet package to be used
'';
};

jormungandrApi = mkOption {
type = types.str;
default = "http://localhost:8443/api/v0";
};

secretKeyPath = mkOption {
type = types.str;
default = "/var/lib/private/jormungandr-faucet/private.key";
};

port = mkOption {
type = types.port;
default = 3008;
};

lovelacesToGive = mkOption {
type = types.int;
default = 1;
};
};
}
49 changes: 49 additions & 0 deletions nix/nixos/jormungandr-faucet-service.nix
@@ -0,0 +1,49 @@
{ config, lib, pkgs, ... }:

let
cfg = config.services.jormungandr-faucet;
inherit (lib) mkOption types mkIf;
in {
options.services.jormungandr-faucet.enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable the Jormungandr Faucet, an HTTP service that talks to Jormungandr
to spread ADA love.
'';
};

config = mkIf cfg.enable {
systemd.services.jormungandr-faucet = {
description = "jormungandr-faucet daemon";
after = [ "jormungandr.service"];
wantedBy = [ "multi-user.target" ];

serviceConfig = {
DynamicUser = true;
Restart = "always";
User = "jormungandr-faucet";
RestartSec = "10s";
StartLimitBurst = 50;
StateDirectory = "jormungandr-faucet";
};

environment = {
JORMUNGANDR_API = cfg.jormungandrApi;
PORT = toString cfg.port;
LOVELACES_TO_GIVE = toString cfg.lovelacesToGive;
};

serviceConfig.PermissionsStartOnly = true;
preStart = ''
ls -la /var/lib
cp /var/lib/keys/jormungandr-faucet.key /var/lib/private/jormungandr-faucet/private.key
'';

script = ''
export SECRET_KEY="$(< /var/lib/private/jormungandr-faucet/private.key)"
${cfg.package}/bin/faucet
'';
};
};
}
4 changes: 4 additions & 0 deletions nix/nixos/module-list.nix
@@ -0,0 +1,4 @@
[
./jormungandr-faucet-options.nix
./jormungandr-faucet-service.nix
]
19 changes: 19 additions & 0 deletions nix/nixos/tests/default.nix
@@ -0,0 +1,19 @@
{ pkgs, supportedSystems ? [ "x86_64-linux" ] }:

let
inherit (pkgs) lib;
inherit (lib) genAttrs hydraJob;

forAllSystems = genAttrs supportedSystems;

importTest = fn: args: system:
let
imported = import fn;
test = import (pkgs.path + "/nixos/tests/make-test.nix") imported;
in test ({ inherit system; } // args);

callTest = fn: args:
forAllSystems (system: hydraJob (importTest fn args system));
in rec {
simple = callTest ./simple.nix { };
}
29 changes: 29 additions & 0 deletions nix/nixos/tests/simple.nix
@@ -0,0 +1,29 @@
{ pkgs , ... }:

{
name = "jormungandr-faucet-test";
nodes = {
machine = { config, pkgs, ... }: {
imports = [
../.
];
services = {
jormungandr-faucet = {
enable = true;
};

jormungandr = {
enable = true;
};
};
};
};
testScript = ''
startAll
$machine->execute("mkdir -p /var/lib/keys");
$machine->execute("echo SECRET_KEY=key > /var/lib/keys/jormungandr-faucet.key");
$machine->waitForUnit("jormungandr-faucet.service");
$machine->waitForOpenPort(3008);
'';

}
12 changes: 12 additions & 0 deletions nix/packages.nix
@@ -0,0 +1,12 @@
{ stdenv, mkYarnPackage, yarn2nix, callPackage }:

{
jormungandr-faucet-js = mkYarnPackage {
name = "jormungandr-faucet";
src = ../.;
packageJSON = ../package.json;
yarnLock = ../yarn.lock;
};

jormungandr-faucet-tests = callPackage ./nixos/tests {};
}
74 changes: 74 additions & 0 deletions nix/sources.json
@@ -0,0 +1,74 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add iohk-nix (see iohk-ops for how). We can put genesis files/hashes and any other env specific data in there that we can use to key off of. Granted, we're using iohk-ops here so it's not 100% needed but could be useful for end users wanting to run a faucet without iohk-ops. See cardanoLib in there. We'd want to add a jormungandr_testnet attribute with env specific stuff in there.

"gitignore": {
"branch": "master",
"description": "Nix function for filtering local git sources",
"homepage": "",
"owner": "hercules-ci",
"repo": "gitignore",
"rev": "31860d428b0d6cc03fb7ca9eca8b99dc3750ee5e",
"sha256": "1km1nryf41f0xc7n632vqc8p7wgx5lz7nmz3qm5zj1dr6260jk3m",
"type": "tarball",
"url": "https://github.com/hercules-ci/gitignore/archive/31860d428b0d6cc03fb7ca9eca8b99dc3750ee5e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"iohk-nix": {
"branch": "jormungandr-master",
"description": "nix scripts shared across projects",
"homepage": null,
"owner": "input-output-hk",
"repo": "iohk-nix",
"rev": "689cf245da41f5178246802d3318ca610529ed56",
"sha256": "0fn3p94iblgi366vr6773h8i6i7b7p1gjcsb7005rsf6z2h71khb",
"type": "tarball",
"url": "https://github.com/input-output-hk/iohk-nix/archive/689cf245da41f5178246802d3318ca610529ed56.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "c57098815e542b3a345d6f3fa821ea87c75b751d",
"sha256": "0q4xjg2nkzcvh62m92d1d2xzxf6xhfr512yndaklqp6qy8vz29jx",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/c57098815e542b3a345d6f3fa821ea87c75b751d.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixpkgs-unstable",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs-channels",
"rev": "e19054ab3cd5b7cc9a01d0efc71c8fe310541065",
"sha256": "0b92yhkj3pq58svyrx7jp0njhaykwr29079izqn6qs638v8zvhl2",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs-channels/archive/e19054ab3cd5b7cc9a01d0efc71c8fe310541065.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-mozilla": {
"branch": "master",
"description": "mozilla related nixpkgs (extends nixos/nixpkgs repo)",
"homepage": null,
"owner": "mozilla",
"repo": "nixpkgs-mozilla",
"rev": "b52a8b7de89b1fac49302cbaffd4caed4551515f",
"sha256": "1np4fmcrg6kwlmairyacvhprqixrk7x9h89k813safnlgbgqwrqb",
"type": "tarball",
"url": "https://github.com/mozilla/nixpkgs-mozilla/archive/b52a8b7de89b1fac49302cbaffd4caed4551515f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"yarn2nix": {
"branch": "master",
"description": "Generate nix expressions from a yarn.lock file",
"homepage": null,
"owner": "moretea",
"repo": "yarn2nix",
"rev": "7effadded30d611a460e212cb73614506ef61c52",
"sha256": "0r4ww3mjx3n7bn2v1iav33liyphyr2x005ak6644qs15bp4bn3cr",
"type": "tarball",
"url": "https://github.com/moretea/yarn2nix/archive/7effadded30d611a460e212cb73614506ef61c52.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}