Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions nixos/modules/misc/ids.nix
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
rpc = 271;
geoip = 272;
fcron = 273;
bitcoin = 275;
dash = 276;
parity = 277;
monero = 278;

# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!

Expand Down Expand Up @@ -547,6 +551,10 @@
#rpc = 271; # unused
#geoip = 272; # unused
fcron = 273;
bitcoin = 275;
dash = 276;
parity = 277;
monero = 278;

# When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal
Expand Down
4 changes: 4 additions & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
./services/backup/rsnapshot.nix
./services/backup/tarsnap.nix
./services/backup/znapzend.nix
./services/blockchain/bitcoin.nix
./services/blockchain/dash.nix
./services/blockchain/parity.nix
./services/blockchain/monero.nix
./services/cluster/fleet.nix
./services/cluster/kubernetes.nix
./services/cluster/panamax.nix
Expand Down
123 changes: 123 additions & 0 deletions nixos/modules/services/blockchain/bitcoin-core-generic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{ config, options, pkgs, lib
, name
, description
, defaultUser
, userDescription
, defaultGroup
, groupDescription
, defaultPackage
, daemonExec
, cliExec
, ... }:

with lib;

let

stateDir = "/var/lib/${name}";
pidFile = "${stateDir}/${name}.pid";

cu = pkgs.coreutils;

cfg = config.services.${name};
opts = options.services.${name};

configFile = optionalString (!isNull cfg.extraConfig) (" -conf=${pkgs.writeText "${name}.conf" cfg.extraConfig}");

in

{

options = {

services.${name} = {

enable = mkOption {
default = false;
description = "Enable ${description}";
type = types.bool;
};

package = mkOption {
default = defaultPackage;
description = "Package to use";
type = types.package;
};

user = mkOption {
default = defaultUser;
description = userDescription;
type = types.str;
};
Copy link
Member

Choose a reason for hiding this comment

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

since static user/group names are allocated, it is not really configurable. I would just drop these two options here and in every other service.

Copy link
Author

Choose a reason for hiding this comment

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

I don't really get what you mean. You can set user with services.bitcoind.user or services.dashd.user
Static is only the default value.


group = mkOption {
default = defaultGroup;
description = groupDescription;
type = types.str;
};

dataDir = mkOption {
description = "Data directory";
type = types.path;
};

extraConfig = mkOption {
description = "Additional configuration";
type = types.nullOr types.str;
};

};

};

config = mkIf cfg.enable {

systemd.services.${name} = {

inherit description;
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

serviceConfig = {
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.dataDir;

Type = "forking";
PIDFile = pidFile;

ExecStartPre = [
"+${cu}/bin/mkdir -p ${stateDir}"
"+${cu}/bin/chown -R ${cfg.user}:${cfg.group} ${stateDir}"
"+${cu}/bin/chmod -R 700 ${stateDir}"
];
ExecStart = "${cfg.package}/bin/${daemonExec} -daemon -pid=${pidFile} -datadir=${cfg.dataDir}${configFile}";
ExecStop = "${cfg.package}/bin/${cliExec} -rpcwait -datadir=${cfg.dataDir}${configFile} stop";

Restart = "always";
PrivateTmp = true;
TimeoutStopSec = 60;
};
};

users = {
extraUsers = optionalAttrs (cfg.user == opts.user.default) (singleton {
name = opts.user.default;
uid = config.ids.uids.${opts.user.default};
group = opts.group.default;
description = opts.user.description;
home = cfg.dataDir;
createHome = true;
});

extraGroups = optionalAttrs (cfg.group == opts.group.default) (singleton {
name = opts.group.default;
gid = config.ids.gids.${opts.group.default};
});
};

environment.systemPackages = [ cfg.package ];

};

}
16 changes: 16 additions & 0 deletions nixos/modules/services/blockchain/bitcoin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ config, options, pkgs, lib, ... }:

(import ./bitcoin-core-generic.nix {
inherit config options pkgs lib;

name = "bitcoind";
description = "Bitcoin's distributed currency daemon";
defaultUser = "bitcoin";
userDescription = "Bitcoin daemon user";
defaultGroup = "bitcoin";
groupDescription = "Bitcoin daemon group";
defaultPackage = pkgs.altcoins.bitcoind;
daemonExec = "bitcoind";
cliExec = "bitcoin-cli";

})
16 changes: 16 additions & 0 deletions nixos/modules/services/blockchain/dash.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ config, options, pkgs, lib, ... }:

(import ./bitcoin-core-generic.nix {
inherit config options pkgs lib;

name = "dashd";
description = "Dash's distributed currency daemon";
defaultUser = "dash";
userDescription = "Dash daemon user";
defaultGroup = "dash";
groupDescription = "Dash daemon group";
defaultPackage = pkgs.altcoins.dashpay;
daemonExec = "dashd";
cliExec = "dash-cli";

})
Loading