-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add services for Bitcoin, Dash, Parity and Monero #24576
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
nixos/modules/services/blockchain/bitcoin-core-generic.nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }; | ||
|
|
||
| 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 ]; | ||
|
|
||
| }; | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
|
|
||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
|
|
||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.