Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit cf02326

Browse files
HirotoShioiksaric
authored andcommitted
[GH-14] Reuse existing Dhall configuration (#18)
* Copy dhall files from Daedalus repository * Implement parser for cluster, launcher, osConfig * Implement a parser for Topology * Implement installer config parser * Fix installerConfig bug * Explicit imports * Add missing instances * Rename module and folder * Explicit export on Lib, add Haddock comments * Remove unused library * Add documents regarding dhall * [WIP] Define new launcher.dhall * Replace newLauncher with Launcher, small refactoring * Remove field macPackageName * Add field x509ToolPath with comment * Remove macPackageName field * Implement typeclass instance of Inject for each data types * Define arbitrary instance for each data type * Add test cases on dhall configurations * Fix * Apply generalization on defining instance of Interpret, Inject * Rename genMaybe with maybeOf * Use arbitraryASCIIChar * Explicit import * Fix cabal file * Remove redundant type class deriving * Use renderOS to render OS in arbitrary instance * Remove pragma RecordWildCards * Utilize renderOS * Resolve merge conflict * Rename Pass to Param * Fix test cases * Rename dhall fields
1 parent b42560f commit cf02326

20 files changed

+810
-5
lines changed

cardano-shell.cabal

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ source-repository head
2222
library
2323
exposed-modules:
2424
Cardano.Shell.Lib
25+
, Configuration.Lib
26+
, Configuration.Types
2527
other-modules:
2628
Paths_cardano_shell
2729
, Cardano.Shell.Types
@@ -32,13 +34,19 @@ library
3234
build-depends:
3335
base >=4.7 && <5
3436
, cardano-prelude
37+
, contravariant
38+
, dhall
3539
, aeson
3640
, katip
3741
, ekg
3842
, ekg-core
3943
--, async
40-
, concurrency
44+
--, concurrency
45+
, QuickCheck
4146
, safe-exceptions
47+
, text
48+
, transformers
49+
, concurrency
4250
default-language: Haskell2010
4351
default-extensions: NoImplicitPrelude
4452
OverloadedStrings
@@ -78,13 +86,15 @@ test-suite cardano-shell-test
7886
main-is: Spec.hs
7987
other-modules:
8088
Paths_cardano_shell
89+
DhallConfigSpec
8190
hs-source-dirs:
8291
test
8392
ghc-options: -threaded -rtsopts -with-rtsopts=-N
8493
build-depends:
8594
base >=4.7 && <5
8695
, cardano-shell
8796
, cardano-prelude
97+
, dhall
8898
-- quickcheck
8999
, QuickCheck
90100
, hspec

cardano-shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ mkDerivation, aeson, base, cardano-prelude, concurrency, dejafu
1+
{ mkDerivation, aeson, base, cardano-prelude, concurrency, dejafu, dhall
22
, ekg, ekg-core, hspec, hspec-contrib, hunit-dejafu, katip
33
, QuickCheck, safe-exceptions, stdenv
44
}:
@@ -9,7 +9,7 @@ mkDerivation {
99
isLibrary = true;
1010
isExecutable = true;
1111
libraryHaskellDepends = [
12-
aeson base cardano-prelude concurrency ekg ekg-core katip
12+
aeson base cardano-prelude concurrency dhall ekg ekg-core katip
1313
safe-exceptions
1414
];
1515
executableHaskellDepends = [ base cardano-prelude ];

dhall/cluster.type

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ ccfgName : Text
2+
, ccfgKeyPrefix : Text
3+
, ccfgRelays : Text
4+
, ccfgUpdateServer : Text
5+
, ccfgReportServer : Text
6+
, ccfgInstallDirectorySuffix : Text
7+
, ccfgMacPackageSuffix : Text
8+
, ccfgWalletPort : Integer
9+
}

dhall/demo.dhall

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ ccfgName = "demo"
2+
, ccfgKeyPrefix = "TODO, default without the suffix"
3+
, ccfgRelays = "TODO, ip support missing"
4+
, ccfgUpdateServer = "https://disabled.iohkdev.io"
5+
, ccfgReportServer = "http://staging-report-server.awstest.iohkdev.io:8080"
6+
, ccfgInstallDirectorySuffix = " Demo"
7+
, ccfgMacPackageSuffix = "Demo"
8+
, ccfgWalletPort = +8092
9+
}

