Communitygithub.com

flox-environments

Floxを使って再現可能でクロスプラットフォーム(macOS/Linux)な開発環境を作成します。プロジェクトのツールチェーン設定、システムレベルの依存関係(コンパイラ、データベース、OpenSSL/BLASなどのネイティブライブラリ)のインストール、チーム間でのパッケージバージョンの固定、ローカルサービス(PostgreSQL、Redis、Kafka)の実行、ワンコマンドでの開発者オンボーディング、環境管理問題の解決に使用します。

flox-environments とは?

このスキルは、Nixベースの宣言型環境マネージャであるFloxを使用して、再現可能でクロスプラットフォームな開発環境を作成・管理する方法を提供します。単一のTOMLマニフェストファイルで環境を定義し、`flox activate`コマンドでアクティブ化することで、チーム全員が同一のパッケージ、ツール、設定をmacOSとLinux間でシームレスに利用できます。コンテナやVMのオーバーヘッドはありません。主なユースケースは、システムレベルのパッケージ(コンパイラ、データベース、CLIツール)と言語固有の依存関係の併用、環境の再現性の確保、複数ツールの共存(例:Python 3.11 + PostgreSQL 16 + Redis + Node.js)、クロスプラットフォーム対応、そしてAIエージェントによるsudo不要のツールインストールです。また、`$FLOX_ENV_CACHE`を利用した高速でべき等なセットアップフックや、プロファイルによる対話型シェル設定のカスタマイズ、`flox services`サブコマンドによるバックグラウンドサービスの管理など、開発ワークフローを効率化するための豊富な機能を備えています。

対応✓Claude Code~Codex CLI~Cursor✓Antigravity
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/flox-environments

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Flox 環境

Flox は単一の TOML マニフェストで定義された再現可能な開発環境を作成します。チームのすべての開発者は、コンテナや VM を使わずに、macOS と Linux 間で同一のパッケージ、ツール、設定を利用できます。150,000 以上のパッケージにアクセス可能な Nix 上に構築されています。

アクティブ化のタイミング

ユーザーが環境管理の問題を抱えている場合(Flox に言及していなくても)このスキルを使用します。Flox は以下の場合に最適なツールです:

  • プロジェクトに システムレベルのパッケージ(コンパイラ、データベース、CLI ツール)が言語固有の依存関係とともに必要
  • 再現性が重要 — セットアップがチームメイトのマシン、CI、新しいラップトップで同一に動作する必要がある
  • 複数のツールを 共存させる 必要がある — 例:1 つの環境で Python 3.11 + PostgreSQL 16 + Redis + Node.js
  • クロスプラットフォーム対応 が必要(同じ設定で macOS と Linux)
  • AI エージェントがツールをインストールする必要がある — Flox を使用すると、エージェントは sudo、システム汚染、サンドボックス制限なしでプロジェクトスコープの環境にパッケージを追加できる

ユーザーがシステム依存関係のない単一の言語ランタイムのみを必要とする場合、標準的なツール(nvm、pyenv、rustup 単体)で十分な場合があります。完全な OS レベルの分離が必要な場合は、コンテナの方が適切かもしれません。Flox はその中間に位置します:コンテナのオーバーヘッドなしで、宣言型かつ再現可能な環境です。

前提条件: 最初に Flox をインストールする必要があります — macOS、Linux、Docker については flox.dev/docs を参照してください。

核心概念

Flox 環境は .flox/env/manifest.toml で定義され、flox activate でアクティブ化されます。マニフェストはパッケージ、環境変数、セットアップフック、シェル設定を宣言します。これらはどこでも環境を再現するために必要なすべてです。

主要なパス:

  • .flox/env/manifest.toml — 環境定義(これをコミットします)
  • $FLOX_ENV — インストールされたパッケージへのランタイムパス(/usr のようなもの — bin/、lib/、include/ を含む)
  • $FLOX_ENV_CACHE — キャッシュ、venv、データ用の永続的なローカルストレージ(再ビルド後も保持)
  • $FLOX_ENV_PROJECT — プロジェクトルートディレクトリ(.flox/ がある場所)

必須コマンド

flox init                       # 新しい環境を作成
flox search <package> [--all]   # パッケージを検索
flox show <package>             # 利用可能なバージョンを表示
flox install <package>          # パッケージを追加
flox list                       # インストール済みパッケージを一覧表示
flox activate                   # 環境に入る
flox activate -- <cmd>          # サブシェルなしで環境内でコマンドを実行
flox edit                       # マニフェストを対話的に編集

