diff --git a/nixos/modules/services/networking/blockbook-frontend.nix b/nixos/modules/services/networking/blockbook-frontend.nix index 504c98e9ab8e..6200a098c34a 100644 --- a/nixos/modules/services/networking/blockbook-frontend.nix +++ b/nixos/modules/services/networking/blockbook-frontend.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let eachBlockbook = config.services.blockbook-frontend; @@ -10,24 +7,24 @@ let options = { - enable = mkEnableOption "blockbook-frontend application"; + enable = lib.mkEnableOption "blockbook-frontend application"; - package = mkPackageOption pkgs "blockbook" { }; + package = lib.mkPackageOption pkgs "blockbook" { }; - user = mkOption { - type = types.str; + user = lib.mkOption { + type = lib.types.str; default = "blockbook-frontend-${name}"; description = "The user as which to run blockbook-frontend-${name}."; }; - group = mkOption { - type = types.str; + group = lib.mkOption { + type = lib.types.str; default = "${config.user}"; description = "The group as which to run blockbook-frontend-${name}."; }; - certFile = mkOption { - type = types.nullOr types.path; + certFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; example = "/etc/secrets/blockbook-frontend-${name}/certFile"; description = '' @@ -36,15 +33,15 @@ let ''; }; - configFile = mkOption { - type = with types; nullOr path; + configFile = lib.mkOption { + type = with lib.types; nullOr path; default = null; example = "${config.dataDir}/config.json"; description = "Location of the blockbook configuration file."; }; - coinName = mkOption { - type = types.str; + coinName = lib.mkOption { + type = lib.types.str; default = "Bitcoin"; description = '' See @@ -52,68 +49,68 @@ let ''; }; - cssDir = mkOption { - type = types.path; + cssDir = lib.mkOption { + type = lib.types.path; default = "${config.package}/share/css/"; - defaultText = literalExpression ''"''${package}/share/css/"''; - example = literalExpression ''"''${dataDir}/static/css/"''; + defaultText = lib.literalExpression ''"''${package}/share/css/"''; + example = lib.literalExpression ''"''${dataDir}/static/css/"''; description = '' Location of the dir with {file}`main.css` CSS file. By default, the one shipped with the package is used. ''; }; - dataDir = mkOption { - type = types.path; + dataDir = lib.mkOption { + type = lib.types.path; default = "/var/lib/blockbook-frontend-${name}"; description = "Location of blockbook-frontend-${name} data directory."; }; - debug = mkOption { - type = types.bool; + debug = lib.mkOption { + type = lib.types.bool; default = false; description = "Debug mode, return more verbose errors, reload templates on each request."; }; - internal = mkOption { - type = types.nullOr types.str; + internal = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = ":9030"; description = "Internal http server binding `[address]:port`."; }; - messageQueueBinding = mkOption { - type = types.str; + messageQueueBinding = lib.mkOption { + type = lib.types.str; default = "tcp://127.0.0.1:38330"; description = "Message Queue Binding `address:port`."; }; - public = mkOption { - type = types.nullOr types.str; + public = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = ":9130"; description = "Public http server binding `[address]:port`."; }; rpc = { - url = mkOption { - type = types.str; + url = lib.mkOption { + type = lib.types.str; default = "http://127.0.0.1"; description = "URL for JSON-RPC connections."; }; - port = mkOption { - type = types.port; + port = lib.mkOption { + type = lib.types.port; default = 8030; description = "Port for JSON-RPC connections."; }; - user = mkOption { - type = types.str; + user = lib.mkOption { + type = lib.types.str; default = "rpc"; description = "Username for JSON-RPC connections."; }; - password = mkOption { - type = types.str; + password = lib.mkOption { + type = lib.types.str; default = "rpc"; description = '' RPC password for JSON-RPC connections. @@ -122,8 +119,8 @@ let ''; }; - passwordFile = mkOption { - type = types.nullOr types.path; + passwordFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; description = '' File containing password of the RPC user. @@ -132,24 +129,24 @@ let }; }; - sync = mkOption { - type = types.bool; + sync = lib.mkOption { + type = lib.types.bool; default = true; description = "Synchronizes until tip, if together with zeromq, keeps index synchronized."; }; - templateDir = mkOption { - type = types.path; + templateDir = lib.mkOption { + type = lib.types.path; default = "${config.package}/share/templates/"; - defaultText = literalExpression ''"''${package}/share/templates/"''; - example = literalExpression ''"''${dataDir}/templates/static/"''; + defaultText = lib.literalExpression ''"''${package}/share/templates/"''; + example = lib.literalExpression ''"''${dataDir}/templates/static/"''; description = "Location of the HTML templates. By default, ones shipped with the package are used."; }; - extraConfig = mkOption { - type = types.attrs; + extraConfig = lib.mkOption { + type = lib.types.attrs; default = {}; - example = literalExpression '' { + example = lib.literalExpression '' { "alternative_estimate_fee" = "whatthefee-disabled"; "alternative_estimate_fee_params" = "{\"url\": \"https://whatthefee.io/data.json\", \"periodSeconds\": 60}"; "fiat_rates" = "coingecko"; @@ -174,8 +171,8 @@ let ''; }; - extraCmdLineOptions = mkOption { - type = types.listOf types.str; + extraCmdLineOptions = lib.mkOption { + type = lib.types.listOf lib.types.str; default = []; example = [ "-workers=1" "-dbcache=0" "-logtosderr" ]; description = '' @@ -190,8 +187,8 @@ in # interface options = { - services.blockbook-frontend = mkOption { - type = types.attrsOf (types.submodule blockbookOpts); + services.blockbook-frontend = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule blockbookOpts); default = {}; description = "Specification of one or more blockbook-frontend instances."; }; @@ -199,10 +196,10 @@ in # implementation - config = mkIf (eachBlockbook != {}) { + config = lib.mkIf (eachBlockbook != {}) { - systemd.services = mapAttrs' (blockbookName: cfg: ( - nameValuePair "blockbook-frontend-${blockbookName}" ( + systemd.services = lib.mapAttrs' (blockbookName: cfg: ( + lib.nameValuePair "blockbook-frontend-${blockbookName}" ( let configFile = if cfg.configFile != null then cfg.configFile else pkgs.writeText "config.conf" (builtins.toJSON ( { @@ -220,7 +217,7 @@ in preStart = '' ln -sf ${cfg.templateDir} ${cfg.dataDir}/static/ ln -sf ${cfg.cssDir} ${cfg.dataDir}/static/ - ${optionalString (cfg.rpc.passwordFile != null && cfg.configFile == null) '' + ${lib.optionalString (cfg.rpc.passwordFile != null && cfg.configFile == null) '' CONFIGTMP=$(mktemp) ${pkgs.jq}/bin/jq ".rpc_pass = \"$(cat ${cfg.rpc.passwordFile})\"" ${configFile} > $CONFIGTMP mv $CONFIGTMP ${cfg.dataDir}/${blockbookName}-config.json @@ -237,11 +234,11 @@ in "-blockchaincfg=${configFile}" } \ -datadir=${cfg.dataDir} \ - ${optionalString (cfg.sync != false) "-sync"} \ - ${optionalString (cfg.certFile != null) "-certfile=${toString cfg.certFile}"} \ - ${optionalString (cfg.debug != false) "-debug"} \ - ${optionalString (cfg.internal != null) "-internal=${toString cfg.internal}"} \ - ${optionalString (cfg.public != null) "-public=${toString cfg.public}"} \ + ${lib.optionalString (cfg.sync != false) "-sync"} \ + ${lib.optionalString (cfg.certFile != null) "-certfile=${toString cfg.certFile}"} \ + ${lib.optionalString (cfg.debug != false) "-debug"} \ + ${lib.optionalString (cfg.internal != null) "-internal=${toString cfg.internal}"} \ + ${lib.optionalString (cfg.public != null) "-public=${toString cfg.public}"} \ ${toString cfg.extraCmdLineOptions} ''; Restart = "on-failure"; @@ -251,23 +248,23 @@ in } ) )) eachBlockbook; - systemd.tmpfiles.rules = flatten (mapAttrsToList (blockbookName: cfg: [ + systemd.tmpfiles.rules = lib.flatten (lib.mapAttrsToList (blockbookName: cfg: [ "d ${cfg.dataDir} 0750 ${cfg.user} ${cfg.group} - -" "d ${cfg.dataDir}/static 0750 ${cfg.user} ${cfg.group} - -" ]) eachBlockbook); - users.users = mapAttrs' (blockbookName: cfg: ( - nameValuePair "blockbook-frontend-${blockbookName}" { + users.users = lib.mapAttrs' (blockbookName: cfg: ( + lib.nameValuePair "blockbook-frontend-${blockbookName}" { name = cfg.user; group = cfg.group; home = cfg.dataDir; isSystemUser = true; })) eachBlockbook; - users.groups = mapAttrs' (instanceName: cfg: ( - nameValuePair "${cfg.group}" { })) eachBlockbook; + users.groups = lib.mapAttrs' (instanceName: cfg: ( + lib.nameValuePair "${cfg.group}" { })) eachBlockbook; }; - meta.maintainers = with maintainers; [ _1000101 ]; + meta.maintainers = with lib.maintainers; [ _1000101 ]; }