dhall/installer.dhall

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
\(cluster : ./cluster.type) ->
2+
\( os : ./os.type) ->
3+
{ icfgInstallDirectory = os.osInstallDirectory
4+
, icfgWalletPort = cluster.ccfgWalletPort
5+
}

dhall/launcher.dhall

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
\(cluster : ./cluster.type) ->
2+
\(os : ./os.type) ->
3+
{ lConfiguration =
4+
{ lcfgFilePath = os.osConfigurationYaml
5+
, lcfgKey = "${cluster.ccfgKeyPrefix}_${os.osName}"
6+
, lcfgSystemStart = [] : Optional Integer
7+
, lcfgSeed = [] : Optional Integer
8+
}
9+
, lNodeDbPath = os.osPass.pNodeDbPath
10+
, lNodeLogConfig = os.osPass.pNodeLogConfig
11+
, lUpdaterPath = os.osPass.pUpdaterPath
12+
, lUpdaterArgs = os.osPass.pUpdaterArgs
13+
, lUpdateArchive = os.osPass.pUpdateArchive
14+
, lLogsPrefix = os.osNodeArgs.naLogsPrefix
15+
, lReportServer = cluster.ccfgReportServer
16+
17+
-- Remove this field once x509tool is introduced in Cardano
18+
, lX509ToolPath = os.osX509ToolPath
19+
20+
-- XXX: NodeArgs
21+
, lTlsca = "${os.osNodeArgs.naTlsPath}/server/ca.crt"
22+
, lTlscert = "${os.osNodeArgs.naTlsPath}/server/server.crt"
23+
, lTlsKey = "${os.osNodeArgs.naTlsPath}/server/server.key"
24+
, lNoClientAuth = True
25+
, lLogConsoleOff = True
26+
, lUpdateServer = cluster.ccfgUpdateServer
27+
, lKeyFile = os.osNodeArgs.naKeyfile
28+
, lTopology = os.osNodeArgs.naTopology
29+
, lWalletDbPath = os.osNodeArgs.naWalletDBPath
30+
, lUpdateLatestPath = os.osNodeArgs.naUpdateLatestPath
31+
, lWalletAddress = "127.0.0.1:0"
32+
33+
-- XXX: this is a workaround for Linux
34+
, lUpdateWithPackage = True
35+
}

dhall/linux64.dhall

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
\(cluster : ./cluster.type) ->
2+
let dataDir = "\${XDG_DATA_HOME}/Daedalus/${cluster.ccfgName}"
3+
in
4+
{ osName = "linux64"
5+
, osConfigurationYaml = "\${DAEDALUS_CONFIG}/configuration.yaml"
6+
, osInstallDirectory = ""
7+
, osX509ToolPath = "cardano-x509-certificates"
8+
, osNodeArgs =
9+
{ naKeyfile = "${dataDir}/Secrets/secret.key"
10+
, naLogsPrefix = "${dataDir}/Logs"
11+
, naTopology = "\${DAEDALUS_CONFIG}/wallet-topology.yaml"
12+
, naUpdateLatestPath = "${dataDir}/installer.sh"
13+
, naWalletDBPath = "${dataDir}/Wallet"
14+
, naTlsPath = "${dataDir}/tls"
15+
}
16+
, osPass =
17+
{ pStatePath = dataDir
18+
, pWorkingDir = dataDir
19+
, pNodePath = "cardano-node"
20+
, pNodeDbPath = "${dataDir}/DB/"
21+
, pNodeLogConfig = "\${DAEDALUS_CONFIG}/log-config-prod.yaml"
22+
, pNodeLogPath = [] : Optional Text
23+
, pWalletPath = "daedalus-frontend"
24+
, pWalletLogging = False
25+
, pFrontendOnlyMode = True
26+
27+
-- todo, find some way to disable updates when unsandboxed?
28+
, pUpdaterPath = "/bin/update-runner"
29+
, pUpdaterArgs = [] : List Text
30+
, pUpdateArchive = [ "${dataDir}/installer.sh" ] : Optional Text
31+
, pUpdateWindowsRunner = [] : Optional Text
32+
33+
, pLauncherLogsPrefix = "${dataDir}/Logs/"
34+
}
35+
}