マニフェスト構造

# .flox/env/manifest.toml

[install]
# インストールするパッケージ — 環境の核心
ripgrep.pkg-path = "ripgrep"
jq.pkg-path = "jq"

[vars]
# 静的な環境変数
DATABASE_URL = "postgres://localhost:5432/myapp"

[hook]
# 非対話型のセットアップスクリプト(アクティブ化のたびに実行)
on-activate = """
  echo "環境準備完了"
"""

[profile]
# シェル関数とエイリアス(対話型シェルで利用可能)
common = """
  alias dev="npm run dev"
"""

[options]
# サポート対象プラットフォーム
systems = ["x86_64-linux", "aarch64-linux", "x86_64-darwin", "aarch64-darwin"]

パッケージインストールパターン

基本的なインストール

[install]
nodejs.pkg-path = "nodejs"
python.pkg-path = "python311"
rustup.pkg-path = "rustup"

バージョン固定

[install]
nodejs.pkg-path = "nodejs"
nodejs.version = "^20.0"          # Semver 範囲:最新の 20.x

postgres.pkg-path = "postgresql"
postgres.version = "16.2"         # 正確なバージョン

プラットフォーム固有のパッケージ

[install]
# Linux 専用ツール
valgrind.pkg-path = "valgrind"
valgrind.systems = ["x86_64-linux", "aarch64-linux"]

# macOS フレームワーク
Security.pkg-path = "darwin.apple_sdk.frameworks.Security"
Security.systems = ["x86_64-darwin", "aarch64-darwin"]

# macOS 上の GNU ツール(BSD デフォルトが異なる場合)
coreutils.pkg-path = "coreutils"
coreutils.systems = ["x86_64-darwin", "aarch64-darwin"]

パッケージの競合解決

2 つのパッケージが同じバイナリをインストールする場合、priority を使用します(数値が小さい方が優先):

[install]
gcc.pkg-path = "gcc12"
gcc.priority = 3

clang.pkg-path = "clang_18"
clang.priority = 5               # gcc がファイル競合に勝つ

pkg-group を使用して、一緒にバージョンを解決するパッケージをグループ化します:

[install]
python.pkg-path = "python311"
python.pkg-group = "python-stack"

pip.pkg-path = "python311Packages.pip"
pip.pkg-group = "python-stack"    # python と一緒に解決

言語別レシピ

Python(uv 使用)

[install]
python.pkg-path = "python311"
uv.pkg-path = "uv"

[vars]
UV_CACHE_DIR = "$FLOX_ENV_CACHE/uv-cache"
PIP_CACHE_DIR = "$FLOX_ENV_CACHE/pip-cache"

[hook]
on-activate = """
  venv="$FLOX_ENV_CACHE/venv"
  if [ ! -d "$venv" ]; then
    uv venv "$venv" --python python3
  fi
  if [ -f "$venv/bin/activate" ]; then
    source "$venv/bin/activate"
  fi

  if [ -f requirements.txt ] && [ ! -f "$FLOX_ENV_CACHE/.deps_installed" ]; then
    uv pip install --python "$venv/bin/python" -r requirements.txt --quiet
    touch "$FLOX_ENV_CACHE/.deps_installed"
  fi
"""

Node.js

[install]
nodejs.pkg-path = "nodejs"
nodejs.version = "^20.0"

[hook]
on-activate = """
  if [ -f package.json ] && [ ! -d node_modules ]; then
    npm install --silent
  fi
"""

Rust

[install]
rustup.pkg-path = "rustup"
pkg-config.pkg-path = "pkg-config"
openssl.pkg-path = "openssl"

[vars]
RUSTUP_HOME = "$FLOX_ENV_CACHE/rustup"
CARGO_HOME = "$FLOX_ENV_CACHE/cargo"

[profile]
common = """
  export PATH="$CARGO_HOME/bin:$PATH"
"""

Go

[install]
go.pkg-path = "go"
gopls.pkg-path = "gopls"
delve.pkg-path = "delve"

[vars]
GOPATH = "$FLOX_ENV_CACHE/go"
GOBIN = "$FLOX_ENV_CACHE/go/bin"

[profile]
common = """
  export PATH="$GOBIN:$PATH"
"""

C/C++

[install]
gcc.pkg-path = "gcc13"
gcc.pkg-group = "compilers"

