MCP HubMCP Hub
返回技能列表

flox-builds

flox
更新于 Today
16 次查看
3
3
在 GitHub 上查看
design

关于

The flox-builds skill enables application building and packaging using Flox's two main approaches. Manifest builds allow quick adoption of existing workflows with sandbox support, while Nix expression builds provide fully isolated, reproducible builds at the cost of learning Nix. Use manifest builds for getting started quickly and Nix builds when you need guaranteed reproducibility.

技能文档

Flox Build System Guide

Build System Overview

Flox supports two build modes, each with its own strengths:

Manifest builds enable you to define your build steps in your manifest and reuse your existing build scripts and toolchains. Flox manifests are declarative artifacts, expressed in TOML.

Manifest builds:

  • Make it easy to get started, requiring few if any changes to your existing workflows
  • Can run inside a sandbox (using sandbox = "pure") for reproducible builds
  • Are best for getting going fast with existing projects

Nix expression builds guarantee build-time reproducibility because they're both isolated and purely functional. Their learning curve is steeper because they require proficiency with the Nix language.

Nix expression builds:

  • Are isolated by default. The Nix sandbox seals the build off from the host system, so no state leak ins
  • Are functional. A Nix build is defined as a pure function of its declared inputs

You can mix both approaches in the same project, but package names must be unique.

Core Commands

flox build                      # Build all targets
flox build app docs             # Build specific targets
flox build -d /path/to/project  # Build in another directory
flox build -v                   # Verbose output
flox build .#hello              # Build specific Nix expression

Manifest Builds

Flox treats a manifest build as a short, deterministic Bash script that runs inside an activated environment and copies its deliverables into $out. Anything copied there becomes a first-class, versioned package that can later be published and installed like any other catalog artifact.

Critical insights from real-world packaging:

  • Build hooks don't run: [hook] scripts DO NOT execute during flox build - only during interactive flox activate
  • Guard env vars: Always use ${FLOX_ENV_CACHE:-} with default fallback in hooks to avoid build failures
  • Wrapper scripts pattern: Create launcher scripts in $out/bin/ that set up runtime environment:
    cat > "$out/bin/myapp" << 'EOF'
    #!/usr/bin/env bash
    APP_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
    export PYTHONPATH="$APP_ROOT/share/myapp:$PYTHONPATH"
    exec python3 "$APP_ROOT/share/myapp/main.py" "$@"
    EOF
    chmod +x "$out/bin/myapp"
    
  • User config pattern: Default to ~/.myapp/ for user configs, not $FLOX_ENV_CACHE (packages are immutable)
  • Model/data directories: Create user directories at runtime, not build time:
    mkdir -p "${MYAPP_DIR:-$HOME/.myapp}/models"
    
  • Python package strategy: Don't bundle Python deps - include requirements.txt and setup script:
    # In build, create setup script:
    cat > "$out/bin/myapp-setup" << 'EOF'
    venv="${VENV:-$HOME/.myapp/venv}"
    uv venv "$venv" --python python3
    uv pip install --python "$venv/bin/python" -r "$APP_ROOT/share/myapp/requirements.txt"
    EOF
    
  • Dual-environment workflow: Build in project-build/, use package in project/:
    cd project-build && flox build myapp
    cd ../project && flox install owner/myapp
    

Build Definition Syntax

[build.<name>]
command      = '''  # required – Bash, multiline string
  <your build steps>                 # e.g. cargo build, npm run build
  mkdir -p $out/bin
  cp path/to/artifact $out/bin/<name>
'''
version      = "1.2.3"               # optional
description  = "one-line summary"    # optional
sandbox      = "pure" | "off"        # default: off
runtime-packages = [ "id1", "id2" ]  # optional

One table per package. Multiple [build.*] tables let you publish, for example, a stripped release binary and a debug build from the same sources.

Bash only. The script executes under set -euo pipefail. If you need zsh or fish features, invoke them explicitly inside the script.

Environment parity. Before your script runs, Flox performs the equivalent of flox activate — so every tool listed in [install] is on PATH.

Package groups and builds. Only packages in the toplevel group (default) are available during builds. Packages with explicit pkg-group settings won't be accessible in build commands unless also installed to toplevel.

Referencing other builds. ${other} expands to the $out of [build.other] and forces that build to run first, enabling multi-stage flows (e.g. vendoring → compilation).

Purity and Sandbox Control

