Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102{ lib, stdenv, fetchurl, gleam, beamPackages, python311, bash, coreutils, ripgrep, makeWrapper, chrome-headless-shell, render, usageCore,}: let inherit (beamPackages) erlang; # esqlite loads the pc plugin during its Rebar3 build, which cannot fetch # plugins from Hex inside the Nix sandbox. rebar3 = beamPackages.rebar3WithPlugins {plugins = [beamPackages.pc];}; manifest = builtins.fromTOML (builtins.readFile ../../manifest.toml); daemonSource = lib.fileset.toSource { root = ../..; fileset = lib.fileset.unions [ ../../gleam.toml ../../manifest.toml ../../src ../../vendor (lib.fileset.fileFilter (file: !file.hasExt "pyc") ../../priv) ]; }; hexPackages = map (p: { inherit (p) name version; archive = fetchurl { url = "https://repo.hex.pm/tarballs/${p.name}-${p.version}.tar"; sha256 = lib.toLower p.outer_checksum; }; }) (lib.filter (p: p.source == "hex") manifest.packages); # Path dependencies (patched copies under vendor/) build from the source # tree; gleam only needs them named in the package index. localPackages = lib.filter (p: p.source == "local") manifest.packages; packageIndex = builtins.toFile "packages.toml" ("[packages]\n" + lib.concatMapStrings (p: "${p.name} = \"${p.version}\"\n") (hexPackages ++ localPackages));in stdenv.mkDerivation { pname = "albedo-server"; version = "1.0.0"; src = daemonSource; nativeBuildInputs = [gleam erlang rebar3 makeWrapper]; buildPhase = '' runHook preBuild export HOME="$TMPDIR/home" mkdir -p "$HOME" build/packages ${lib.concatMapStringsSep "\n" (p: '' mkdir -p build/packages/${p.name} "$TMPDIR/hex-${p.name}" tar -xf ${p.archive} -C "$TMPDIR/hex-${p.name}" tar -xzf "$TMPDIR/hex-${p.name}/contents.tar.gz" -C build/packages/${p.name} '') hexPackages} cp ${packageIndex} build/packages/packages.toml # A path dependency whose gleam.toml is newer than its fingerprint file # makes gleam resolve versions again, which needs the network. Store # sources are dated 1970, so any fingerprint written now is newer. ${lib.concatMapStringsSep "\n" (p: "touch build/packages/${p.name}.config_fingerprint") localPackages} chmod -R u+w build/packages gleam export erlang-shipment runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out/lib/albedo $out/bin cp -R build/erlang-shipment/. $out/lib/albedo/ # Kernels import this python from the read-only store, where Python # cannot cache bytecode, so each would compile it again (megabytes per # kernel). Hash-checked, because the store resets every mtime. ${python311}/bin/python3 -m compileall -q --invalidation-mode checked-hash \ $out/lib/albedo/albedo/priv/python mkdir -p $out/lib/albedo/albedo/priv/bin ln -s ${render}/bin/albedo-render $out/lib/albedo/albedo/priv/bin/albedo-render ln -s ${usageCore}/bin/usage $out/lib/albedo/albedo/priv/bin/usage makeWrapper $out/lib/albedo/albedo/priv/bin/albedo-daemon $out/bin/albedo-daemon \ --add-flags "$out/lib/albedo/entrypoint.sh run" \ --set-default ALBEDO_BUILD $out/bin/albedo-daemon \ --prefix PATH : ${lib.makeBinPath [erlang python311 bash coreutils ripgrep render chrome-headless-shell]} runHook postInstall ''; # Sealed last: fixup rewrites shebangs and strips files under priv. postFixup = '' ALBEDO_BUILD_APP="$out/lib/albedo/albedo" ${erlang}/bin/erl +S 2:2 \ -pa "$out/lib/albedo"/*/ebin -noshell \ -eval 'application:ensure_all_started(crypto), ok = albedo_daemon:seal_build(unicode:characters_to_binary(os:getenv("ALBEDO_BUILD_APP"))), halt().' ''; meta = { description = "coding agent daemon with its runtime and native helpers"; license = with lib.licenses; [agpl3Only classpathException20]; mainProgram = "albedo-daemon"; platforms = lib.platforms.unix; }; }