new user config module style

This commit is contained in:
2025-12-17 15:37:59 -05:00
parent 3ff1128765
commit db96137bb4
4 changed files with 109 additions and 297 deletions

189
README.md
View File

@@ -1,183 +1,40 @@
# User Configuration Template
# hdh20267-nix
This directory contains templates for creating external user configuration modules that can be referenced from the main `nixos-systems/users.nix` file.
## Overview
External user modules allow users to maintain their personal configurations (dotfiles, packages, settings) in separate Git repositories and reference them from the main `nixos-systems` repository using `builtins.fetchGit`.
Personal NixOS and home-manager configuration for hdh20267.
## Structure
```
user-dotfiles-repo/
├── home.nix # Required: Home-manager configuration
├── nixos.nix # Optional: System-level NixOS configuration
├── README.md # Documentation
└── dotfiles/ # Optional: Dotfiles to symlink
```
This repository contains:
- `user.nix` - User account options and home-manager configuration
- `nixos.nix` - System-level NixOS configuration (optional)
## Usage
### 1. Create Your User Configuration Repository
Copy the templates from this directory to your own Git repository:
- `home.nix` - Required for home-manager configuration
- `nixos.nix` - Optional for system-level configuration
### 2. Reference It in users.nix
Reference this repository in the main nixos-systems users.nix:
```nix
{
ugaif.users = {
myusername = {
description = "My Name";
extraGroups = [ "wheel" "networkmanager" ];
shell = pkgs.zsh;
hdh20267.external = builtins.fetchGit {
url = "https://github.com/hdh20267/hdh20267-nix";
rev = "commit-hash"; # Pin to specific commit
};
# Option 1: External module from Git
home = builtins.fetchGit {
url = "https://github.com/username/dotfiles";
rev = "abc123def456..."; # Full commit hash for reproducibility
ref = "main"; # Optional: branch/tag name
};
# Option 2: Local path for testing
# home = /path/to/local/dotfiles;
# Option 3: Inline configuration
# home = {
# home.packages = [ pkgs.vim ];
# programs.git.enable = true;
# };
};
};
}
# Or for local development:
hdh20267.external = /path/to/hdh20267-nix;
```
### 3. Enable on Systems
## Files
Enable the user in `inventory.nix`:
### user.nix
```nix
{
"my-system" = {
devices = {
"hostname" = {
extraUsers = [ "myusername" ];
};
};
};
}
```
This file configures both:
1. User account options (description, shell, groups, etc.)
2. Home-manager configuration (packages, programs, dotfiles, etc.)
## File Descriptions
The same file is imported in two contexts:
- As a NixOS module to read ugaif.users.hdh20267 options
- As a home-manager module for user environment
### home.nix (Required)
### nixos.nix
This file contains your home-manager configuration. It must be a valid NixOS module that accepts `{ inputs, ... }` and returns a home-manager configuration.
**Must export:**
- Home-manager options (programs.*, home.packages, etc.)
**Receives:**
- `inputs` - Flake inputs (nixpkgs, home-manager, etc.)
- `config` - Home-manager config
- `pkgs` - Nixpkgs package set
- `osConfig` - Access to OS-level configuration
### nixos.nix (Optional)
This file contains system-level NixOS configuration. Only needed for:
- System services related to the user
- System packages requiring root
- Special permissions or system settings
## Examples
### Minimal home.nix
```nix
{ inputs, ... }:
{ config, lib, pkgs, ... }:
{
home.packages = with pkgs; [
vim
git
htop
];
programs.git = {
enable = true;
userName = "My Name";
userEmail = "me@example.com";
};
}
```
### With Dotfiles
```nix
{ inputs, ... }:
{ config, lib, pkgs, ... }:
{
home.packages = with pkgs; [ ripgrep fd bat ];
# Symlink dotfiles
home.file.".bashrc".source = ./dotfiles/bashrc;
home.file.".vimrc".source = ./dotfiles/vimrc;
programs.git = {
enable = true;
userName = "My Name";
userEmail = "me@example.com";
};
}
```
### With System Configuration (nixos.nix)
```nix
{ inputs, ... }:
{ config, lib, pkgs, ... }:
{
# Add user to docker group
users.users.myusername.extraGroups = [ "docker" ];
# Install system package
environment.systemPackages = [ pkgs.docker ];
}
```
## Integration Features
External user modules:
- Receive the same flake inputs as nixos-systems
- Can use all home-manager options
- Optionally provide system-level configuration (nixos.nix)
- System zsh theme applied if `useZshTheme = true` (default)
- System nvim config applied if `useNvimPlugins = true` (default)
- Merged with inventory.nix user settings (groups, shell, etc.)
## Development Workflow
1. Create your user config repository with `home.nix`
2. Test locally: `home = /path/to/local/repo;`
3. Build: `nix build .#nixosConfigurations.hostname.config.system.build.toplevel`
4. Commit and push changes
5. Update users.nix with commit hash
6. Deploy to systems
## Benefits
- **Personal Ownership**: Users maintain their own configs
- **Version Control**: Track dotfile changes over time
- **Portability**: Use same config across multiple machines
- **Reproducibility**: Pin to specific commits
- **Privacy**: Use private repositories for personal settings
- **Separation**: Keep personal configs separate from system configs
System-level configuration that requires root privileges.
Optional - only needed for system services, special permissions, etc.

