Skip to content

Commit

Permalink
Add NixOS level service module (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
paluh authored May 11, 2024
1 parent d4e5218 commit 38f6f91
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
65 changes: 65 additions & 0 deletions nix/nixos.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}

2 changes: 1 addition & 1 deletion nix/outputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 38f6f91

Please sign in to comment.