Skip to content

Quick Start

This guide will walk you through creating your first DHD module and applying it to your system.

Create a new file called essentials.ts:

import { defineModule, packageInstall, gitConfig, directory, copyFile } from "dhd";
export default defineModule("essentials")
.description("My essential system setup")
.tags(["core", "setup"])
.actions([
// Install essential packages
packageInstall({
names: ["git", "curl", "wget", "vim", "tmux"]
}),
// Configure git globally
gitConfig({
scope: "global",
settings: {
"user.name": "Your Name",
"user.email": "your.email@example.com",
"init.defaultBranch": "main",
"pull.rebase": "true"
}
}),
// Create common directories
directory({ path: "~/projects" }),
directory({ path: "~/.config" }),
directory({ path: "~/.local/bin" })
]);

DHD automatically discovers TypeScript files in your current directory:

Terminal window
# List all modules
dhd list
# Output:
# Available modules:
# essentials - My essential system setup [core, setup]

Before applying changes, preview what DHD will do:

Terminal window
dhd apply --dry-run
# Output shows planned actions without making changes:
# [DRY RUN] Would install packages: git, curl, wget, vim, tmux
# [DRY RUN] Would set git config user.name = "Your Name"
# [DRY RUN] Would create directory: ~/projects
# ...

When you’re ready, apply the configuration:

Terminal window
dhd apply
# DHD will:
# 1. Check what's already configured
# 2. Apply only necessary changes
# 3. Show progress for each action
# 4. Report success/failure

Let’s create a development environment module:

development.ts
import { defineModule, packageInstall, executeCommand, linkFile, platform } from "dhd";
export default defineModule("development")
.description("Development environment setup")
.tags(["dev", "tools"])
.dependsOn(["essentials"]) // Requires essentials module first
.actions([
// Language runtimes
platform.select({
linux: packageInstall({
names: ["nodejs", "npm", "python3", "python3-pip"]
}),
macos: packageInstall({
names: ["node", "python3"],
manager: "brew"
})
}),
// Development tools
packageInstall({
names: ["docker", "docker-compose"],
manager: platform.isLinux() ? "native" : "brew"
}),
// Configure npm
executeCommand({
command: "npm config set init-author-name 'Your Name'"
}),
// Link dotfiles
linkFile({
source: "./dotfiles/vimrc",
destination: "~/.vimrc"
})
]);

Step 6: Use Tags for Selective Application

Section titled “Step 6: Use Tags for Selective Application”

Apply only specific tagged modules:

Terminal window
# Apply only core modules
dhd apply --tags core
# Apply dev tools but exclude docker
dhd apply --tags dev --exclude-tags docker
# Apply specific modules
dhd apply --modules essentials,development
import { platform, packageInstall } from "dhd";
// Different actions per platform
platform.select({
ubuntu: packageInstall({ names: ["neovim"] }),
macos: packageInstall({ names: ["neovim"], manager: "brew" }),
fedora: packageInstall({ names: ["neovim"], manager: "dnf" })
});
// Conditional execution
if (platform.isLinux()) {
// Linux-specific actions
}
export default defineModule("dotfiles")
.description("Symlink all dotfiles")
.actions([
// Link individual files
linkFile({
source: "./dotfiles/zshrc",
destination: "~/.zshrc",
force: true // Overwrite if exists
}),
// Link entire directory
linkDirectory({
source: "./dotfiles/config",
destination: "~/.config",
merge: true // Merge with existing directory
})
]);
export default defineModule("services")
.description("Configure system services")
.actions([
// Create a systemd service
systemdService({
name: "my-backup.service",
description: "Daily backup service",
execStart: "/home/user/scripts/backup.sh",
serviceType: "oneshot"
}),
// Enable and start the service
systemdManage({
unit: "my-backup.service",
operation: "enable"
})
]);
  1. Start Small: Begin with essential tools and gradually add more modules
  2. Use Tags: Organize modules with meaningful tags for easy filtering
  3. Test with Dry Run: Always preview changes before applying
  4. Version Control: Keep your DHD modules in a git repository
  5. Document Actions: Use clear descriptions for modules and actions

A typical DHD project might look like:

my-system-config/
├── essentials.ts # Core system setup
├── development.ts # Dev tools and languages
├── dotfiles/ # Configuration files
│ ├── vimrc
│ ├── zshrc
│ └── gitconfig
├── work/ # Work-specific modules
│ ├── vpn.ts
│ └── corporate.ts
└── personal/ # Personal modules
├── gaming.ts
└── media.ts

Now that you’ve created your first DHD modules: