feat: Add templates for external configs

This commit is contained in:
UGA Innovation Factory
2025-12-16 16:09:08 -05:00
committed by Hunter Halloran
parent f658a4a5cc
commit 11edaada84
17 changed files with 1102 additions and 23 deletions

3
templates/system/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
result
result-*
.direnv/

View File

@@ -0,0 +1,99 @@
# External System Module Template
This directory contains a template for creating external system configuration modules that can be referenced from the main `nixos-systems` repository.
## Overview
External modules allow you to maintain system configurations in separate Git repositories and reference them from the main `nixos-systems/inventory.nix` file using `builtins.fetchGit` or `builtins.fetchTarball`.
## Usage
### 1. Create Your Module Repository
Copy `default.nix` from this template to your own Git repository. Customize it with your system configuration.
### 2. Reference It in inventory.nix
```nix
{
"my-system-type" = {
devices = {
"hostname" = builtins.fetchGit {
url = "https://github.com/your-org/your-config-repo";
rev = "abc123def456..."; # Full commit hash for reproducibility
ref = "main"; # Optional: branch/tag name
};
};
};
}
```
### 3. Module Structure
Your `default.nix` must:
- Accept `{ inputs, ... }` as parameters (you'll receive the same flake inputs)
- Return a valid NixOS module with `{ config, lib, pkgs, ... }: { ... }`
- Export configuration under the `config` attribute
## Examples
### Simple Configuration Module
```nix
{ inputs, ... }:
{ config, lib, pkgs, ... }:
{
config = {
time.timeZone = "America/New_York";
environment.systemPackages = with pkgs; [
vim
git
htop
];
services.openssh.enable = true;
};
}
```
### Advanced Module with Options
```nix
{ inputs, ... }:
{ config, lib, pkgs, ... }:
{
options.myorg.databaseUrl = lib.mkOption {
type = lib.types.str;
description = "Database connection URL";
};
config = {
# Use the option
services.postgresql = {
enable = true;
# ... configuration using config.myorg.databaseUrl
};
};
}
```
## Benefits
- **Separation of Concerns**: Keep specialized configurations in dedicated repositories
- **Reusability**: Share configurations across multiple NixOS fleets
- **Version Control**: Pin to specific commits for reproducibility
- **Team Ownership**: Different teams can maintain their own config repos
- **Security**: Private repositories for sensitive configurations
## Integration with nixos-systems
External modules are automatically integrated into the nixos-systems build:
- They receive the same flake inputs (nixpkgs, home-manager, etc.)
- They can use ugaif.* options if defined in the host type
- They are merged with local overrides and base configuration
- They work with all build methods (ISO, LXC, Proxmox, etc.)

View File

@@ -0,0 +1,56 @@
{ inputs, ... }:
# ============================================================================
# External System Module Template
# ============================================================================
# This is a template for creating external system configuration modules
# that can be referenced from nixos-systems/inventory.nix using builtins.fetchGit
#
# Usage in inventory.nix:
# "my-type" = {
# devices = {
# "hostname" = builtins.fetchGit {
# url = "https://github.com/your-org/your-config-repo";
# rev = "commit-hash";
# };
# };
# };
#
# This module will receive the same `inputs` flake inputs as the main
# nixos-systems configuration, allowing you to use nixpkgs, home-manager, etc.
{
config,
lib,
pkgs,
...
}:
{
# ========== Module Options ==========
# Define any custom options your module needs
options = {
# Example: myorg.customOption = lib.mkOption { ... };
};
# ========== Module Configuration ==========
config = {
# Your system configuration goes here
# This can include any NixOS options
# Example: Set timezone
# time.timeZone = "America/New_York";
# Example: Install packages
# environment.systemPackages = with pkgs; [
# vim
# git
# ];
# Example: Configure services
# services.openssh.enable = true;
# Example: Use ugaif options if available from nixos-systems
# ugaif.users.myuser.enable = true;
};
}