Skip to content

Commit

Permalink
feat(faucet): add nixos module (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen authored Sep 29, 2023
2 parents 64b67d2 + b6a0018 commit 55f0f0f
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
3 changes: 3 additions & 0 deletions faucet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Faucet

This implements a build process for [cosmos-faucet](https://github.com/okp4/cosmos-faucet) and a nixosModule for easy deployments.
142 changes: 142 additions & 0 deletions faucet/faucet.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{ self, ... }: {
perSystem = { self', pkgs, ... }:
let
faucet = pkgs.buildGoModule {
name = "faucet";
vendorSha256 = "sha256-LDu9GSgMsCHTk5K7hsEhLg36SatUpgQZrOdEvuPSM84=";
meta.mainProgram = "cosmos-faucet";
version = "2.0.0";
src = pkgs.fetchFromGitHub {
name = "faucet";
owner = "okp4";
repo = "cosmos-faucet";
rev = "18ac81747e6ea9503b13b65ec01388c498caaa9c";
sha256 = "sha256-re7c0itkTmDwuvuwluLxhrpAyngzMhp9Ec9DuOGlvfc=";
};
};
in
{
packages = {
inherit faucet;

faucet-image = pkgs.dockerTools.buildLayeredImage {
name = "faucet";
contents = [ pkgs.coreutils-full pkgs.cacert self'.packages.faucet ];
config = {
Entrypoint = [ (pkgs.lib.getExe self'.packages.faucet) ];
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
};
};
};
};

flake.nixosModules.faucet = { lib, pkgs, config, ... }:
with lib;
let cfg = config.services.faucet;
in {
options.services.faucet = {
enable = mkEnableOption "Faucet service";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.system}.faucet;
};
home = mkOption {
type = types.str;
default = "";
description = "the home folder";
};
mnemonic = mkOption {
type = types.str;
default = "";
description = "wallet mnemonic";
};
address = mkOption {
type = types.str;
default = ":8080";
description = "graphql api address";
};
captcha-secret = mkOption {
type = types.str;
default = "";
description = "if set, a captcha is required";
};
captcha-verify-url = mkOption {
type = types.str;
default = "https://www.google.com/recaptcha/api/siteverify";
description = "Captcha verify URL";
};
chain-id = mkOption {
type = types.str;
default = "union-testnet-3";
};
denom = mkOption {
type = types.str;
default = "muno";
};
memo = mkOption {
type = types.str;
default = "Join the Union";
};
prefix = mkOption {
type = types.str;
default = "union1";
};
amount-send = mkOption {
type = types.int;
default = 1;
};
grpc-address = mkOption {
type = types.str;
default = "127.0.0.1:9090";
description = "grpc address of the node";
};
extra-args = mkOption {
type = types.str;
default = "";
description = "extra arguments to pass to the command";
};
};

config = mkIf cfg.enable {
systemd.services.faucet =
let
faucet-systemd-script = pkgs.writeShellApplication {
name = "faucet-systemd";
runtimeInputs = [ pkgs.coreutils cfg.package ];
text =
let
captcha = if cfg.captcha-secret != "" then "--captcha --captcha-secret '${cfg.captcha-secret}'" else "";
captcha-verify-url = if cfg.captcha-verify-url != "" then "--captcha-verify-url '${cfg.captcha-verify-url}'" else "";
in
''
${pkgs.lib.getExe cfg.package} \
--chain-id '${cfg.chain-id}' \
--denom '${cfg.denom}' \
--memo '${cfg.memo}' \
--prefix '${cfg.prefix}' \
start \
${captcha} \
${captcha-verify-url} \
--address '${cfg.address}' \
--amount-send ${toString cfg.amount-send} \
--grpc-address ${cfg.grpc-address} \
--mnemonic '${cfg.mnemonic}' ${cfg.extra-args}
'';
};
in
{
wantedBy = [ "multi-user.target" ];
description = "Faucet";
serviceConfig = {
Type = "simple";
ExecStart = pkgs.lib.getExe faucet-systemd-script;
Restart = mkForce "always";
};
environment = {
HOME = cfg.home;
};
};
};
};

}
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
./e2e/all-tests.nix
./e2e/e2e.nix
./lib/unionlabs/fuzz/default.nix
./faucet/faucet.nix
treefmt-nix.flakeModule
];

Expand Down

0 comments on commit 55f0f0f

Please sign in to comment.