Flake: HM module
This commit is contained in:
@@ -1,2 +1,6 @@
|
|||||||
import Config
|
import Config
|
||||||
config :frajtano, listen_path: Path.expand(System.get_env("FRAJTANO_DIR")) |> Path.join("agent.sock")
|
config :frajtano,
|
||||||
|
listen_path: Path.expand(System.get_env("FRAJTANO_DIR")) |> Path.join("agent.sock"),
|
||||||
|
initial_peers: System.get_env("FRAJTANO_PEERS") |> String.split(":") |> Enum.map(&Path.expand/1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
45
flake.nix
45
flake.nix
@@ -15,7 +15,11 @@
|
|||||||
ownPkgs = self.packages.${system};
|
ownPkgs = self.packages.${system};
|
||||||
});
|
});
|
||||||
in {
|
in {
|
||||||
devShells = eachSystem ({pkgs, ownPkgs, ...}: {
|
devShells = eachSystem ({
|
||||||
|
pkgs,
|
||||||
|
ownPkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
default = pkgs.beam.packages.erlang_26.callPackage ./shell.nix {
|
default = pkgs.beam.packages.erlang_26.callPackage ./shell.nix {
|
||||||
inherit ownPkgs;
|
inherit ownPkgs;
|
||||||
};
|
};
|
||||||
@@ -23,5 +27,44 @@
|
|||||||
packages = eachSystem ({pkgs, ...}: {
|
packages = eachSystem ({pkgs, ...}: {
|
||||||
default = pkgs.beam.packages.erlang_26.callPackage ./default.nix {};
|
default = pkgs.beam.packages.erlang_26.callPackage ./default.nix {};
|
||||||
});
|
});
|
||||||
|
homeModules.default = {
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
}: let
|
||||||
|
cfg = config.bluepython508.frajtano;
|
||||||
|
in {
|
||||||
|
options.bluepython508.frajtano = {
|
||||||
|
enable = lib.mkEnableOption "frajtano";
|
||||||
|
dir = lib.mkOption {
|
||||||
|
name = "directory in which to place the listening socket";
|
||||||
|
default = "${config.home.homeDirectory}/.ssh/frajtano";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
home.sessionVariables.FRAJTANO_DIR = cfg.dir;
|
||||||
|
|
||||||
|
systemd.user.services.frajtano = {
|
||||||
|
Unit.Description = "frajtano";
|
||||||
|
Unit.After = ["default.target"];
|
||||||
|
Service.Environment = "'FRAJTANO_DIR=${cfg.dir}'";
|
||||||
|
Service.ExecStart = "${self.packages.${pkgs.system}.default} start";
|
||||||
|
Install.WantedBy = ["default.target"];
|
||||||
|
};
|
||||||
|
|
||||||
|
launchd.agents.frajtano = {
|
||||||
|
enable = true;
|
||||||
|
config = {
|
||||||
|
EnvironmentVariables = {
|
||||||
|
FRAJTANO_DIR = cfg.dir;
|
||||||
|
};
|
||||||
|
ProgramArguments = ["${lib.getExe self.packages.${pkgs.system}.default}" "start"];
|
||||||
|
RunAtLoad = true;
|
||||||
|
KeepAlive = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
20
lib/agent.ex
20
lib/agent.ex
@@ -8,10 +8,19 @@ defmodule Frajtano.Agent do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def init(_) do
|
def init(_) do
|
||||||
{:ok,
|
{
|
||||||
%{
|
:ok,
|
||||||
keys: %{}
|
%{
|
||||||
}}
|
keys: %{}
|
||||||
|
},
|
||||||
|
{:continue, :init_peers}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_continue(:init_peers, state) do
|
||||||
|
for peer <- Application.fetch_env!(:frajtano, :initial_peers), do: {:ok, _} = Peer.start(peer)
|
||||||
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@@ -26,10 +35,9 @@ defmodule Frajtano.Agent do
|
|||||||
with {:ok, idents} <- Peer.identities(peer),
|
with {:ok, idents} <- Peer.identities(peer),
|
||||||
do: {:ok, {idents, peer}}
|
do: {:ok, {idents, peer}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
# Double :ok-wrapping because of Task.async_stream
|
# Double :ok-wrapping because of Task.async_stream
|
||||||
idents = (for {:ok, {:ok, {idents, peer}}} <- idents, do: {idents, peer})
|
idents = for {:ok, {:ok, {idents, peer}}} <- idents, do: {idents, peer}
|
||||||
|
|
||||||
{
|
{
|
||||||
:reply,
|
:reply,
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ defmodule Frajtano.Supervisor do
|
|||||||
@impl true
|
@impl true
|
||||||
def init(:ok) do
|
def init(:ok) do
|
||||||
children = [
|
children = [
|
||||||
|
{DynamicSupervisor, name: Frajtano.Peer},
|
||||||
Frajtano.Agent,
|
Frajtano.Agent,
|
||||||
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
|
|
||||||
{Task.Supervisor, name: Frajtano.ClientSupervisor},
|
{Task.Supervisor, name: Frajtano.ClientSupervisor},
|
||||||
{DynamicSupervisor, name: Frajtano.Peer}
|
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
|
||||||
]
|
]
|
||||||
|
|
||||||
Supervisor.init(children, strategy: :one_for_one)
|
Supervisor.init(children, strategy: :one_for_one)
|
||||||
|
|||||||
Reference in New Issue
Block a user