Skip to content

Commit

Permalink
deploy: Add NixOS module (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
shlevy authored May 10, 2024
1 parent 24733d8 commit 5d15da6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
64 changes: 64 additions & 0 deletions nix/nixos.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
self: { lib, config, pkgs, ... }:
let
inherit (lib) mkOption types mapAttrs';

inherit (pkgs) writeTextDir symlinkJoin;

runnerOptions = { name, ... }: {
options = {
domain = mkOption {
type = types.str;
default = name;
description = "The domain to host marlowe-runner";
};

# 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 runner 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-runner-${name}-root";
paths = [
flake.packages.${pkgs.system}.marlowe-runner
configJson
];
};
in
{
options = {
marlowe.runners = mkOption {
type = types.attrsOf (types.submodule runnerOptions);
default = { };
description = "Marlowe Runner instances to run";
};
};
config = {
http-services.static-sites = mapAttrs'
(name: runner: {
name = "marlowe-runner-${name}";
value = {
inherit (runner) domain;
root = mkRoot name runner;
index-fallback = true;
};
})
config.marlowe.runners;
};
}

0 comments on commit 5d15da6

Please sign in to comment.