summaryrefslogtreecommitdiffhomepage
path: root/gleam/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'gleam/flake.nix')
-rw-r--r--gleam/flake.nix66
1 files changed, 66 insertions, 0 deletions
diff --git a/gleam/flake.nix b/gleam/flake.nix
new file mode 100644
index 0000000..a5a3407
--- /dev/null
+++ b/gleam/flake.nix
@@ -0,0 +1,66 @@
+{
+ description = "ocda-lib: the object-centric document abstraction as a Gleam library";
+ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ outputs = { self, nixpkgs }:
+ let
+ system = "x86_64-linux"; # adjust for aarch64-linux / darwin
+ pkgs = import nixpkgs { inherit system; };
+
+ name = "ocda_lib";
+
+ /* The builder, nix-gleam's, kept here in nix-gleam/ (see the README
+ there). It fetches each Hex dependency on its own, with the
+ checksum gleam has already written into manifest.toml, so there is
+ no hash in this file to keep up to date, and nothing a run of gleam
+ could make come out differently.
+ */
+ inherit (pkgs.callPackage ./nix-gleam { }) buildGleamApplication;
+
+ /* rebar3 with the port compiler already in it.
+ esqlite builds a NIF, and its rebar3 configuration asks for the
+ `pc` plugin, which rebar3 would otherwise fetch from Hex at build
+ time: impossible in a sandbox, and the build fails with
+ "missing_package pc". nixpkgs carries the plugin, so the answer is
+ a rebar3 that has it before it starts.
+ */
+ rebar3-pc = pkgs.beamPackages.rebar3WithPlugins {
+ plugins = [ pkgs.beamPackages.pc ];
+ };
+ in {
+ packages.${system} = {
+ default = self.packages.${system}.${name};
+ /* Shipped as an Erlang shipment rather than as an escript, because
+ sqlite on the BEAM is a NIF: esqlite compiles its own sqlite into
+ a shared object, and a NIF cannot be loaded from inside an
+ escript archive, the runtime needing a real file on disk. The
+ shipment keeps priv/ on disk, so it loads.
+ */
+ ${name} = buildGleamApplication {
+ pname = "ocda-lib";
+ version = "2.0.0";
+ src = ./.;
+ rebar3Package = rebar3-pc;
+ nativeBuildInputs = [ pkgs.makeWrapper ];
+ preBuild = ''
+ export HOME=$TMPDIR
+ '';
+ installPhase = ''
+ runHook preInstall
+ mkdir -p $out/lib $out/bin
+ cp -r build/erlang-shipment $out/lib/${name}
+ makeWrapper $out/lib/${name}/entrypoint.sh $out/bin/ocda-lib \
+ --add-flags run \
+ --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.beamPackages.erlang pkgs.coreutils ]}
+ runHook postInstall
+ '';
+ meta = {
+ description = "the abstraction as a Gleam library";
+ mainProgram = "ocda-lib";
+ };
+ };
+ };
+ devShells.${system}.default = pkgs.mkShell {
+ packages = [ pkgs.gleam pkgs.beamPackages.erlang pkgs.rebar3 pkgs.sqlite ];
+ };
+ };
+}