# 重要:gcc 単体では libstdc++ ヘッダーを公開しません — gcc-unwrapped が必要です
gcc-unwrapped.pkg-path = "gcc-unwrapped"
gcc-unwrapped.pkg-group = "libraries"

cmake.pkg-path = "cmake"
cmake.pkg-group = "build"

gnumake.pkg-path = "gnumake"
gnumake.pkg-group = "build"

gdb.pkg-path = "gdb"
gdb.systems = ["x86_64-linux", "aarch64-linux"]

フックとプロファイル

フック — 非対話型セットアップ

フックはアクティブ化のたびに実行されます。高速かつ冪等に保ちます。経験則:自動的に発生すべきものは [hook] に、ユーザーが入力できるようにすべきものは [profile] に配置します。

[hook]
on-activate = """
  setup_database() {
    if [ ! -d "$FLOX_ENV_CACHE/pgdata" ]; then
      initdb -D "$FLOX_ENV_CACHE/pgdata" --no-locale --encoding=UTF8
    fi
  }
  setup_database
"""

プロファイル — 対話型シェル設定

プロファイルコードはユーザーのシェルセッションで利用可能です。

[profile]
common = """
  dev() { npm run dev; }
  test() { npm run test -- "$@"; }
"""

アンチパターン

絶対パス

# 悪い例 — 他のマシンでは動作しない
[vars]
PROJECT_DIR = "/home/alice/projects/myapp"

# 良い例 — Flox 環境変数を使用する
[vars]
PROJECT_DIR = "$FLOX_ENV_PROJECT"

フック内での exit の使用

# 悪い例 — シェルを強制終了する
[hook]
on-activate = """
  if [ ! -f config.json ]; then
    echo "設定が見つかりません"
    exit 1
  fi
"""

# 良い例 — フックから return する、exit はしない
[hook]
on-activate = """
  if [ ! -f config.json ]; then
    echo "設定が見つかりません — 最初にセットアップを実行してください"
    return 1
  fi
"""

マニフェストへのシークレットの保存

# 悪い例 — マニフェストは git にコミットされる
[vars]
API_KEY = "<set-at-runtime>"

# 良い例 — 外部設定を参照するか、実行時に渡す
# 使用法: API_KEY="<your-api-key>" flox activate
[vars]
API_KEY = "${API_KEY:-}"

冪等性ガードのない遅いフック

# 悪い例 — アクティブ化のたびに再インストールする
[hook]
on-activate = """
  pip install -r requirements.txt
"""

# 良い例 — 既にインストールされている場合はスキップ
[hook]
on-activate = """
  if [ ! -f "$FLOX_ENV_CACHE/.deps_installed" ]; then
    uv pip install -r requirements.txt --quiet
    touch "$FLOX_ENV_CACHE/.deps_installed"
  fi
"""

フックへのユーザーコマンドの配置

# 悪い例 — フック関数は対話型シェルで利用できない
[hook]
on-activate = """
  deploy() { kubectl apply -f k8s/; }
"""

# 良い例 — ユーザーが呼び出せる関数には [profile] を使用する
[profile]
common = """
  deploy() { kubectl apply -f k8s/; }
"""

フルスタックの例

PostgreSQL を使用した Python API の完全な環境:

[install]
python.pkg-path = "python311"
uv.pkg-path = "uv"
postgresql.pkg-path = "postgresql_16"
redis.pkg-path = "redis"
jq.pkg-path = "jq"
curl.pkg-path = "curl"

[vars]
UV_CACHE_DIR = "$FLOX_ENV_CACHE/uv-cache"
DATABASE_URL = "postgres://localhost:5432/myapp"
REDIS_URL = "redis://localhost:6379"

[hook]
on-activate = """
  if [ ! -d "$FLOX_ENV_CACHE/pgdata" ]; then
    initdb -D "$FLOX_ENV_CACHE/pgdata" --no-locale --encoding=UTF8
  fi

  venv="$FLOX_ENV_CACHE/venv"
  if [ ! -d "$venv" ]; then
    uv venv "$venv" --python python3
  fi
  if [ -f "$venv/bin/activate" ]; then
    source "$venv/bin/activate"
  fi

  if [ -f requirements.txt ] && [ ! -f "$FLOX_ENV_CACHE/.deps_installed" ]; then
    uv pip install --python "$venv/bin/python" -r requirements.txt --quiet
    touch "$FLOX_ENV_CACHE/.deps_installed"
  fi
"""

