@@ -7,7 +7,7 @@ with lib; with builtins;
7
7
let
8
8
cfg = config . services . cardano-node ;
9
9
envConfig = cfg . environments . ${ cfg . environment } ;
10
- runtimeDir = i : if cfg . runtimeDir i == null then cfg . stateDir i else "/run/ ${ cfg . runtimeDir i } " ;
10
+ runtimeDir = i : if cfg . runtimeDir i == null then cfg . stateDir i else "${ cfg . runDirBase } ${ lib . removePrefix cfg . runDirBase ( cfg . runtimeDir i ) } " ;
11
11
suffixDir = base : i : "${ base } ${ optionalString ( i != 0 ) "-${ toString i } " } " ;
12
12
nullOrStr = types . nullOr types . str ;
13
13
funcToOr = t : types . either t ( types . functionTo t ) ;
@@ -333,21 +333,37 @@ in {
333
333
'' ;
334
334
} ;
335
335
336
+ stateDirBase = mkOption {
337
+ type = types . str ;
338
+ default = "/var/lib/" ;
339
+ description = ''
340
+ Base directory to store blockchain data, for each instance.
341
+ '' ;
342
+ } ;
343
+
336
344
stateDir = mkOption {
337
345
type = funcToOr types . str ;
338
- default = "/var/lib/ cardano-node" ;
346
+ default = "${ cfg . stateDirBase } cardano-node" ;
339
347
apply = x : if ( builtins . isFunction x ) then x else i : x ;
340
348
description = ''
341
349
Directory to store blockchain data, for each instance.
342
350
'' ;
343
351
} ;
344
352
353
+ runDirBase = mkOption {
354
+ type = types . str ;
355
+ default = "/run/" ;
356
+ description = ''
357
+ Base runtime directory, for each instance.
358
+ '' ;
359
+ } ;
360
+
345
361
runtimeDir = mkOption {
346
362
type = funcToOr nullOrStr ;
347
- default = suffixDir "cardano-node" ;
348
- apply = x : if builtins . isFunction x then x else if x == null then _ : null else suffixDir x ;
363
+ default = i : '' ${ cfg . runDirBase } ${ suffixDir "cardano-node" i } '' ;
364
+ apply = x : if builtins . isFunction x then x else if x == null then _ : null else " ${ cfg . runDirBase } ${ suffixDir "cardano-node" x } " ;
349
365
description = ''
350
- Runtime directory relative to /run , for each instance
366
+ Runtime directory relative to ${ cfg . runDirBase } , for each instance
351
367
'' ;
352
368
} ;
353
369
705
721
} ;
706
722
707
723
config = mkIf cfg . enable ( let
708
- stateDirBase = "/var/lib/" ;
709
- runDirBase = "/run/" ;
710
724
lmdbPaths = filter ( x : x != null ) ( map ( e : cfg . lmdbDatabasePath e ) ( builtins . genList lib . trivial . id cfg . instances ) ) ;
711
725
genInstanceConf = f : listToAttrs ( if cfg . instances > 1
712
726
then genList ( i : let n = "cardano-node-${ toString i } " ; in nameValuePair n ( f n i ) ) cfg . instances
@@ -745,11 +759,11 @@ in {
745
759
ExecReload = mkIf ( cfg . useSystemdReload && cfg . useNewTopology ) "${ pkgs . coreutils } /bin/kill -HUP $MAINPID" ;
746
760
Restart = "always" ;
747
761
RuntimeDirectory = lib . mkIf ( ! cfg . systemdSocketActivation )
748
- ( lib . removePrefix runDirBase ( runtimeDir i ) ) ;
762
+ ( lib . removePrefix cfg . runDirBase ( runtimeDir i ) ) ;
749
763
WorkingDirectory = cfg . stateDir i ;
750
- # This assumes /var/lib/ is a prefix of cfg.stateDir.
764
+ # This assumes cfg.stateDirBase is a prefix of cfg.stateDir.
751
765
# This is checked as an assertion below.
752
- StateDirectory = lib . removePrefix stateDirBase ( cfg . stateDir i ) ;
766
+ StateDirectory = lib . removePrefix cfg . stateDirBase ( cfg . stateDir i ) ;
753
767
NonBlocking = lib . mkIf cfg . systemdSocketActivation true ;
754
768
# time to sleep before restarting a service
755
769
RestartSec = 1 ;
765
779
++ optional ( cfg . ipv6HostAddr i != null ) "[${ cfg . ipv6HostAddr i } ]:${ toString ( if cfg . shareIpv6port then cfg . port else cfg . port + i ) } "
766
780
++ ( cfg . additionalListenStream i )
767
781
++ [ ( cfg . socketPath i ) ] ;
768
- RuntimeDirectory = lib . removePrefix runDirBase
769
- ( cfg . runtimeDir i ) ;
782
+ RuntimeDirectory = lib . removePrefix cfg . runDirBase ( cfg . runtimeDir i ) ;
770
783
NoDelay = "yes" ;
771
784
ReusePort = "yes" ;
772
785
SocketMode = "0660" ;
@@ -788,17 +801,17 @@ in {
788
801
User = "cardano-node" ;
789
802
Group = "cardano-node" ;
790
803
ExecStart = "${ pkgs . coreutils } /bin/echo Starting ${ toString cfg . instances } cardano-node instances" ;
791
- WorkingDirectory = "/var/lib/cardano-node" ;
792
- StateDirectory = "cardano-node" ;
804
+ WorkingDirectory = cfg . stateDir i ;
805
+ StateDirectory = lib . removePrefix cfg . stateDirBase ( cfg . stateDir i ) ;
793
806
} ;
794
807
} ;
795
808
}
796
809
{
797
810
assertions = [
798
811
{
799
- assertion = builtins . all ( i : lib . hasPrefix stateDirBase ( cfg . stateDir i ) )
812
+ assertion = builtins . all ( i : lib . hasPrefix cfg . stateDirBase ( cfg . stateDir i ) )
800
813
( builtins . genList lib . trivial . id cfg . instances ) ;
801
- message = "The option services.cardano-node.stateDir should have ${ stateDirBase }
814
+ message = "The option services.cardano-node.stateDir should have ${ cfg . stateDirBase }
802
815
as a prefix, for each instance!" ;
803
816
}
804
817
{
0 commit comments