dhall/macos64.dhall

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
\(cluster : ./cluster.type) ->
2+
let dataDir = "\${HOME}/Library/Application Support/Daedalus${cluster.ccfgInstallDirectorySuffix}"
3+
--
4+
--
5+
in
6+
{ osName = "macos64"
7+
, osConfigurationYaml = "\${DAEDALUS_INSTALL_DIRECTORY}/configuration.yaml"
8+
, osInstallDirectory = "Daedalus${cluster.ccfgInstallDirectorySuffix}"
9+
, osX509ToolPath = "\${DAEDALUS_INSTALL_DIRECTORY}/cardano-x509-certificates"
10+
, osNodeArgs =
11+
{ naKeyfile = "${dataDir}/Secrets-1.0/secret.key"
12+
, naLogsPrefix = "${dataDir}/Logs"
13+
, naTopology = "\${DAEDALUS_INSTALL_DIRECTORY}/wallet-topology.yaml"
14+
, naUpdateLatestPath = "${dataDir}/installer.pkg"
15+
, naWalletDBPath = "${dataDir}/Wallet-1.0"
16+
, naTlsPath = "${dataDir}/tls"
17+
}
18+
, osPass =
19+
{ pStatePath = dataDir
20+
, pWorkingDir = dataDir
21+
, pNodePath = "\${DAEDALUS_INSTALL_DIRECTORY}/cardano-node"
22+
, pNodeDbPath = "${dataDir}/DB-1.0"
23+
, pNodeLogConfig = "\${DAEDALUS_INSTALL_DIRECTORY}/log-config-prod.yaml"
24+
, pNodeLogPath = [] : Optional Text
25+
26+
, pWalletPath = "\${DAEDALUS_INSTALL_DIRECTORY}/Frontend"
27+
, pWalletLogging = True
28+
, pFrontendOnlyMode = True
29+
30+
, pUpdaterPath = "/usr/bin/open"
31+
, pUpdaterArgs = ["-FW"]
32+
, pUpdateArchive = ["${dataDir}/installer.pkg"] : Optional Text
33+
, pUpdateWindowsRunner = [] : Optional Text
34+
35+
, pLauncherLogsPrefix = "${dataDir}/Logs/pub/"
36+
}
37+
}

dhall/mainnet.dhall

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ ccfgName = "mainnet"
2+
, ccfgKeyPrefix = "mainnet_wallet"
3+
, ccfgRelays = "relays.cardano-mainnet.iohk.io"
4+
, ccfgUpdateServer = "https://update-cardano-mainnet.iohk.io"
5+
, ccfgReportServer = "http://report-server.cardano-mainnet.iohk.io:8080"
6+
, ccfgInstallDirectorySuffix = ""
7+
, ccfgMacPackageSuffix = ""
8+
, ccfgWalletPort = +8090
9+
}

dhall/os.type

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ osName : Text
2+
, osConfigurationYaml : Text
3+
, osInstallDirectory : Text
4+
, osX509ToolPath : Text
5+
, osNodeArgs :
6+
{ naKeyfile : Text
7+
, naLogsPrefix : Text
8+
, naTopology : Text
9+
, naUpdateLatestPath : Text
10+
, naWalletDBPath : Text
11+
, naTlsPath : Text
12+
}
13+
, osPass :
14+
{ pStatePath : Text
15+
, pNodePath : Text
16+
, pNodeDbPath : Text
17+
, pNodeLogConfig : Text
18+
, pNodeLogPath : Optional Text
19+
, pWalletPath : Text
20+
, pWalletLogging : Bool
21+
, pWorkingDir : Text
22+
, pFrontendOnlyMode : Bool
23+
, pUpdaterPath : Text
24+
, pUpdaterArgs : List Text
25+
, pUpdateArchive : Optional Text
26+
, pUpdateWindowsRunner : Optional Text
27+
, pLauncherLogsPrefix : Text
28+
}
29+
}