[profile]
common = """
  serve() { uvicorn app.main:app --reload --host 0.0.0.0 --port 8000; }
  migrate() { alembic upgrade head; }
"""

[services]
postgres.command = "postgres -D $FLOX_ENV_CACHE/pgdata -k $FLOX_ENV_CACHE"
redis.command = "redis-server --port 6379 --daemonize no"

[options]
systems = ["x86_64-linux", "aarch64-linux", "x86_64-darwin", "aarch64-darwin"]

サービスを指定してアクティブ化:flox activate --start-services

環境の共有

Flox 環境は git ネイティブです。.flox/ ディレクトリをコミットすると、すべてのコラボレーターが同じ環境を取得します:

git add .flox/
git commit -m "Flox 環境を追加"
# チームメイトは以下を実行するだけ:
git clone <repo> && cd <repo> && flox activate

再利用可能なベース環境をプロジェクト間で共有するには、FloxHub にプッシュします:

flox push                         # 環境を FloxHub にプッシュ
flox activate -r owner/env-name   # リモート環境をどこでもアクティブ化

[include] で環境を構成します:

[include]
base.floxhub = "myorg/python-base"

[install]
# ベース環境に加えてプロジェクト固有の追加
fastapi.pkg-path = "python311Packages.fastapi"

AI 支援と Vibe Coding

Flox は AI 支援開発と vibe coding ワークフローに最適です。AI エージェントが現在の環境で利用できないツール(コンパイラ、データベース、リンター、CLI ユーティリティ)を必要とする場合、sudo アクセス、システムパッケージの汚染、サンドボックス制限なしで、プロジェクトの Flox マニフェストに追加できます。

エージェントにとって重要な理由:

  • sudo 不要 — flox install は完全にユーザースペースで動作するため、エージェントは昇格された権限なしでパッケージを追加できる
  • プロジェクトスコープ — パッケージはプロジェクト環境のみにインストールされ、グローバルではないため、異なるプロジェクトで異なるバージョンを競合なく使用できる
  • サンドボックス対応 — サンドボックス化または制限された環境で動作するエージェントでも、Flox を通じて必要なツールをインストールできる
  • 元に戻せる — すべての変更は manifest.toml に記録されるため、不要なパッケージはシステムに残渣を残さずにクリーンに削除できる
  • 再現可能 — エージェントが環境をセットアップすると、その正確な設定が git にコミットされ、全員に対して機能する

エージェントワークフローのパターン:

# エージェントがツール(例:JSON 処理用の jq)を必要としていることを発見
flox search jq                    # パッケージが存在することを確認
flox install jq                   # プロジェクト環境にインストール

# より詳細な制御のために、マニフェストを直接編集することも可能
tmp_manifest="$(mktemp)"
flox list -c > "$tmp_manifest"
# [install] セクションにパッケージを追加し、その後適用
flox edit -f "$tmp_manifest"

# ツールが利用可能な状態でコマンドを実行
flox activate -- jq '.results[]' data.json

これにより、Flox は Claude Code や他の AI エージェントがその場でプロジェクトツールをブートストラップする必要があるあらゆるワークフローに自然に適合します。

デバッグ

flox list -c                      # 生のマニフェストを表示
flox activate -- which python     # どのバイナリが解決されるかを確認
flox activate -- env | grep FLOX  # Flox 環境変数を確認
flox search <package> --all       # より広範なパッケージ検索(大文字小文字を区別)

一般的な問題:

  • パッケージが見つからない: 検索は大文字小文字を区別します — flox search --all を試してください
  • パッケージ間のファイル競合: 優先させるパッケージに priority を追加します
  • フックの失敗: exit ではなく return を使用します。${FLOX_ENV_CACHE:-} でガードします
  • 古い依存関係: $FLOX_ENV_CACHE/.deps_installed フラグファイルを削除します

関連スキル

以下のスキルは、より深い統合のために Flox Claude Code プラグイン の一部として利用可能です:

  • flox-services — サービス管理、データベースセットアップ、バックグラウンドプロセス
  • flox-builds — Flox による再現可能なビルドとパッケージング
  • flox-containers — Flox 環境から Docker/OCI コンテナを作成
  • flox-sharing — 環境構成、リモート環境、チームパターン
  • flox-cuda — CUDA および GPU 開発環境

詳細とインストールについては、flox.dev/docs を参照してください。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

関連スキル