~evhan/beaker

49dd5955acf9287ec5ba0503e8c30e6e81b3e746 — Evan Hanson 8 months ago 6bfb584
Document Nix helpers
4 files changed, 90 insertions(+), 14 deletions(-)

M aux/generate-wiki-page.scm
M beaker.wiki.in
M default.nix
A nix.md
M aux/generate-wiki-page.scm => aux/generate-wiki-page.scm +1 -0
@@ 4,6 4,7 @@ exec csi -s "$0" "$@"
|#

(import (beaker markdown))
(import (chicken io))
(import (only (chicken port) make-concatenated-port))
(import (markdown-svnwiki))


M beaker.wiki.in => beaker.wiki.in +8 -4
@@ 8,10 8,10 @@ Lab supplies for CHICKEN Scheme.

Beaker is a collection of development tools.

It is currently fairly limited, including only two programs and a small
handful of libraries to make common development tasks easier. If you
have an idea for something that would be useful to include, don't
hesitate to contact the [[##author|author]].
It is currently fairly limited, including only a few programs and a handful
of libraries to make common development tasks easier. If you have an idea
for something that would be useful to include, don't hesitate to contact
the [[##author|author]].

The project's source is available [[https://git.sr.ht/~evhan/beaker|here]].



@@ 43,6 43,10 @@ The project's source is available [[https://git.sr.ht/~evhan/beaker|here]].

#(document-extension "lib/beaker/system.scm")

== Nix Helpers

#(with-input-from-file "nix.md" read-string)

== Links

* Sources: [[https://git.sr.ht/~evhan/beaker]]

M default.nix => default.nix +22 -10
@@ 1,13 1,15 @@
{ pkgs ? import <nixpkgs> {} }:

with pkgs;

rec {
  repositoryPath = "lib/chicken/${toString pkgs.chicken.binaryVersion}";
  repositoryPath = "lib/chicken/${toString chicken.binaryVersion}";

  eggCache = {
    name ? "eggs",
    hash,
    overrideFile,
  }: with pkgs; runCommand name {
  }: runCommand name {
    buildInputs = [ chicken ];
    outputHash = hash;
    outputHashMode = "recursive";


@@ 26,7 28,7 @@ rec {
    preUnpack ? "",
    preBuild ? "",
    ...
  } @ args: with pkgs; stdenv.mkDerivation {
  } @ args: stdenv.mkDerivation {
    name = name;
    src = src;
    buildInputs = [ chicken makeWrapper ] ++ buildInputs;


@@ 47,20 49,30 @@ rec {

    buildPhase = ''
      runHook preBuild

      chicken-install

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      mv $CHICKEN_INSTALL_PREFIX $out
      find $out/lib -type f -not -name \*.so -delete
      for bin in $out/bin/*; do
        wrapProgram $bin \
          --prefix CHICKEN_INCLUDE_PATH : $out/share \
          --prefix CHICKEN_REPOSITORY_PATH : $out/${repositoryPath} \
          --prefix LD_LIBRARY_PATH : ${chicken}/lib
      done

      if [ -d $out/lib ]; then
        find $out/lib -type f -not -name \*.so -delete
      fi

      if [ -d $out/bin ]; then
        for bin in $out/bin/*; do
          wrapProgram $bin \
            --prefix CHICKEN_INCLUDE_PATH : $out/share \
            --prefix CHICKEN_REPOSITORY_PATH : $out/${repositoryPath} \
            --prefix LD_LIBRARY_PATH : ${chicken}/lib
        done
      fi

      runHook postInstall
    '';
  } // removeAttrs args [ "preUnpack" "preBuild" ];

A nix.md => nix.md +59 -0
@@ 0,0 1,59 @@
=== Usage

This library's Nix helpers can be imported from the Git repository archive:

    let
      beaker = import (fetchTarball https://git.sr.ht/~evhan/beaker/archive/master.tar.gz) {};
    in
      doStuff { ... }

The project's `default.nix` only includes two helpers so it's also relatively
harmless to pull into scope, for example:

    with import (fetchTarball https://git.sr.ht/~evhan/beaker/archive/6bfb584b.tar.gz) {};
    
    eggProgram {
      name = "example";
      src = ./.;
      eggCache = eggCache {
        overrideFile = ./example.egg.lock;
        hash = "sha256:00x5k7rhs1fy7fj5kma1yp2ikzbq98bfm33si5y8z8m25chb45sg";
      };
    }

=== Fetching Egg Dependencies

    [procedure] eggCache attrSet

A fixed-output derivation that fetches a set of eggs for installation.

The list of eggs to cache should be specified via `overrideFile`, which
expects a path to a file in "override" specifying a list of egg names and
versions. This file can be generated via `chicken-status -list` (for installed
eggs) or `chicken-lock` (for a specific egg's dependencies).

    eggCache {
      name = "example-egg-cache"
      overrideFile = ./eggs.lock
      hash = "sha256:03pz5927dkazrf8hf53w03r80ca98fwp09gmd8iiywxc5vl8ll2m"
    }

=== Building Eggs

    [procedure] eggProgram attrSet

Builds any eggs in the given `src` directory, bundling all dependencies and
placing the resulting binaries into `<path>/bin`.

Egg dependencies must be provided via `eggCache` so that all inputs are known
at build time. If any dependencies are missing from the cache, the build will
fail with the error message `"extension or version not found: <egg>"`.

    eggProgram {
      name = "example-program";
      src = ./.;
      eggCache = eggCache { ... };
    }

Apart from `eggCache`, this derivation accepts all the same attributes as
`stdenv.mkDerivation`.