Files
frajtano/default.nix

41 lines
1.0 KiB
Nix

{
lib,
pkgs,
mixRelease,
elixir,
}: let
pname = "frajtano";
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";
};
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; }