View File

@@ -1,23 +0,0 @@
# User Configuration for hdh20267
{ inputs, pkgs, ... }:
let
zshPackage = pkgs.zsh;
homeConfig = ./home.nix;
in
{
description = "HDH";
shell = zshPackage;
hashedPassword = "!";
enable = true; # Enable by default
opensshKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBC7xzHxY2BfFUybMvG4wHSF9oEAGzRiLTFEndLvWV/X hdh20267@engr733847d.engr.uga.edu"
];
home = homeConfig;
useZshTheme = true;
useNvimPlugins = true;
}

107
home.nix
View File

@@ -1,107 +0,0 @@
{ inputs, ... }:
# ============================================================================
# User Home Manager Configuration Template
# ============================================================================
# This file provides home-manager configuration for a user.
# It will be imported into the NixOS system's home-manager configuration.
#
# Usage in users.nix:
# myusername = {
# description = "My Name";
# home = builtins.fetchGit {
# url = "https://github.com/username/dotfiles";
# rev = "commit-hash";
# };
# };
#
# This module receives the same `inputs` flake inputs as the main
# nixos-systems configuration (nixpkgs, home-manager, etc.).
{
config,
lib,
pkgs,
osConfig, # Access to the OS-level config
...
}:
{
# ========== Home Manager Configuration ==========
# User identity (required)
home.username = lib.mkDefault config.home.username; # Set by system
home.homeDirectory = lib.mkDefault config.home.homeDirectory; # Set by system
home.stateVersion = lib.mkDefault "25.11";
# ========== Packages ==========
home.packages = with pkgs; [
htop
ripgrep
fd
bat
];
# ========== Programs ==========
# Git configuration
programs.git = {
enable = true;
settings = {
init.defaultBranch = "main";
user = {
name = "Hunter Halloran";
email = "hdh20267@uga.edu";
};
};
};
# Zsh configuration
programs.zsh = {
enable = true;
# System theme is applied automatically if useZshTheme = true in users.nix
# Add your custom zsh config here
};
programs.vscode = {
enable = true;
package = pkgs.vscode.fhs;
profiles.default.extensions = with pkgs.vscode-extensions; [
vscodevim.vim
jnoortheen.nix-ide
ms-vscode-remote.vscode-remote-extensionpack
ms-vscode-remote.remote-ssh
ms-python.python
ms-python.vscode-pylance
ms-python.debugpy
github.copilot
];
};
# Neovim configuration
# programs.neovim = {
# enable = true;
# # System nvim config is applied automatically if useNvimPlugins = true
# # Add your custom neovim config here
# };
# ========== Shell Environment ==========
home.sessionVariables = {
EDITOR = "nvim";
# Add your custom environment variables
};
# ========== Dotfiles ==========
# You can manage dotfiles with home.file
# home.file.".bashrc".source = ./dotfiles/bashrc;
# home.file.".vimrc".source = ./dotfiles/vimrc;
# Or use programs.* options for better integration
# ========== XDG Configuration ==========
xdg.enable = true;
# xdg.configFile."app/config.conf".source = ./config/app.conf;
}

85
user.nix Normal file
View File

@@ -0,0 +1,85 @@
{ inputs, ... }:
# ============================================================================
# User Configuration for hdh20267
# ============================================================================
# This file configures BOTH:
# 1. User account options (ugaif.users.hdh20267)
# 2. Home-manager configuration (home.*, programs.*, services.*)
{
config,
lib,
pkgs,
osConfig ? null,
...
}:
{
# ========== User Account Configuration ==========
ugaif.users.hdh20267 = {
description = "Hunter Halloran";
shell = pkgs.zsh;
hashedPassword = "!";
opensshKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBC7xzHxY2BfFUybMvG4wHSF9oEAGzRiLTFEndLvWV/X hdh20267@engr733847d.engr.uga.edu"
];
useZshTheme = true;
useNvimPlugins = true;
};
# ========== Home Manager Configuration ==========
# Packages
home.packages = with pkgs; [
htop
ripgrep
fd
bat
] ++ lib.optional (osConfig.ugaif.sw.type or null == "desktop") ghostty;
# ========== Programs ==========
# Git configuration
programs.git = {
enable = true;
userName = "Hunter Halloran";
userEmail = "hdh20267@uga.edu";
extraConfig = {
init.defaultBranch = "main";
};
};
# Zsh configuration
programs.zsh = {
enable = true;
# System theme is applied automatically if useZshTheme = true
};
programs.vscode = {
enable = true;
package = pkgs.vscode.fhs;
extensions = with pkgs.vscode-extensions; [
vscodevim.vim
jnoortheen.nix-ide
ms-vscode-remote.vscode-remote-extensionpack
ms-vscode-remote.remote-ssh
ms-python.python
ms-python.vscode-pylance
ms-python.debugpy
github.copilot
];
};
# ========== Shell Environment ==========
home.sessionVariables = {
EDITOR = "nvim";
};
# ========== XDG Configuration ==========
xdg.enable = true;
}