Home Explore Blog Models CI



nixpkgs

4th chunk of `doc/languages-frameworks/factor.section.md`
6885927db8e5be39a4a196820dfdec5ef83fcf664177360c000000010000089e
factorPackages.buildFactorApplication (finalAttrs: {
  pname = "foo";
  version = "1.0";

  src = fetchurl {
    url = "https://some-forge.org/foo-${finalAttrs.version}.tar.gz";
  };
})
```

The `buildFactorApplication` function expects the following source structure for a package `foo-1.0` and produces a `/bin/foo` application:
```
foo-1.0/
  foo/
    foo.factor
    deploy.factor
  <more files and directories>...
```

It provides the additional attributes `vocabName` and `binName` to cope with naming deviations.
The `deploy.factor` file controls how the application is deployed and is documented in the Factor online documentation on the `deploy` facility.

Use the `preInstall` or `postInstall` hooks to copy additional files and directories to `out/`.
The function itself only builds the application in `/lib/factor/` and a wrapper in `/bin/`.

A more complex example shows how to specify runtime dependencies and additional Factor vocabularies at the example of the `painter` Factor application:
```nix
{
  lib,
  fetchFromGitHub,
  factorPackages,
  curl,
}:

factorPackages.buildFactorApplication (finalAttrs: {
  pname = "painter";
  version = "1";

  factor-lang = factorPackages.factor-minimal-gui;

  src = fetchFromGitHub {
    name = finalAttrs.vocabName;
    owner = "Capital-EX";
    repo = "painter";
    rev = "365797be8c4f82440bec0ad0a50f5a858a06c1b6";
    hash = "sha256-VdvnvKNGcFAtjWVDoxyYgRSyyyy0BEZ2MZGQ71O8nUI=";
  };

  sourceRoot = ".";

  enableUI = true;
  extraVocabs = [ factorPackages.bresenham ];

  extraPaths = with finalAttrs.factor-lang; binPackages ++ defaultBins ++ [ curl ];

})
```

The use of the `src.name` and `sourceRoot` attributes conveniently establish the necessary `painter` vocabulary directory that is needed for the deployment to work.

It requires the packager to specify the full set of binaries to be made available at runtime.
This enables the standard pattern for application packages to specify all runtime dependencies explicitly without the Factor runtime interfering.

`buildFactorApplication` is a wrapper around `stdenv.mkDerivation` and takes all of its attributes.
Additional attributes that are understood by `buildFactorApplication`:

Title: Advanced Configuration for Factor Applications with `buildFactorApplication`
Summary
This chunk elaborates on the `buildFactorApplication` function, detailing its expected source structure (e.g., `foo/foo.factor`, `deploy.factor`) and the use of `vocabName` and `binName` for naming flexibility. It highlights the role of `preInstall`/`postInstall` hooks for file copying and provides a complex example using the `painter` application. This example demonstrates how to specify the Factor runtime (`factor-lang`), set up vocabulary directories with `src.name` and `sourceRoot`, enable UI features (`enableUI`), include additional Factor vocabularies (`extraVocabs`), and define explicit runtime dependencies for external binaries via `extraPaths`. The chunk concludes by stating that `buildFactorApplication` is a wrapper around `stdenv.mkDerivation` and supports all its attributes, in addition to its own specific ones.