sandbox valueFilesystem scopeNetworkTypical use-case
"off" (default)Project working tree; complete host FSallowedFast, iterative dev builds
"pure"Git-tracked files only, copied to tmpLinux: blocked<br>macOS: allowedReproducible, host-agnostic packages

Pure mode highlights undeclared inputs early and is mandatory for builds intended for CI/CD publication. When a pure build needs pre-fetched artifacts (e.g. language modules) use a two-stage pattern:

[build.deps]
command  = '''go mod vendor -o $out/etc/vendor'''
sandbox  = "off"

[build.app]
command  = '''
  cp -r ${deps}/etc/vendor ./vendor
  go build ./...
  mkdir -p $out/bin
  cp app $out/bin/
'''
sandbox  = "pure"

$out Layout and Filesystem Hierarchy

Only files placed under $out survive. Follow FHS conventions:

PathPurpose
$out/bin / $out/sbinCLI and daemon binaries (must be chmod +x)
$out/lib, $out/libexecShared libraries, helper programs
$out/share/manMan pages (gzip them)
$out/etcConfiguration shipped with the package

Scripts or binaries stored elsewhere will not end up on callers' paths.

Running Manifest Builds

# Build every target in the manifest
flox build

# Build a subset
flox build app docs

# Build a manifest in another directory
flox build -d /path/to/project

Results appear as immutable symlinks: ./result-<name>/nix/store/...-<name>-<version>.

To execute a freshly built binary: ./result-app/bin/app.

Multi-Stage Examples

Rust release binary plus source tar

[build.bin]
command = '''
  cargo build --release
  mkdir -p $out/bin
  cp target/release/myproject $out/bin/
'''
version = "0.9.0"

[build.src]
command = '''
  git archive --format=tar HEAD | gzip > $out/myproject-${bin.version}.tar.gz
'''
sandbox = "pure"

${bin.version} resolves because both builds share the same manifest.

Go with vendored dependencies

[build.vendor]
command = '''
  go mod vendor
  mkdir -p $out/vendor
  cp -r vendor/* $out/vendor/
'''
sandbox = "off"

[build.app]
command = '''
  cp -r ${vendor}/vendor ./
  go build -mod=vendor -o $out/bin/myapp
'''
sandbox = "pure"

Trimming Runtime Dependencies

By default, every package in the toplevel install-group becomes a runtime dependency of your build's closure—even if it was only needed at compile time.

Declare a minimal list instead:

[install]
clang.pkg-path = "clang"
pytest.pkg-path = "pytest"

[build.cli]
command = '''
  make
  mv build/cli $out/bin/
'''
runtime-packages = [ "clang" ]  # exclude pytest from runtime closure

Smaller closures copy faster and occupy less disk when installed on users' systems.

Version and Description Metadata

Flox surfaces these fields in flox search, flox show, and during publication.

[build.mytool]
version.command = "git describe --tags"
description = "High-performance log shipper"

Alternative forms:

version = "1.4.2"            # static string
version.file = "VERSION.txt" # read at build time

Cross-Platform Considerations for Manifest Builds

flox build targets the host's systems triple. To ship binaries for additional platforms you must trigger the build on machines (or CI runners) of those architectures:

linux-x86_64 → build → publish
darwin-aarch64 → build → publish

The manifest can remain identical across hosts.

Beyond Code — Packaging Assets

Any artifact that can be copied into $out can be versioned and installed:

Nginx baseline config

[build.nginx_cfg]
command = '''mkdir -p $out/etc && cp nginx.conf $out/etc/'''

Organization-wide .proto schema bundle

[build.proto]
command = '''
  mkdir -p $out/share/proto
  cp proto/**/*.proto $out/share/proto/
'''

Teams install these packages and reference them via $FLOX_ENV/etc/nginx.conf or $FLOX_ENV/share/proto.

Nix Expression Builds

You can write a Nix expression instead of (or in addition to) defining a manifest build.

Put *.nix build files in .flox/pkgs/ for Nix expression builds. Git add all files before building.

File Naming

  • hello.nix → package named hello
  • hello/default.nix → package named hello

Common Patterns

Shell Script

{writeShellApplication, curl}:
writeShellApplication {
  name = "my-ip";
  runtimeInputs = [ curl ];
  text = ''curl icanhazip.com'';
}

Your Project

