diff --git a/README.md b/README.md index d64d211..34b08c9 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,15 @@ It is available as open source code here: [`\marlowe-ts-sdk/blob/main/packages/l The vesting contract is documented in our TS-SDK [API Reference](https://input-output-hk.github.io/marlowe-ts-sdk/modules/_marlowe_io_language_examples.vesting.html). + +### Configuration + +In order to configure the application your HTTP server should serve a `config.json`. To do so, create the file `public/config.json` with the following structure: + +```json +{ "marloweWebServerUrl": 'https://link-to-runner-instance', "develMode": false } +``` + ## The Prototype The prototype allows you to create ₳ Token Plans over Cardano. diff --git a/flake.nix b/flake.nix index e812565..0344ff0 100644 --- a/flake.nix +++ b/flake.nix @@ -10,6 +10,9 @@ inherit inputs; repoRoot = ./.; systems = [ "x86_64-linux" "x86_64-darwin" ]; + flake = { + nixosModules.default = import ./nix/nixos.nix inputs.self; + }; outputs = import ./nix/outputs.nix; }; diff --git a/nix/nixos.nix b/nix/nixos.nix new file mode 100644 index 0000000..e9077b9 --- /dev/null +++ b/nix/nixos.nix @@ -0,0 +1,65 @@ +self: { lib, config, pkgs, ... }: +let + inherit (lib) mkOption types mapAttrs'; + + inherit (pkgs) writeTextDir symlinkJoin; + + tokenPlansOptions = { name, ... }: { + options = { + domain = mkOption { + type = types.str; + default = name; + description = "The domain to host marlowe-token-plans"; + }; + + # TODO local or remote + runtime-instance = mkOption { + type = types.str; + description = "The name of the runtime instance to connect to"; + }; + + flake = mkOption { + type = types.attrs; + default = self; + description = "A Nix Flake containing the token plans application"; + }; + }; + }; + + mkRoot = name: { runtime-instance, flake, ... }: + let + configJson = writeTextDir "config.json" (builtins.toJSON { + marloweWebServerUrl = "//${config.marlowe.runtimes.${runtime-instance}.domain}"; + develMode = false; + }); + in + symlinkJoin { + name = "marlowe-token-plans-${name}-root"; + paths = [ + flake.packages.${pkgs.system}.marlowe-token-plans + configJson + ]; + }; +in +{ + options = { + marlowe.token-plans = mkOption { + type = types.attrsOf (types.submodule tokenPlansOptions); + default = { }; + description = "Marlowe Token Plans instances to run"; + }; + }; + config = { + http-services.static-sites = mapAttrs' + (name: tokenPlan: { + name = "marlowe-token-plans-${name}"; + value = { + inherit (tokenPlan) domain; + root = mkRoot name tokenPlan; + index-fallback = true; + }; + }) + config.marlowe.token-plans; + }; +} + diff --git a/nix/outputs.nix b/nix/outputs.nix index 744cacc..c69ad05 100644 --- a/nix/outputs.nix +++ b/nix/outputs.nix @@ -4,7 +4,7 @@ { devShells.default = repoRoot.nix.shell; - packages.marlowe-vesting = repoRoot.nix.marlowe-vesting; + packages.marlowe-token-plans = repoRoot.nix.marlowe-vesting; hydraJobs.devShells.default = repoRoot.nix.shell; hydraJobs.marlowe-vesting = repoRoot.nix.marlowe-vesting;