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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191# One derivation per workspace package: it compiles the package on its own# manifest, checks its formatting, and runs its tests. The output holds the# compiled application and the package's public interface.## Dependencies are explicit inputs, never compiled again inside a package's# check (robot-docs/workspace-packages.md#nix):# - `workspace-hex` compiles every Hex package the root manifest locks once. A# package seeds the ones it locks at the root's version and checksum, which# test/packages.sh requires of its production closure; any other compiles# from source in its own build.# - Each path dependency, a workspace package or a patched copy under vendor/,# has a library derivation: its src/ compiled alone with# `gleam compile-package --no-dev`, against the libraries of its own# dependencies. It holds no tests and does not read them, so a change to a# package's tests rebuilds only that package's check.{ lib, stdenv, callPackage, gleam, beamPackages, projects,}: let workspace = callPackage ../packages/workspace-packages.nix {}; # esqlite, which sqlight wraps, loads the pc plugin during its Rebar3 build, # which cannot fetch plugins from Hex inside the Nix sandbox. rebar3 = beamPackages.rebar3WithPlugins {plugins = lib.unique (lib.concatMap (project: project.rebarPlugins or []) (lib.attrValues projects));}; gleamDeps = callPackage ../packages/gleam-deps.nix {}; nativeBuildInputs = [gleam beamPackages.erlang rebar3]; readToml = file: builtins.fromTOML (builtins.readFile file); rootHex = lib.listToAttrs (map (p: lib.nameValuePair p.name p) (lib.filter (p: p.source == "hex") (readToml (workspace.repo + "/apps/albedo/manifest.toml")).packages)); # The directory under build/dev/erlang a locked package compiles into. appDir = p: p.otp_app or p.name; sameAsRoot = p: rootHex ? ${p.name} && rootHex.${p.name}.version == p.version && rootHex.${p.name}.outer_checksum == p.outer_checksum;
# A scratch project that requires each of the root's Hex packages at its # locked version, with a manifest that already agrees, so gleam compiles # them all without resolving anything. hexRequirements = lib.concatMapStrings (p: "${p.name} = { version = \"== ${p.version}\" }\n") (lib.attrValues rootHex); hexManifest = builtins.toFile "manifest.toml" ('' packages = [ '' + lib.concatMapStrings (p: '' { name = "${p.name}", version = "${p.version}", build_tools = ${builtins.toJSON p.build_tools}, requirements = ${builtins.toJSON p.requirements}, ${lib.optionalString (p ? otp_app) "otp_app = \"${p.otp_app}\", "}source = "hex", outer_checksum = "${p.outer_checksum}" }, '') (lib.attrValues rootHex) + '' ]
[requirements] '' + hexRequirements); hex = stdenv.mkDerivation { name = "albedo-workspace-hex"; dontUnpack = true; inherit nativeBuildInputs; buildPhase = '' runHook preBuild export HOME="$TMPDIR/home" mkdir -p "$HOME" project/src cd project printf 'name = "albedo_workspace_hex"\nversion = "1.0.0"\ntarget = "erlang"\n\n[dependencies]\n%s' '${hexRequirements}' > gleam.toml cp ${hexManifest} manifest.toml ${(gleamDeps {packages = lib.attrValues rootHex;}).stage} gleam build runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out cp -R build/dev/erlang/. $out/ rm -rf $out/albedo_workspace_hex runHook postInstall ''; };
# Library derivations, by each path dependency's directory from the root. relative = path: lib.removePrefix (toString workspace.repo + "/") (toString path); pathDeps = dir: lib.filter (d: d.spec ? path) (lib.mapAttrsToList (name: spec: {inherit name spec;}) ((readToml (dir + "/gleam.toml")).dependencies or {})); libraryOf = dir: libraries.${relative dir}; buildLibrary = dir: let config = readToml (dir + "/gleam.toml"); deps = map (d: { inherit (d) name; drv = libraryOf (dir + "/${d.spec.path}"); }) (pathDeps dir); otpApps = lib.concatStringsSep "," (map (p: "${p.name}=${p.otp_app}") (lib.filter (p: p ? otp_app && p.otp_app != p.name) (lib.attrValues rootHex))); in stdenv.mkDerivation { pname = "albedo-gleam-lib-${config.name}"; inherit (config) version; src = lib.fileset.toSource { root = workspace.repo; fileset = lib.fileset.unions (workspace.compiled dir); }; sourceRoot = "source/${relative dir}"; inherit nativeBuildInputs; buildPhase = '' runHook preBuild export HOME="$TMPDIR/home" mkdir -p "$HOME" "$TMPDIR/lib" for app in ${hex}/*/; do ln -s "$app" "$TMPDIR/lib/"; done ${lib.concatMapStrings (d: "ln -s ${d.drv} \"$TMPDIR/lib/${d.name}\"\n") deps} gleam compile-package --target erlang --no-dev --package . --out "$TMPDIR/out" \ --lib "$TMPDIR/lib" ${lib.optionalString (otpApps != "") "--otp-app-names ${otpApps}"} if [ -d priv ]; then cp -R priv "$TMPDIR/out/priv"; fi runHook postBuild ''; installPhase = '' runHook preInstall cp -R "$TMPDIR/out" $out runHook postInstall ''; }; libraryPaths = lib.unique (lib.concatMap (project: let inherit (project) dir; manifest = readToml (dir + "/manifest.toml"); in [(relative dir)] ++ map (p: relative (dir + "/${p.path}")) (lib.filter (p: p.source == "local") manifest.packages)) (lib.attrValues projects)); libraries = lib.genAttrs libraryPaths (path: buildLibrary (workspace.repo + "/${path}"));
build = dir: let config = readToml (dir + "/gleam.toml"); inherit (config) name; manifestFile = dir + "/manifest.toml"; locked = (readToml manifestFile).packages; # The path dependencies its manifest locks, transitive ones included, by # their paths from this package, such as ../albedo_protect or # ../../vendor/mist. Their tests are not part of the source. local = lib.filter (p: p.source == "local") locked; seededHex = lib.filter (p: p.source == "hex" && sameAsRoot p) locked; in stdenv.mkDerivation { pname = name; inherit (config) version; # Rooted at the repository, so each path dependency's relative path # resolves to the same place it does in a checkout. src = lib.fileset.toSource { root = workspace.repo; fileset = lib.fileset.unions (workspace.compiled dir ++ [ manifestFile (lib.fileset.maybeMissing (dir + "/test")) ] ++ lib.concatMap (p: workspace.compiled (dir + "/${p.path}")) local); }; sourceRoot = "source/${relative dir}"; inherit nativeBuildInputs; buildPhase = '' runHook preBuild export HOME="$TMPDIR/home" mkdir -p "$HOME" build/dev/erlang ${(gleamDeps (readToml manifestFile)).stage} cp ${hex}/fingerprint build/dev/erlang/ ${lib.concatMapStrings (p: "cp -R ${hex}/${appDir p} build/dev/erlang/\n") seededHex} ${lib.concatMapStrings (p: "cp -R ${libraries.${relative (dir + "/${p.path}")}} build/dev/erlang/${p.name}\n") local} chmod -R u+w build/dev/erlang gleam build --warnings-as-errors runHook postBuild ''; doCheck = true; checkPhase = '' runHook preCheck gleam format --check src test gleam test runHook postCheck ''; installPhase = '' runHook preInstall mkdir -p $out/lib/${name} cp -R build/dev/erlang/${name}/ebin $out/lib/${name}/ gleam export package-interface --out $out/package-interface.json runHook postInstall ''; passthru.library = libraryOf dir; meta = { description = config.description or "albedo workspace Gleam package ${name}"; license = map lib.meta.getLicenseFromSpdxId config.licences; platforms = lib.platforms.unix; }; };in {inherit build libraries hex rebar3;}