{ rustPlatform, lib }:
rustPlatform.buildRustPackage {
  pname = "my-app";
  version = "0.1.0";
  src = ../../.;
  cargoLock.lockFile = "${src}/Cargo.lock";
}

Update Version

{ hello, fetchurl }:
hello.overrideAttrs (finalAttrs: _: {
  version = "2.12.2";
  src = fetchurl {
    url = "mirror://gnu/hello/hello-${finalAttrs.version}.tar.gz";
    hash = "sha256-WpqZbcKSzCTc9BHO6H6S9qrluNE72caBm0x6nc4IGKs=";
  };
})

Apply Patches

{ hello }:
hello.overrideAttrs (oldAttrs: {
  patches = (oldAttrs.patches or []) ++ [ ./my.patch ];
})

Hash Generation

  1. Use hash = "";
  2. Run flox build
  3. Copy hash from error message

Commands

  • flox build - build all
  • flox build .#hello - build specific
  • git add .flox/pkgs/* - track files

Language-Specific Build Examples

Python Application

[build.myapp]
command = '''
  mkdir -p $out/bin $out/share/myapp

  # Copy application code
  cp -r src/* $out/share/myapp/
  cp requirements.txt $out/share/myapp/

  # Create wrapper script
  cat > $out/bin/myapp << 'EOF'
#!/usr/bin/env bash
APP_ROOT="$(dirname "$(dirname "$(readlink -f "$0")")")"
export PYTHONPATH="$APP_ROOT/share/myapp:$PYTHONPATH"
exec python3 "$APP_ROOT/share/myapp/main.py" "$@"
EOF
  chmod +x $out/bin/myapp
'''
version = "1.0.0"

Node.js Application

[build.webapp]
command = '''
  npm ci
  npm run build

  mkdir -p $out/share/webapp
  cp -r dist/* $out/share/webapp/
  cp package.json package-lock.json $out/share/webapp/

  cd $out/share/webapp && npm ci --production
'''
version = "1.0.0"

Rust Binary

[build.cli]
command = '''
  cargo build --release
  mkdir -p $out/bin
  cp target/release/mycli $out/bin/
'''
version.command = "cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version'"

Debugging Build Issues

Common Problems

Build hooks don't run: [hook] scripts DO NOT execute during flox build

Package groups: Only toplevel group packages available during builds

Network access: Pure builds can't access network on Linux

Debugging Steps

  1. Check build output: flox build -v
  2. Inspect result: ls -la result-<name>/
  3. Test binary: ./result-<name>/bin/<name>
  4. Check dependencies: nix-store -q --references result-<name>

Related Skills

  • flox-environments - Setting up build environments
  • flox-publish - Publishing built packages to catalogs
  • flox-containers - Building container images

快速安装

/plugin add https://github.com/flox/flox-agentic/tree/main/flox-builds

在 Claude Code 中复制并粘贴此命令以安装该技能

GitHub 仓库

flox/flox-agentic
路径: flox-plugin/skills/flox-builds

相关推荐技能

langchain

LangChain是一个用于构建LLM应用程序的框架,支持智能体、链和RAG应用开发。它提供多模型提供商支持、500+工具集成、记忆管理和向量检索等核心功能。开发者可用它快速构建聊天机器人、问答系统和自主代理,适用于从原型验证到生产部署的全流程。

查看技能

project-structure

这个Skill为开发者提供全面的项目目录结构设计指南和最佳实践。它涵盖了多种项目类型包括monorepo、前后端框架、库和扩展的标准组织结构。帮助团队创建可扩展、易维护的代码架构,特别适用于新项目设计、遗留项目迁移和团队规范制定。

查看技能

issue-documentation

该Skill为开发者提供标准化的issue文档模板和指南,适用于创建bug报告、GitHub/Linear/Jira问题等场景。它能系统化地记录问题状况、复现步骤、根本原因、解决方案和影响范围,确保团队沟通清晰高效。通过实施主流问题跟踪系统的最佳实践,帮助开发者生成结构完整的故障排除文档和事件报告。

查看技能

llamaindex

LlamaIndex是一个专门构建RAG应用的开发框架,提供300多种数据连接器用于文档摄取、索引和查询。它具备向量索引、查询引擎和智能代理等核心功能,支持构建文档问答、知识检索和聊天机器人等数据密集型应用。开发者可用它快速搭建连接私有数据与LLM的RAG管道。

查看技能