[Refactor]: Project Restructure #84
Labels
No labels
blocked: external
bug
documentation
feature
optimization
refactor
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kruziikrel13/NixOS#84
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refactor Summary
No response
Motivation
Make my config less confusing!
Scope
All!
NixOS Configuration Restructure Recommendations
Date: December 1, 2024
Updated: December 1, 2024
Purpose: Restructure configuration for better common/host-specific separation and potential home-manager → hjem migration
User Requirements
Current Configuration Analysis
Your current setup has:
aridhol(laptop) andstriking_distance(desktop)modules/personalModule/system/home/Current Pain Points:
Recommended Directory Structure
Key Design Principles
1. Separation of Concerns
hosts/= host-specific config only (hostname, monitors, hardware quirks)profiles/= reusable, composable configuration chunksmodules/= custom module definitions2. Common vs Specific
profiles/core/= Config shared by ALL hosts and environmentsprofiles/environments/{work,personal}/= Environment-specific bundleshosts/= ONLY truly host-specific config (hostname, monitors, hardware quirks)3. Home Manager → hjem Migration Path
profiles/home/abstracted from HM-specific syntax where possibleprofiles/core/home/and environment wrappersprofiles/home/remain mostly unchanged4. Composability
5. File Organization
default.nixto import and expose sibling filesExample Implementation
Host Configuration (Work Laptop - aridhol)
File:
hosts/aridhol/default.nixFile:
hosts/aridhol/user.nix(home-manager wrapper)Host Configuration (Gaming Desktop - striking-distance)
File:
hosts/striking-distance/default.nixFile:
hosts/striking-distance/user.nixCore Configuration (Shared Across All Hosts)
File:
profiles/core/nixos/default.nixFile:
profiles/core/nixos/boot.nixFile:
profiles/core/nixos/nix.nixFile:
profiles/core/nixos/users.nixFile:
profiles/core/nixos/networking.nixFile:
profiles/core/nixos/security.nixFile:
profiles/core/home/default.nixFile:
profiles/core/home/packages.nixFile:
profiles/core/home/shell.nixFile:
profiles/core/home/git.nixFile:
profiles/core/home/xdg.nixEnvironment Profiles - Work/University
File:
profiles/environments/work/nixos/default.nixFile:
profiles/environments/work/nixos/packages.nixFile:
profiles/environments/work/nixos/hardware.nixFile:
profiles/environments/work/user/default.nixFile:
profiles/environments/work/user/hyprland.nixFile:
profiles/environments/work/user/apps.nixFile:
profiles/environments/work/user/development.nixFile:
profiles/environments/work/user/semester.nixEnvironment Profiles - Personal/Gaming
File:
profiles/environments/personal/nixos/default.nixFile:
profiles/environments/personal/nixos/gaming.nixFile:
profiles/environments/personal/nixos/graphics.nixFile:
profiles/environments/personal/nixos/packages.nixFile:
profiles/environments/personal/user/default.nixFile:
profiles/environments/personal/user/hyprland.nixFile:
profiles/environments/personal/user/gaming.nixFile:
profiles/environments/personal/user/media.nixFile:
profiles/environments/personal/user/apps.nixShared Home-Manager Building Blocks
File:
profiles/home/development/default.nixFile:
profiles/home/development/nvim/default.nixFile:
profiles/home/development/tools.nixFile:
profiles/home/desktop/hyprland/default.nixFile:
profiles/home/desktop/hyprland/settings/default.nixFile:
profiles/home/desktop/hyprland/settings/general.nixFile:
profiles/home/desktop/hyprland/settings/decoration.nixFile:
profiles/home/desktop/hyprland/settings/animations.nixFile:
profiles/home/desktop/hyprland/settings/input.nixFile:
profiles/home/desktop/hyprland/binds.nixFile:
profiles/home/desktop/hyprland/rules.nixFile:
profiles/home/desktop/hyprland/workspaces.nixMigration Strategy
Phase 1: Create Structure & Core Config
git commit -am "backup before restructure"system/core/*→ split intoprofiles/core/nixos/{boot,nix,users,security}.nixsystem/network/*→profiles/core/nixos/networking.nixhome/configs →profiles/core/home/hosts/default.niximportsnixos-rebuild build --flake .#aridholPhase 2: Create Shared Building Blocks
home/programs/git.nix→profiles/core/home/git.nixhome/programs/nvim.nix→profiles/home/development/nvim/modules/personalModule/hyprlandConfig/→profiles/home/desktop/hyprland/profiles/hardware/laptop.nixfrom aridhol's laptop-specific configPhase 3: Create Environment Profiles
profiles/environments/work/{nixos,user}/directoriesprofiles/environments/personal/{nixos,user}/directoriesPhase 4: Update Host Configs
hosts/aridhol/default.nixto import work environmenthosts/striking-distance/default.nixto import personal environmenthosts/striking-distance/audio.nixas-isnixos-rebuild build --flake .#{aridhol,striking-distance}Phase 5: Abstract for hjem (Future - Optional)
hosts/*/user.nixfilesBenefits of This Structure
✅ Clear Environment Separation
✅ Clear Organization
✅ Reduced Duplication
✅ Composable
✅ Migration-Friendly
✅ Testable
Mapping Your Current Structure
system/core/boot.nixprofiles/core/nixos/boot.nixsystem/core/users.nixprofiles/core/nixos/users.nixsystem/core/security.nixprofiles/core/nixos/security.nixsystem/core/safe.nixprofiles/core/nixos/system/nix/profiles/core/nixos/nix.nixsystem/nix/overlays.nixoverlays/default.nixsystem/network/profiles/core/nixos/networking.nixsystem/hardware/profiles/core/nixos/, laptop →profiles/hardware/home/programs/cli.nixprofiles/core/home/packages.nixhome/programs/git.nixprofiles/core/home/git.nixhome/programs/gtk.nixprofiles/home/desktop/gtk.nixhome/programs/nvim.nixprofiles/home/development/nvim/home/programs/quickshell.nixprofiles/home/desktop/quickshell/home/programs/zen.nixhome/programs/vesktop.nixprofiles/environments/personal/user/apps.nixmodules/personalModule/hyprlandConfig/profiles/home/desktop/hyprland/modules/personalModule/gaming.nixprofiles/environments/personal/nixos/gaming.nixhosts/aridhol/laptop configprofiles/hardware/laptop.nixhosts/aridhol/home/extra.nixprofiles/environments/work/user/hosts/striking-distance/home/gaming.nixprofiles/environments/personal/user/gaming.nixhosts/striking-distance/audio.nixhosts/striking-distance/audio.nixmodules/nixosModules/modules/nixos/modules/homeManagerModules/modules/home/File Organization Best Practices
Split Files When:
Keep Together When:
Example: Hyprland Settings
Split: Settings into general.nix, decoration.nix, animations.nix, input.nix
Why: Environment profiles override animations/decoration differently
Split: binds.nix, rules.nix, workspaces.nix separate
Why: Each is independently large and logically distinct
Additional Considerations
Semester-Specific Changes (Work Environment)
Update
profiles/environments/work/user/semester.nixeach semester:Switching Environments
If you ever want to test personal config on laptop or work config on desktop:
Then rebuild. Easy environment switching!
Secrets Management
Consider adding for VPN configs, API keys, etc:
Use
sops-nixoragenixfor encrypted secrets.Testing Strategy
Adding a New Host
hosts/new-host/{default.nix,hardware.nix,user.nix}hosts/default.nixNext Steps
git commitbefore startingAdditional Resources
This document is a living guide. Update it as your configuration evolves!