Skip to content

Commit

Permalink
feat(flake): implement justfile
Browse files Browse the repository at this point in the history
  • Loading branch information
airone01 committed Nov 10, 2024
1 parent 0297b95 commit 128467e
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 76 deletions.
161 changes: 104 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# airone01/flake

A modular and extensible NixOS configuration system using a custom star-based architecture. This repository contains my personal NixOS configurations for multiple machines and deployments.
A modular and extensible NixOS configuration system using a custom star-based architecture. This repository contains my personal NixOS configurations for multiple machines and deployments, managed with a comprehensive task runner.

## 📚 Table of Contents

- [Features](#features)
- [Structure](#structure)
- [Getting Started](#getting-started)
- [Usage](#usage)
- [Architecture](#architecture)
- [Contributing](#contributing)
- [Roadmap](#roadmap)

## ✨ Features

- 🌟 Modular "star" system for composable configurations
- 🛠️ Comprehensive task runner using Just
- 🔒 Secret management with sops-nix
- 🚀 Development shells for various tasks
- 📦 Multiple machine configurations
- 🔄 Automated formatting and checks
- 💾 ISO generation capabilities

## 🏗️ Structure

```
Expand Down Expand Up @@ -39,41 +51,94 @@ A modular and extensible NixOS configuration system using a custom star-based ar

- NixOS or Nix with flakes enabled
- Git
- `just` command runner
- (Optional) sops for secret management

### Installation

1. Clone the repository:
1. Install the `just` command runner:
```bash
nix-env -iA nixpkgs.just
```

2. Bootstrap a new system:
```bash
git clone https://github.com/airone01/dotfiles2 ~/.config/nixos
just bootstrap <hostname>
```

2. Review and modify the configuration:
This will:
- Set up the nix channels
- Install required tools
- Clone the repository
- Prepare the system for configuration

3. Generate SOPS key (if using secrets):
```bash
just sops-key
```

4. Review and modify the configuration:
- Choose or create a constellation in `constellations/`
- Modify `flake.nix` to include your system
- Adjust hardware configuration as needed

3. Deploy the configuration:
5. Deploy the configuration:
```bash
# For an existing system
nixos-rebuild switch --flake .#hostname
just switch <hostname>
```

# For a new installation
nixos-install --flake .#hostname
## 🛠️ Usage

### System Management

```bash
# Build and switch to configuration
just switch <hostname>

# Test configuration without applying
just test <hostname>

# Build ISO image
just iso [system] [format]

# Clean old generations
just clean [days]
```

### Development Environment
### Development Tasks

```bash
# Format nix files
just fmt

# Check formatting
just fmt-check

The repository includes development shells for various tasks:
# Run flake checks
just check

# Enter development shell
just develop [shell-name]

# Show changes to nix files
just show-diff
```

### Update Management

```bash
# For commit message linting
nix develop .#commitlint
# Update all flake inputs
just update

# For Tauri development
nix develop .#tauri
# Update specific input
just update-input <input-name>
```

### Available Development Shells

- `commitlint`: For commit message linting
- `tauri`: For Tauri application development (JS/TS support included)

## 🏛️ Architecture

### The Star System
Expand Down Expand Up @@ -107,6 +172,24 @@ Secrets are managed using sops-nix with age encryption:
- Secrets are stored in `secrets/`
- Keys are configured in `.sops.yaml`
- Each constellation can access only its required secrets
- Generate keys with `just sops-key`

## 📦 Machines

### aquarius
- Purpose: Home server
- Services: Caddy, planned hosting for various services
- Status: Active

### cassiopeia
- Purpose: Desktop workstation
- Features: GNOME desktop, development tools
- Status: Active

### ursamajor
- Purpose: Installation ISO
- Features: Basic system for testing and installation
- Status: In Development

## 🤝 Contributing

Expand All @@ -118,10 +201,10 @@ This is my flake and it's mainly personal but contributions are welcome if you h
4. Run the following checks:
```bash
# Format code
nix fmt
just fmt

# Verify builds
nix flake check
just check
```
5. Commit your changes (following commitlint conventions)
6. Push to your branch
Expand Down Expand Up @@ -150,7 +233,7 @@ Scopes: See `.commitlintrc.yml` for valid scopes
| Documentation | Create contribution guidelines | Medium | 🔴 Not Started |
| Testing | Add GitHub Actions workflows | High | 🔴 Not Started |
| Testing | Implement basic system tests | Medium | 🔴 Not Started |
| Testing | Add Nix formatting checks | High | 🔴 Not Started |
| Testing | Add Nix formatting checks | High | 🟢 Complete |
| Security | Implement firewall configuration | High | 🔴 Not Started |
| Security | Add fail2ban configuration | Medium | 🔴 Not Started |
| Security | Configure automatic security updates | High | 🔴 Not Started |
Expand All @@ -174,52 +257,15 @@ Scopes: See `.commitlintrc.yml` for valid scopes
| Infrastructure | Add Syncthing instance | Low | 🔴 Not Started |
| Infrastructure | Add Calibre-Web instance | Low | 🔴 Not Started |
| Infrastructure | Add Photoprism instance | Low | 🔴 Not Started |
| Architecture | Task runner implementation | High | 🟢 Complete |
| Architecture | Figuring all of this out | High | 🟣 Always going on |


Legend:
- 🟢 Complete
- 🟡 In Progress/Partial
- 🔴 Not Started
- 🟣 Special

## 🔧 Tooling

### Available Development Shells

- `commitlint`: For commit message linting
- `tauri`: For Tauri application development (I use it for JS/TS as well)

### Useful Commands

```bash
# Rebuild the current system
./rebuild.sh <hostname>

# Build an ISO image
nix build .#ursamajor-install-iso

# Enter development shell
nix develop .#<shell-name>
```

## 📦 Machines

### aquarius
- Purpose: Home server
- Services: Caddy, planned hosting for various services
- Status: Active

### cassiopeia
- Purpose: Desktop workstation
- Features: GNOME desktop, development tools
- Status: Active

### ursamajor
- Purpose: Installation ISO
- Features: Basic system for testing and installation
- Status: In Development

## 📄 License

This project is open source and available under the Apache v2 license.
Expand All @@ -228,5 +274,6 @@ This project is open source and available under the Apache v2 license.

- [NixOS](https://nixos.org/) for the amazing Linux distribution
- All the fantastic Nix community members who share their configurations
- NotAShelf for inspiration
- [NotAShelf](https://github.com/NotAShelf) for inspiration
- [casey/just](https://github.com/casey/just) for the fantastic command runner
- Contributors to all the tools and packages used in this configuration
1 change: 1 addition & 0 deletions constellations/cassiopeia/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
boot-plymouth
cli-btop
cli-eza
cli-just
cli-nvim
cli-oh-my-posh
cli-zellij
Expand Down
136 changes: 136 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Variables
hostname := `hostname`
flake_dir := env_var_or_default("FLAKE_DIR", "~/.config/nixos")
flake_url := env_var_or_default("FLAKE_URL", "github:airone01/flake")

# Default recipe to display help
default:
@just --list

# Build and switch to a new configuration
switch host=hostname *args="": check-dirty
#!/usr/bin/env bash
set -euo pipefail
echo "🔄 Rebuilding system for {{host}}..."
sudo nixos-rebuild switch --flake {{flake_dir}}#{{host}} {{args}} 2>&1 | tee nixos-switch.log || (
grep --color error nixos-switch.log && false
)
echo "✅ System successfully rebuilt!"
# Build and test configuration without switching
test host=hostname *args="": check-dirty
#!/usr/bin/env bash
set -euo pipefail
echo "🧪 Testing configuration for {{host}}..."
nixos-rebuild test --flake {{flake_dir}}#{{host}} {{args}} 2>&1 | tee nixos-test.log || (
grep --color error nixos-test.log && false
)
echo "✅ Test build successful!"
# Build an ISO image
iso system="ursamajor" format="install-iso":
#!/usr/bin/env bash
set -euo pipefail
echo "📀 Building {{format}} for {{system}}..."
nix build {{flake_dir}}#{{system}}-{{format}}
echo "✅ ISO build complete!"
# Update all flake inputs
update:
#!/usr/bin/env bash
set -euo pipefail
echo "⬆️ Updating flake inputs..."
nix flake update {{flake_dir}}
echo "✅ Flake inputs updated!"
# Update specific flake input
update-input input:
#!/usr/bin/env bash
set -euo pipefail
echo "⬆️ Updating {{input}}..."
nix flake lock {{flake_dir}} --update-input {{input}}
echo "✅ {{input}} updated!"
# Format all nix files
fmt:
#!/usr/bin/env bash
set -euo pipefail
echo "🎨 Formatting nix files..."
find . -name "*.nix" -exec alejandra {} +
echo "✅ Formatting complete!"
# Check nix file formatting
fmt-check:
#!/usr/bin/env bash
set -euo pipefail
echo "🔍 Checking nix formatting..."
find . -name "*.nix" -exec alejandra --check {} +
echo "✅ Format check passed!"
# Run checks on the flake
check:
#!/usr/bin/env bash
set -euo pipefail
echo "🔍 Running flake checks..."
nix flake check {{flake_dir}}
echo "✅ All checks passed!"
# Clean old generations
clean generations="14d":
#!/usr/bin/env bash
set -euo pipefail
echo "🧹 Cleaning generations older than {{generations}}..."
sudo nix-collect-garbage --delete-older-than {{generations}}
sudo /run/current-system/bin/switch-to-configuration switch
echo "✅ System cleaned!"
# Enter a development shell
develop shell="commitlint":
#!/usr/bin/env bash
set -euo pipefail
echo "🚀 Launching {{shell}} development environment..."
nix develop {{flake_dir}}#{{shell}}
# Show the diff of staged nix files
show-diff:
git diff -U0 *.nix

# Internal recipe to check for dirty git state
[private]
check-dirty:
#!/usr/bin/env bash
if [ -n "$(git status --porcelain)" ]; then
echo "⚠️ Warning: Working directory is dirty. Uncommitted changes may be lost."
echo "Continue? [y/N]"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Operation cancelled."
exit 1
fi
fi
# Generate an initial SOPS key
sops-key:
#!/usr/bin/env bash
set -euo pipefail
echo "🔑 Generating SOPS age key..."
mkdir -p ~/.config/sops/age
if [ ! -f ~/.config/sops/age/keys.txt ]; then
age-keygen -o ~/.config/sops/age/keys.txt
echo "✅ Key generated at ~/.config/sops/age/keys.txt"
else
echo "⚠️ Key already exists at ~/.config/sops/age/keys.txt"
fi
# Bootstrap a new system
bootstrap host tools="git curl":
#!/usr/bin/env bash
set -euo pipefail
echo "🚀 Bootstrapping new system for {{host}}..."
sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos
sudo nix-channel --update
sudo nix-env -iA nixos.{{tools}}
if [ ! -d "{{flake_dir}}" ]; then
git clone {{flake_url}} {{flake_dir}}
fi
echo "✅ Bootstrap complete! You can now run: just switch {{host}}"
Loading

0 comments on commit 128467e

Please sign in to comment.