Initialize hx in an existing project.
Synopsis
hx init [OPTIONS]Description
The init command initializes hx in an existing Haskell project by creating an hx.toml configuration file. It detects existing Cabal configuration and toolchain settings.
Options
--force Overwrite existing hx.toml
--ghc <VERSION> Specify GHC version
--backend <BACKEND> Compiler backend [ghc, bhc]
--detect Auto-detect settings from existing configuration
-v, --verbose Show detailed outputExamples
Basic Initialization
cd existing-project
hx initWith Auto-Detection
# Detect GHC version from cabal.project or stack.yaml
hx init --detectForce Overwrite
hx init --forceSpecify GHC Version
hx init --ghc 9.8.2Initialize with BHC Backend
hx init --backend bhcThis sets [compiler].backend = "bhc" in the generated hx.toml with sensible defaults for the BHC profile.
What It Does
Detects existing configuration
- Reads
.cabalfiles for package info - Checks
cabal.projectfor GHC settings - Checks
stack.yamlif present
- Reads
Creates hx.toml
- Generates configuration based on detected settings
- Sets up toolchain pinning
Does NOT modify
- Existing
.cabalfiles cabal.projectstack.yaml- Source files
- Existing
Generated hx.toml
Based on detection:
[project]
name = "detected-name"
version = "detected-version"
[toolchain]
ghc = "9.8.2" # Detected or specified
[build]
ghc-options = ["-Wall"]
# If cabal.project exists with freeze file
[dependencies]
lock-strategy = "cabal-freeze"Detection Sources
hx looks for settings in:
| Source | Detects |
|---|---|
*.cabal | Package name, version |
cabal.project | GHC version, packages |
cabal.project.freeze | Pinned dependencies |
stack.yaml | Resolver, extra-deps |
| System PATH | Active GHC version |
Migrating from Stack
If you have a Stack project:
cd stack-project
hx init --detecthx will:
- Read resolver from
stack.yaml - Map to equivalent GHC version
- Create
hx.tomlwith settings
You can then use hx alongside or instead of Stack.
Migrating from Cabal
If you have a Cabal-only project:
cd cabal-project
hx init --detecthx will:
- Read settings from
cabal.project - Create
hx.tomlwith configuration - Respect existing
cabal.project.freeze
After Initialization
After hx init:
# Verify environment
hx doctor
# Build
hx build
# Generate lockfile
hx lockSee Also
- hx new — Create new project
- Compiler Backends — GHC vs BHC
- Configuration Reference