Compare commits
2 Commits
66cb85ec1d
...
83e18d7da4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83e18d7da4 | ||
|
|
904cb233f3 |
1
.envrc
1
.envrc
@@ -2,3 +2,4 @@ use flake
|
||||
|
||||
export RELEASE_NODE=frajtano-test@$(cat /etc/hostname)
|
||||
export FRAJTANO_DIR=$PWD/.frajtano_state
|
||||
export FRAJTANO_CONFIG=$PWD/config/config.exs
|
||||
|
||||
4
config/config.exs
Normal file
4
config/config.exs
Normal file
@@ -0,0 +1,4 @@
|
||||
import Config
|
||||
|
||||
config :frajtano,
|
||||
initial_peers: []
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
case "''${1:-}" in
|
||||
assimilate)
|
||||
run rpc ":ok = \"$(echo -n "$2" | ${pkgs.coreutils}/bin/base64)\" |> Base.decode64!() |> Frajtano.Agent.assimilate()"
|
||||
run rpc ":ok = ~S{$2} |> Frajtano.Agent.assimilate()"
|
||||
;;
|
||||
spawn)
|
||||
shift
|
||||
|
||||
17
flake.nix
17
flake.nix
@@ -40,10 +40,22 @@
|
||||
dir = lib.mkOption {
|
||||
description = "directory in which to place the listening socket";
|
||||
default = "${config.home.homeDirectory}/.ssh/frajtano";
|
||||
type = lib.types.path;
|
||||
};
|
||||
initialPeers = lib.mkOption {
|
||||
description = "initially spawned peers - will be passed to /usr/bin/env";
|
||||
type = with lib.types; listOf (listOf str);
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
config = let
|
||||
peers = lib.strings.concatMapStringsSep ", " (args: ''{:spawn, {"${pkgs.coreutils}/bin/env", [${lib.concatMapStringsSep ", " (s: ''~S{${s}}'') args}]}}'') cfg.initialPeers;
|
||||
configFile = pkgs.writeText "config.exs" ''
|
||||
import Config
|
||||
config :frajtano, initial_peers: [${peers}]
|
||||
'';
|
||||
in lib.mkIf cfg.enable {
|
||||
home.sessionVariables.FRAJTANO_DIR = cfg.dir;
|
||||
home.packages = [self.packages.${pkgs.system}.default];
|
||||
|
||||
@@ -51,7 +63,7 @@
|
||||
Unit.Description = "frajtano";
|
||||
Unit.After = ["default.target"];
|
||||
Service.Type = "notify";
|
||||
Service.Environment = ["'FRAJTANO_DIR=${cfg.dir}'"];
|
||||
Service.Environment = ["'FRAJTANO_DIR=${cfg.dir}'" "'FRAJTANO_CONFIG=${configFile}'"];
|
||||
Service.ExecSearchPath = ["${self.packages.${pkgs.system}.default}/bin"];
|
||||
Service.ExecStart = "frajtano start";
|
||||
Install.WantedBy = ["default.target"];
|
||||
@@ -62,6 +74,7 @@
|
||||
config = {
|
||||
EnvironmentVariables = {
|
||||
FRAJTANO_DIR = cfg.dir;
|
||||
FRAJTANO_CONFIG = configFile;
|
||||
};
|
||||
ProgramArguments = ["${self.packages.${pkgs.system}.default}/bin/frajtano" "start"];
|
||||
RunAtLoad = true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
defmodule Frajtano.Agent do
|
||||
alias Frajtano.Peer
|
||||
use GenServer
|
||||
require Logger
|
||||
|
||||
def start_link(args) do
|
||||
GenServer.start_link(__MODULE__, nil, [{:name, __MODULE__} | args])
|
||||
@@ -14,6 +15,12 @@ defmodule Frajtano.Agent do
|
||||
}
|
||||
end
|
||||
|
||||
def initial_peers() do
|
||||
initial_peers = Application.fetch_env!(:frajtano, :initial_peers)
|
||||
|> Enum.map(&GenServer.call(__MODULE__, {:add_peer, &1}))
|
||||
Logger.info("Started initial peers: #{inspect initial_peers}")
|
||||
end
|
||||
|
||||
# select: list of specs, where specs are a tuple of match, guards, and outputs
|
||||
# match is {key, pid, value}, :"$1" is a match variable
|
||||
def peer_paths() do
|
||||
|
||||
@@ -22,6 +22,7 @@ defmodule Frajtano.Supervisor do
|
||||
Frajtano.Agent,
|
||||
{Task.Supervisor, name: Frajtano.ClientSupervisor},
|
||||
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
|
||||
{Task, &Frajtano.Agent.initial_peers/0},
|
||||
:systemd.ready(),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user