Add runtime support: don't only listen on /tmp/frajtano1, script to add peer

This commit is contained in:
bluepython508
2024-09-19 12:39:19 +01:00
parent 5229bd8d1c
commit 6aaf8ff8e5
6 changed files with 40 additions and 19 deletions

View File

@@ -1,24 +1,40 @@
{
lib,
pkgs,
mixRelease,
fetchMixDeps,
elixir,
}:
mixRelease rec {
}: let
pname = "frajtano";
version = "0.0.1";
pkg = mixRelease {
inherit pname;
version = "0.0.1";
inherit elixir;
src = builtins.path {
path = ./.;
name = "${pname}-source";
filter = path: _type: baseNameOf path != "flake.nix" && baseNameOf path != "flake.lock";
};
mixFodDeps = fetchMixDeps {
pname = "mix-deps-${pname}";
inherit version src;
sha256 = "sha256-lknkq6b1yDOLgTpR/tPEk9UKqpqQT6H1N5g15M60nCA=";
};
inherit elixir;
src = builtins.path {
path = ./.;
name = "${pname}-source";
filter = path: _type: baseNameOf path != "flake.nix" && baseNameOf path != "flake.lock";
};
ELIXIR_MAKE_CACHE_DIR = "/tmp/.elixir-make-cache";
meta.mainProgram = "${pname}";
}
ELIXIR_MAKE_CACHE_DIR = "/tmp/.elixir-make-cache";
meta.mainProgram = pname;
};
script = pkgs.writeShellScriptBin pname ''
set -eu
file="$FRAJTANO_DIR/cookie"
(umask 077; [ -f "$file" ] || ${pkgs.coreutils}/bin/head -c 128 /dev/urandom | ${pkgs.coreutils}/bin/base64 -w0 > "$file")
export RELEASE_COOKIE=$(${pkgs.coreutils}/bin/cat "$file")
run() {
exec ${lib.getExe pkg} "$@"
}
case $1 in
assimilate)
run rpc ":ok = \"$(echo -n "$2" | ${pkgs.coreutils}/bin/base64)\" |> Base.decode64!() |> Frajtano.Agent.add_peer()"
;;
*)
run "$@"
;;
esac
'';
in pkgs.symlinkJoin { name = pname; paths = [ script pkg ]; meta.mainProgram = pname; }