docs: formalize maintenance, packaging, and environment workflows
This commit is contained in:
1 parent
9cce8f1c1b
commit
476d1ac0d7
5 files changed
+289
-4
No files matched your search
@@ -101,6 +101,13 @@ flowchart TD
|
||||
* `gacp <message>` — Shorthand to stage all edits, commit with a message, and push directly to the current branch.
|
||||
* `new-repo <name>` — Scaffolds local files, runs git init, and pushes the project to GitHub using the `gh` CLI.
|
||||
|
||||
### 4. Repository Bundler Utility (`bundle-project`)
|
||||
* **Script Location:** [modules/user/scripts/bundle_project.py](modules/user/scripts/bundle_project.py)
|
||||
* **Features:**
|
||||
* `bundle-project [target_dir] [-o output_file]` — Compresses the structure and contents of a target directory (defaults to `.`) into a single output file (defaults to `output.txt`).
|
||||
* Natively skips binary files and `.git` repositories to prevent pollution.
|
||||
* Automatically runs `eza --tree` and outputs it as a visual guide at the header of the bundle file.
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Secrets Management (SOPS + age)
|
||||
@@ -153,7 +160,11 @@ Rebuild and switch to the profile matching your active target host machine:
|
||||
|
||||
## 📚 Reference Documentation
|
||||
|
||||
* [Secrets Management Details](docs/secrets-management.md) — Secure storage configuration using `sops-nix` and `age`.
|
||||
* [Package & Secrets Workflow Guide](docs/package-and-secrets.md) — Steps for adding custom applications and managing secrets.
|
||||
* [System Maintenance Guide](docs/system-maintenance.md) — Instructions for safe system updates, health checking, and garbage collection.
|
||||
* [Declarative Development Environments](docs/development-environments.md) — How to use nix-shell, devShells, direnv, and uv for project isolation.
|
||||
* [Secrets Management Details](docs/secrets-management.md) — Secure storage bootstrapping using `sops-nix` and `age`.
|
||||
* [Smart DDNS Updater](docs/dynu-ip-monitor.md) — Under-the-hood details of the smart IP change detector and updater.
|
||||
* [Tmux Terminal Multiplexer](docs/tmux.md) — Fast navigation bindings, layouts, and pane splits guide.
|
||||
* [Google Antigravity Setup](docs/antigravity.md) — Technical instructions for packaging and using the Antigravity agent CLI on NixOS.
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
# 💻 Declarative Development Environments
|
||||
|
||||
This guide shows how to run isolated project environments using `nix-shell` or `devShells` alongside `direnv` and `uv` to keep the global system environment clean.
|
||||
|
||||
---
|
||||
|
||||
## ⚡ DevShells and nix-shell
|
||||
|
||||
Instead of installing packages globally in [apps.nix](file:///home/kiskaadee/Config/modules/user/apps.nix) for one-off projects, define them per-project.
|
||||
|
||||
### 1. Classic `shell.nix` (Nix Channels)
|
||||
For standard Nix projects, place a `shell.nix` in your project root:
|
||||
```nix
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
nodejs_20
|
||||
yarn
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "Welcome to the Node.js environment!"
|
||||
'';
|
||||
}
|
||||
```
|
||||
Run `nix-shell` to drop into this isolated shell with `node` and `yarn` pre-loaded.
|
||||
|
||||
### 2. Flake-based `devShell`
|
||||
For modern Flake projects, declare your `devShell` inside your `flake.nix`:
|
||||
```nix
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
go
|
||||
golangci-lint
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
Run `nix develop` to enter this environment.
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Automated Shell Loading with `direnv`
|
||||
|
||||
`direnv` automatically activates your project-specific environment when you `cd` into its directory.
|
||||
|
||||
### Configuration
|
||||
1. In your project root, create a file named `.envrc`.
|
||||
2. Add one of the following lines based on your setup:
|
||||
* **For classic projects (`shell.nix`):**
|
||||
```bash
|
||||
use nix
|
||||
```
|
||||
* **For Flake-based projects (`flake.nix`):**
|
||||
```bash
|
||||
use flake
|
||||
```
|
||||
3. Allow the environment to load:
|
||||
```bash
|
||||
direnv allow
|
||||
```
|
||||
|
||||
As soon as you step into the directory, `direnv` populates `$PATH` and other variables with your Nix-defined tools. Leaving the folder unloads them automatically.
|
||||
|
||||
---
|
||||
|
||||
## 🐍 Python Projects: Nix + `uv` Workflow
|
||||
|
||||
To prevent library conflicts and keep the host system clean, combine Nix (for system-level packages/binaries like C libraries, python compilers) with `uv` (for project-level Python packages).
|
||||
|
||||
### Recommended Workflow:
|
||||
1. **Use Nix (`devShells` or `nix-shell`)** to make Python and system dependencies (like OpenSSL or PostgreSQL drivers) available:
|
||||
```nix
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
python311
|
||||
uv
|
||||
openssl
|
||||
];
|
||||
}
|
||||
```
|
||||
2. **Use `uv`** inside that environment to manage the virtual environment and install Python-specific libraries cleanly:
|
||||
```bash
|
||||
# Create the virtualenv
|
||||
uv venv
|
||||
|
||||
# Activate the environment
|
||||
source .venv/bin/activate
|
||||
|
||||
# Install dependencies lightning-fast without polluting system packages
|
||||
uv pip install fastapi uvicorn
|
||||
```
|
||||
3. **Ensure `.envrc`** loads both the Nix shell and the virtual environment automatically:
|
||||
```bash
|
||||
use flake
|
||||
layout python
|
||||
```
|
||||
This triggers standard Nix tools and sources `.venv/bin/activate` simultaneously upon changing directories.
|
||||
@@ -0,0 +1,82 @@
|
||||
# 📦 Package & Secrets Workflow Guide
|
||||
|
||||
This guide covers the day-to-day workflow for managing user-space packages and sensitive information (secrets) within this NixOS configuration.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Adding a New Package
|
||||
|
||||
User-space applications are managed declaratively using Home Manager in [modules/user/apps.nix](file:///home/kiskaadee/Config/modules/user/apps.nix).
|
||||
|
||||
### Step 1: Find the Package Name
|
||||
Before adding a package, look up its exact attribute name:
|
||||
* **Search Engine:** Go to the official [NixOS Package Search](https://search.nixos.org/packages).
|
||||
* **CLI Search:**
|
||||
```bash
|
||||
nix-env -qaP '<package-name>'
|
||||
# Or using modern flake-native search:
|
||||
nix search nixpkgs <query>
|
||||
```
|
||||
|
||||
### Step 2: Update `apps.nix`
|
||||
Open [modules/user/apps.nix](file:///home/kiskaadee/Config/modules/user/apps.nix) and append the package name directly into the list inside `home.packages`:
|
||||
|
||||
```nix
|
||||
home.packages = with pkgs; [
|
||||
# ... existing packages
|
||||
|
||||
# Text Editors / Development
|
||||
neovim
|
||||
|
||||
# New Package Example
|
||||
ripgrep # Modern grep alternative for fast directory search
|
||||
];
|
||||
```
|
||||
|
||||
### Step 3: Test and Switch
|
||||
Verify the package builds correctly before switching system-wide:
|
||||
```bash
|
||||
# Test build without applying
|
||||
nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link
|
||||
|
||||
# Apply configuration
|
||||
sudo nixos-rebuild switch --flake .#desktop
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Adding a New Secret (SOPS Workflow)
|
||||
|
||||
Sensitive credentials (like passwords, API keys, and environment variables) are managed using `sops-nix`.
|
||||
|
||||
### Step 1: Edit the Secrets File
|
||||
Launch `sops` inside `nix-shell` to decrypt and edit the target secrets file (e.g., [secrets.yaml](file:///home/kiskaadee/Config/hosts/desktop/secrets.yaml)):
|
||||
```bash
|
||||
nix-shell -p sops --run "sops hosts/desktop/secrets.yaml"
|
||||
```
|
||||
Add your key-value pair under the YAML structure:
|
||||
```yaml
|
||||
my_new_api_key: "secure_token_goes_here"
|
||||
```
|
||||
*When you save and close your editor, SOPS automatically encrypts the file before saving it back to disk.*
|
||||
|
||||
### Step 2: Declare the Secret in Nix
|
||||
To make the decrypted secret available to services or applications at runtime, register it in your Nix configuration (e.g., in [hosts/desktop/dynu.nix](file:///home/kiskaadee/Config/hosts/desktop/dynu.nix)):
|
||||
|
||||
```nix
|
||||
sops.secrets.my_new_api_key = {
|
||||
# (Optional) Restrict file access to specific users/groups
|
||||
owner = "root";
|
||||
group = "root";
|
||||
mode = "0400";
|
||||
};
|
||||
```
|
||||
|
||||
### Step 3: Reference the Decrypted Path
|
||||
Once declared, `sops-nix` exposes the decrypted value under `/run/secrets/` at boot time. You can reference the file path dynamically in your Nix configuration using:
|
||||
|
||||
```nix
|
||||
# This resolves to "/run/secrets/my_new_api_key"
|
||||
config.sops.secrets.my_new_api_key.path
|
||||
```
|
||||
Avoid hardcoding raw paths; instead, pass this dynamic path directly to service configurations (e.g., via `EnvironmentFile` or command-line flags).
|
||||
@@ -0,0 +1,78 @@
|
||||
# 🛠️ System Maintenance Guide
|
||||
|
||||
This document describes how to update the system safely, verify its health post-update, and clean up disk space by removing old configurations.
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Performing Clean & Secure System Updates
|
||||
|
||||
NixOS systems managed with Flakes lock dependency versions inside `flake.lock`. To update the system securely, follow this workflow:
|
||||
|
||||
### Step 1: Update the Flake Inputs
|
||||
Fetch the latest revisions of your inputs (e.g., `nixpkgs`, `home-manager`, and other plugins):
|
||||
```bash
|
||||
nix flake update
|
||||
```
|
||||
|
||||
### Step 2: Validate the Build & Formatting
|
||||
Test-build the derivation without applying it to your bootloader. This prevents dirty installations or builder failures (such as Python PEP8 style errors) from affecting system configuration state:
|
||||
```bash
|
||||
nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link
|
||||
```
|
||||
|
||||
### Step 3: Switch & Apply the Update
|
||||
Once the test build completes successfully, switch to the new generation:
|
||||
```bash
|
||||
sudo nixos-rebuild switch --flake .#desktop
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🏥 Post-Update Health Checklist
|
||||
|
||||
Verify system health immediately after a major system switch:
|
||||
|
||||
1. **Systemd Service Status:** Ensure all units are running and no critical services failed:
|
||||
```bash
|
||||
systemctl --failed
|
||||
systemctl --user --failed
|
||||
```
|
||||
2. **Display & Window Manager:** Verify that your graphics drivers, audio services (PipeWire/WirePlumber), and hotkeys are responsive.
|
||||
3. **Secrets Integrity:** Check that decrypted secrets are loaded correctly:
|
||||
```bash
|
||||
ls -la /run/secrets/
|
||||
```
|
||||
4. **Network Resolution:** Check DNS resolution and active IP rotation daemons:
|
||||
```bash
|
||||
systemctl status dynu-monitor.service
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧹 Cleaning Up Old Generations
|
||||
|
||||
Nix keeps older versions (generations) of your system configuration so you can roll back instantly. However, this takes up storage space.
|
||||
|
||||
### Step 1: List System Generations
|
||||
To view all available system generations:
|
||||
```bash
|
||||
sudo nix-env --list-generations --profile /nix/var/nix/profiles/system
|
||||
```
|
||||
|
||||
### Step 2: Delete Old Generations
|
||||
* **Remove older than X days:**
|
||||
```bash
|
||||
sudo nix-env --delete-generations +5d --profile /nix/var/nix/profiles/system
|
||||
```
|
||||
* **Remove specific generations:**
|
||||
```bash
|
||||
sudo nix-env --delete-generations 42 43 --profile /nix/var/nix/profiles/system
|
||||
```
|
||||
|
||||
### Step 3: Collect Garbage (Reclaim Disk Space)
|
||||
Deleting generations only updates configuration links. To actually free up disk space and prune unused dependencies:
|
||||
```bash
|
||||
# Run garbage collection for system and user profiles
|
||||
sudo nix-collect-garbage -d
|
||||
nix-collect-garbage -d
|
||||
```
|
||||
@@ -1,13 +1,17 @@
|
||||
# 📦 User Applications Configuration
|
||||
# This file declares standalone user-space binaries managed by Home Manager.
|
||||
|
||||
{ inputs, pkgs, ... }:
|
||||
|
||||
let
|
||||
# Declaratively compile the Python script as a user utility package
|
||||
bundleProject = pkgs.writers.writePython3Bin "bundle-project" { } (builtins.readFile ./scripts/bundle_project.py);
|
||||
in
|
||||
{
|
||||
home.packages = with pkgs; [
|
||||
# Custom Flake injections: Google Antigravity CLI helper
|
||||
inputs.antigravity.packages.${pkgs.stdenv.hostPlatform.system}.google-antigravity-cli
|
||||
|
||||
# Local Python utilities
|
||||
bundleProject
|
||||
|
||||
# Media, Note-taking & Graphical Tools
|
||||
mpv # Fast, scriptable, keyboard-driven CLI media player
|
||||
gimp # GNU Image Manipulation Program for graphical assets
|
||||
|
||||
Reference in new issue
Block a user