Last active
April 27, 2025 04:22
-
-
Save shegeley/f6503eae78d8bdb30e949e30ee78b8ed to your computer and use it in GitHub Desktop.
bitcon services type sample packed in guix
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
(use-modules | |
(gnu services) | |
(gnu services shepherd) | |
(gnu packages finance) | |
(srfi srfi-1) | |
(srfi srfi-125) | |
(ice-9 match) | |
(guix gexp) | |
(guix records)) | |
#| | |
Есть задача запаковать пакет bitcoin-core в service который будет крутиться под отдельным пользователем и настроить конфиг для хранения бд по определенному пути, кто может ? | |
|# | |
(define %datadir "/var/bitcoin-core") | |
(define %default-arguments | |
'("-rpcport=8332" | |
"-port=8333" | |
(string-append "-datadir=" %datadir) ;; change | |
"-rpcuser=user" ;; change or remove | |
"-server")) ;; server mode | |
(define bitcoin-config | |
`((package . ,bitcoin-core) | |
(log-file . "/home/shegeley/.local/var/lib/bitcoind/bitcoind.log") | |
(arguments . ,%default-arguments) | |
;; user and group has to exists | |
(user . "shegeley") | |
(group . "users"))) | |
(define (bitcoin-activation config) | |
#~(begin | |
(use-modules (guix build utils)) | |
(let* [(user #$(assoc-ref config 'user)) | |
(group #$(assoc-ref config 'group)) | |
(dir #$%datadir)] | |
(mkdir-p dir) | |
(chown dir | |
(passwd:uid user) | |
;; also you can do (passwd:gid user) + | |
;; omit group if user is in the same group | |
(passwd:gid group))))) | |
(define (bitcoin-shepherd-service config) | |
(list | |
(shepherd-service | |
(provision '(bitcoin)) | |
(requirement '(file-systems networking)) | |
(documentation "Run bitcoin walled daemon") | |
(start | |
#~(make-forkexec-constructor | |
(list | |
#$(file-append (assoc-ref config 'package) "/bin/bitcoind") | |
#$@(assoc-ref config 'arguments)) | |
#:user #$(assoc-ref config 'user) | |
;; also you can do #:group #$(passwd:gid (assoc-ref config 'user)) + | |
;; omit group if user is in the same group | |
#:group #$(assoc-ref config 'group) | |
#:log-file #$(assoc-ref config 'log-file))) | |
(auto-start? #t) | |
(respawn? #t) | |
(stop #~(make-kill-destructor))))) | |
(define-public bitcoin-service-type | |
(service-type | |
(name 'bitcoin) | |
(extensions | |
(list | |
(service-extension activation-service-type bitcoin-activation) | |
(service-extension | |
profile-service-type | |
(lambda (config) | |
(list (assoc-ref config 'package)))) | |
(service-extension shepherd-root-service-type bitcoin-shepherd-service))) | |
(default-value bitcoin-config) | |
(description "Run bitcoin"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make sure data-dir "/tmp/bitcoin-core" exists before starting service