dhall/staging.dhall

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ ccfgName = "staging"
2+
, ccfgKeyPrefix = "mainnet_dryrun_wallet"
3+
, ccfgRelays = "relays.awstest.iohkdev.io"
4+
, ccfgUpdateServer = "https://update-awstest.iohkdev.io"
5+
, ccfgReportServer = "http://staging-report-server.awstest.iohkdev.io:8080"
6+
, ccfgInstallDirectorySuffix = " Staging"
7+
, ccfgMacPackageSuffix = "Staging"
8+
, ccfgWalletPort = +8092
9+
}

dhall/testnet.dhall

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ ccfgName = "testnet"
2+
, ccfgKeyPrefix = "testnet_wallet"
3+
, ccfgRelays = "relays.cardano-testnet.iohkdev.io"
4+
, ccfgUpdateServer = "http://updates-cardano-testnet.s3.amazonaws.com"
5+
, ccfgReportServer = "http://report-server.cardano-mainnet.iohk.io:8080"
6+
, ccfgInstallDirectorySuffix = " Testnet"
7+
, ccfgMacPackageSuffix = "Testnet"
8+
, ccfgWalletPort = +8094
9+
}

dhall/topology.dhall

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
\(cluster : ./cluster.type) ->
2+
{ wallet = {
3+
wcfgRelays = [[{ host = cluster.ccfgRelays }]]
4+
, wcfgValency = +1
5+
, wcfgFallbacks = +7
6+
}
7+
}

dhall/win64.dhall

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
\(cluster : ./cluster.type) ->
2+
let installDir = "Daedalus${cluster.ccfgInstallDirectorySuffix}"
3+
in let dataDir = "\${APPDATA}\\${installDir}"
4+
--
5+
--
6+
in
7+
{ osName = "win64"
8+
, osConfigurationYaml = "\${DAEDALUS_INSTALL_DIRECTORY}\\configuration.yaml"
9+
, osInstallDirectory = installDir
10+
, osX509ToolPath = "\${DAEDALUS_DIR}\\cardano-x509-certificates.exe"
11+
, osNodeArgs =
12+
{ naKeyfile = "Secrets-1.0\\secret.key"
13+
, naLogsPrefix = "Logs"
14+
, naTopology = "\${DAEDALUS_DIR}\\wallet-topology.yaml"
15+
, naUpdateLatestPath = "Installer.exe"
16+
, naWalletDBPath = "Wallet-1.0"
17+
, naTlsPath = "tls"
18+
}
19+
, osPass =
20+
{ pStatePath = dataDir
21+
, pWorkingDir = dataDir
22+
, pNodePath = "\${DAEDALUS_DIR}\\cardano-node.exe"
23+
, pNodeDbPath = "DB-1.0"
24+
, pNodeLogConfig = "\${DAEDALUS_INSTALL_DIRECTORY}\\log-config-prod.yaml"
25+
, pNodeLogPath = [] : Optional Text
26+
, pWalletPath = "\${DAEDALUS_DIR}\\Daedalus.exe"
27+
, pWalletLogging = True
28+
, pFrontendOnlyMode = True
29+
30+
, pUpdaterPath = "Installer.exe"
31+
, pUpdaterArgs = [] : List Text
32+
, pUpdateArchive = [] : Optional Text
33+
, pUpdateWindowsRunner = ["Installer.bat"] : Optional Text
34+
35+
, pLauncherLogsPrefix = "Logs\\pub"
36+
}
37+
}

docs/Dhall.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Some caveats regarding Dhall
2+
Package name: dhall
3+
4+
Version used: 1.5.1
5+
6+
[Link](http://hackage.haskell.org/package/dhall-1.15.1)
7+
8+
9+
## When you don't derive the show instance of the datatype that you want to parse, dhall will not print anything on the console.
10+
11+
Say you have some datatype like this:
12+
13+
```
14+
data Config = Config {
15+
walletPort :: !Natural
16+
, walletDBPath :: !Text
17+
}
18+
```
19+
20+
and you forgot to derive an show instance of it.
21+
When you parse the dhall file and try to print the result, the console does not warn you about
22+
missing show instance. It returns nothing at all.
23+
24+
25+
## Breaking change from 1.1.1 to 1.5.1
26+
27+
There was a breaking change upon 1.14 release where the grammar of Natural and Integer was swapped.
28+
You can check the release notes [here](https://github.com/dhall-lang/dhall-haskell/releases/tag/1.14.0)
29+
30+
This means I had to switch some of the types (e.g. WalletPort) from Integer to Natural
31+
32+
## Defining an instance of Interpret with defaultInterpretOptions causes infinite loop
33+
34+
In order to parse Dhall file, you'll need to define an typeclasss instance of `Interpret`, similiar [aeson](http://hackage.haskell.org/package/aeson-1.4.1.0/docs/Data-Aeson.html).
35+
36+
37+
There's is an way to easier way to define an instance of it using [defaultInterpretOptions](http://hackage.haskell.org/package/dhall-1.15.1/docs/Dhall.html#v:defaultInterpretOptions).
38+
39+
But for some reason, this causes infinite loop. Currently looking into it.

src/Configuration/Lib.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Configuration.Lib
2+
( mkLauncher
3+
, mkTopology
4+
, mkOSConfig
5+
, mkInstallerConfig
6+
) where
7+
8+
import Cardano.Prelude
9+
10+
import Dhall (auto, input)
11+
12+
import Configuration.Types (Cluster (..), InstallerConfig, Launcher,
13+
Launcher, OS (..), OSConfig,
14+
TopologyConfig, renderCluster, renderOS)
15+
16+
-- | Generate 'TopologyConfig' with given 'Cluster'
17+
mkTopology :: Cluster -> IO TopologyConfig
18+
mkTopology cluster = input auto topologyPath
19+
where
20+
topologyPath = toPath "topology" <> " " <> toPath (renderCluster cluster)
21+
22+
-- | Generate 'OSConfig' with given 'OS' and 'Cluster'
23+
mkOSConfig :: OS -> Cluster -> IO OSConfig
24+
mkOSConfig os cluster = input auto osConfigPath
25+
where
26+
osConfigPath = toPath (renderOS os) <> " " <> toPath (renderCluster cluster)
27+
28+
-- | Generate 'InstallerConfig' with given 'OS' and 'Cluster'
29+
mkInstallerConfig :: OS -> Cluster -> IO InstallerConfig
30+
mkInstallerConfig os cluster = input auto installerConfigPath
31+
where
32+
installerConfigPath = toPath "installer"
33+
<> " " <> toPath (renderCluster cluster)
34+
<> " (" <> toPath (renderOS os) <> " " <> toPath (renderCluster cluster) <> ")"
35+
36+
-- | Generate 'Launcher' config with given 'OS' and 'Cluster'
37+
mkLauncher :: OS -> Cluster -> IO Launcher
38+
mkLauncher os cluster = input auto launcherPath
39+
where
40+
launcherPath = toPath "launcher"
41+
<> " " <> toPath (renderCluster cluster)
42+
<> " " <> "(" <> toPath (renderOS os) <> " " <> toPath (renderCluster cluster) <> ")"
43+
44+
-- | Given an FileName, return 'FilePath' to dhall file
45+
toPath :: Text -> Text
46+
toPath fileName = "./dhall/" <> fileName <> ".dhall"

0 commit comments

Comments
 (0)