[Refactor]: Project Restructure #84

Closed
opened 2025-12-01 15:29:03 +10:00 by Ghost · 0 comments
Ghost commented 2025-12-01 15:29:03 +10:00 (Migrated from codeberg.org)

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

  • Single user (kruziikrel13) across all hosts, but username configurable
  • Two environment profiles: Work/University and Personal
  • Configuration split into multiple files for organization
  • Work profile: Minimal, performance-optimized Hyprland (animations disabled), no gaming, varies per semester
  • Personal profile: Gaming, latest drivers, Grayjay, full desktop experience with all bells and whistles
  • Laptop (aridhol): Work/University environment
  • Desktop (striking-distance): Personal/Gaming environment

Current Configuration Analysis

Your current setup has:

  • Two hosts: aridhol (laptop) and striking_distance (desktop)
  • Home-manager integration
  • Custom modules in modules/personalModule/
  • Host-specific configs with some duplication
  • Common system config in system/
  • Common home config in home/

Current Pain Points:

  • Unclear separation between common and host-specific configs
  • Home-manager tightly coupled throughout
  • Difficult to see what's shared vs unique per host/environment
  • Hyprland monitor settings scattered
  • No clear environment (work vs personal) separation

/etc/nixos/
├── flake.nix                    # Main flake entry point
├── flake.lock
│
├── hosts/                       # Host-specific configurations ONLY
│   ├── default.nix             # Host definitions (lib.nixosSystem)
│   │
│   ├── aridhol/                # Work/University laptop
│   │   ├── default.nix         # Host config & profile imports
│   │   ├── hardware.nix        # Hardware-configuration.nix
│   │   └── user.nix            # User config & profile imports
│   │
│   └── striking-distance/      # Personal gaming desktop
│       ├── default.nix
│       ├── hardware.nix
│       ├── audio.nix           # Host-specific audio setup
│       └── user.nix
│
├── profiles/                    # All reusable configuration
│   │
│   ├── core/                   # Common config for ALL hosts & environments
│   │   ├── nixos/              # Common NixOS config
│   │   │   ├── default.nix     # Main common imports
│   │   │   ├── boot.nix        # Boot configuration
│   │   │   ├── nix.nix         # Nix daemon settings, flakes
│   │   │   ├── networking.nix  # Basic network config
│   │   │   ├── security.nix    # Security & hardening
│   │   │   └── users.nix       # User account definition
│   │   │
│   │   └── home/               # Common home-manager config (base user)
│   │       ├── default.nix
│   │       ├── shell.nix       # Bash/zsh config
│   │       ├── git.nix
│   │       ├── xdg.nix
│   │       └── packages.nix    # Essential CLI tools
│   │
│   ├── hardware/               # Hardware-specific profiles
│   │   ├── laptop.nix          # TLP, thermald, battery
│   │   ├── bluetooth.nix
│   │   └── printing.nix
│   │
│   ├── environments/           # Environment-specific profile bundles
│   │   ├── work/               # Work/University environment
│   │   │   ├── nixos/
│   │   │   │   ├── default.nix
│   │   │   │   ├── packages.nix
│   │   │   │   └── hardware.nix    # Minimal graphics, drivers
│   │   │   └── user/
│   │   │       ├── default.nix
│   │   │       ├── hyprland.nix    # Performance-optimized
│   │   │       ├── development.nix
│   │   │       ├── apps.nix
│   │   │       └── semester.nix    # Update per semester
│   │   │
│   │   └── personal/           # Personal/Gaming environment
│   │       ├── nixos/
│   │       │   ├── default.nix
│   │       │   ├── gaming.nix      # Gaming packages, drivers
│   │       │   ├── graphics.nix    # Latest AMD drivers
│   │       │   └── packages.nix
│   │       └── user/
│   │           ├── default.nix
│   │           ├── hyprland.nix    # Full animations & effects
│   │           ├── gaming.nix      # Steam, Lutris, etc.
│   │           ├── media.nix       # Grayjay, media apps
│   │           └── apps.nix        # Desktop apps
│   │
│   ├── nixos/                  # Shared NixOS building blocks
│   │   ├── desktop/
│   │   │   ├── hyprland/
│   │   │   │   ├── default.nix
│   │   │   │   ├── base.nix
│   │   │   │   └── portals.nix
│   │   │   └── audio.nix
│   │   │
│   │   └── services/
│   │       ├── openssh.nix
│   │       └── docker.nix
│   │
│   └── home/                   # Shared home-manager building blocks
│       ├── development/
│       │   ├── default.nix
│       │   ├── nvim/
│       │   │   ├── default.nix
│       │   │   ├── plugins.nix
│       │   │   └── config.nix
│       │   └── tools.nix       # Dev tools, LSPs
│       │
│       └── desktop/
│           ├── hyprland/
│           │   ├── default.nix
│           │   ├── settings/
│           │   │   ├── default.nix
│           │   │   ├── general.nix
│           │   │   ├── decoration.nix
│           │   │   ├── animations.nix
│           │   │   └── input.nix
│           │   ├── binds.nix
│           │   ├── rules.nix
│           │   └── workspaces.nix
│           │
│           ├── gtk.nix
│           └── quickshell/
│               ├── default.nix
│               └── config/
│
├── modules/                     # Custom NixOS/HM modules
│   ├── nixos/
│   │   ├── default.nix
│   │   └── ...
│   └── home/
│       ├── default.nix
│       └── quickshell.nix
│
├── packages/                    # Custom packages
│   ├── default.nix
│   └── bibata-hyprcursor/
│
├── lib/                        # Helper functions
│   └── default.nix
│
└── overlays/                   # Nixpkgs overlays
    └── default.nix

Key Design Principles

1. Separation of Concerns

  • hosts/ = host-specific config only (hostname, monitors, hardware quirks)
  • profiles/ = reusable, composable configuration chunks
  • modules/ = custom module definitions

2. Common vs Specific

  • profiles/core/ = Config shared by ALL hosts and environments
  • profiles/environments/{work,personal}/ = Environment-specific bundles
  • hosts/ = ONLY truly host-specific config (hostname, monitors, hardware quirks)
  • Hosts import: core → environment → host-specific overrides

3. Home Manager → hjem Migration Path

  • Keep user configs in profiles/home/ abstracted from HM-specific syntax where possible
  • When switching to hjem, only modify profiles/core/home/ and environment wrappers
  • Shared building blocks in profiles/home/ remain mostly unchanged

4. Composability

  • Profiles are small, focused modules organized by concern
  • Environment bundles compose shared profiles with environment-specific config
  • Hosts select one environment bundle + host-specific overrides
  • Easy to add new hosts or switch environments

5. File Organization

  • Split large configurations into multiple files
  • Group related settings (hyprland settings split into files per category)
  • Use default.nix to import and expose sibling files
  • Keep individual files focused on one concern

Example Implementation

Host Configuration (Work Laptop - aridhol)

File: hosts/aridhol/default.nix

{ pkgs, ... }: {
  imports = [
    ../../profiles/core/nixos      # Common config across all hosts
    ./hardware.nix
    
    # Work environment (NixOS side)
    ../../profiles/environments/work/nixos
    
    # Laptop-specific hardware profile
    ../../profiles/hardware/laptop.nix
  ];
  
  networking.hostName = "aridhol";
  
  # Host-specific: Latest kernel for laptop
  boot.kernelPackages = pkgs.linuxPackages_latest;
  
  # Host-specific monitor config (for Hyprland)
  programs.hyprland.monitors = [
    "desc:Chimei Innolux Corporation 0x1553,1920x1080@60.0,0x0,0.9999999999999997,bitdepth,10"
    ", preferred, auto, 1, mirror, eDP-1"
  ];
}

File: hosts/aridhol/user.nix (home-manager wrapper)

{ ... }: {
  imports = [
    # Work environment (user side)
    ../../profiles/environments/work/user
  ];
  
  # Host-specific monitor override
  wayland.windowManager.hyprland.settings.monitor = [
    "eDP-1,1920x1080@60,0x0,0.9999999999999997"
  ];
}

Host Configuration (Gaming Desktop - striking-distance)

File: hosts/striking-distance/default.nix

{ ... }: {
  imports = [
    ../../profiles/core/nixos      # Common config across all hosts
    ./hardware.nix
    ./audio.nix                    # Host-specific custom audio setup
    
    # Personal/gaming environment (NixOS side)
    ../../profiles/environments/personal/nixos
  ];
  
  networking.hostName = "striking-distance";
  
  # Host-specific monitor config
  programs.hyprland.monitors = [
    "DP-1,2560x1440@165,0x0,1"
    "HDMI-A-1,1920x1080@60,2560x0,1"
  ];
}

File: hosts/striking-distance/user.nix

{ ... }: {
  imports = [
    # Personal/gaming environment (user side)
    ../../profiles/environments/personal/user
  ];
  
  # Host-specific monitor config
  wayland.windowManager.hyprland.settings.monitor = [
    "DP-1,2560x1440@165,0x0,1"
    "HDMI-A-1,1920x1080@60,2560x0,1"
  ];
  
  # Host-specific gaming overrides if needed
  programs.steam.gamescopeSession.enable = true;
}

Core Configuration (Shared Across All Hosts)

File: profiles/core/nixos/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.;
}

File: profiles/core/nixos/boot.nix

{ ... }: {
  boot = {
    loader.systemd-boot.enable = true;
    loader.efi.canTouchEfiVariables = true;
    tmp.cleanOnBoot = true;
  };
}

File: profiles/core/nixos/nix.nix

{ ... }: {
  nix.settings = {
    experimental-features = [ "nix-command" "flakes" ];
    auto-optimise-store = true;
    warn-dirty = false;
  };
  
  nixpkgs.config.allowUnfree = true;
}

File: profiles/core/nixos/users.nix

{ username, pkgs, ... }: {
  users.users.${username} = {
    isNormalUser = true;
    extraGroups = [ "wheel" "networkmanager" "video" "audio" ];
    shell = pkgs.bash;
  };
  
  # Auto-login
  services.getty = {
    autologinUser = username;
    autologinOnce = true;
  };
}

File: profiles/core/nixos/networking.nix

{ ... }: {
  networking.networkmanager.enable = true;
}

File: profiles/core/nixos/security.nix

{ ... }: {
  security.rtkit.enable = true;
  # Add your existing security settings here
}

File: profiles/core/home/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.;
  
  programs.home-manager.enable = true;  # or hjem in future
  xdg.enable = true;
  
  home.stateVersion = "24.11";
}

File: profiles/core/home/packages.nix

{ pkgs, ... }: {
  # Essential CLI tools for ALL environments
  home.packages = with pkgs; [
    htop
    tree
    fzf
    ripgrep
    fd
    bat
    eza
    curl
    wget
  ];
}

File: profiles/core/home/shell.nix

{ ... }: {
  programs.bash = {
    enable = true;
    # Your bash config
  };
}

File: profiles/core/home/git.nix

{ ... }: {
  programs.git = {
    enable = true;
    userName = "kruziikrel13";
    userEmail = "dev@michaelpetersen.io";
    # Your git config
  };
}

File: profiles/core/home/xdg.nix

{ ... }: {
  xdg = {
    enable = true;
    userDirs = {
      enable = true;
      createDirectories = true;
    };
  };
}

Environment Profiles - Work/University

File: profiles/environments/work/nixos/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.
    ++ [
      ../../../core/nixos         # Core NixOS config
      ../../../nixos/desktop/hyprland  # Shared Hyprland base
    ];
}

File: profiles/environments/work/nixos/packages.nix

{ pkgs, ... }: {
  environment.systemPackages = with pkgs; [
    # Work/University specific tools
    libreoffice
    zotero
    thunderbird
    # NO gaming packages
  ];
}

File: profiles/environments/work/nixos/hardware.nix

{ ... }: {
  # Minimal graphics - no gaming drivers
  hardware.graphics.enable = true;
  
  # No Steam, no gaming optimizations
}

File: profiles/environments/work/user/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.
    ++ [
      ../../../core/home         # Core user config for ALL
      ../../../home/development  # Nvim, git, dev tools
    ];
}

File: profiles/environments/work/user/hyprland.nix

{ ... }: {
  imports = [ ../../../home/desktop/hyprland ];
  
  # Override: Performance-optimized for work/battery
  wayland.windowManager.hyprland.settings = {
    animations.enabled = false;  # DISABLED for performance
    
    decoration = {
      blur.enabled = false;      # DISABLED for battery
      drop_shadow = false;
      rounding = 5;              # Minimal rounding
    };
    
    misc = {
      vfr = true;                # Variable refresh rate
      vrr = 0;
    };
  };
}

File: profiles/environments/work/user/apps.nix

{ pkgs, ... }: {
  home.packages = with pkgs; [
    # Minimal desktop apps for work
    firefox  # or zen-browser
    vscode
    obsidian
  ];
}

File: profiles/environments/work/user/development.nix

{ pkgs, ... }: {
  # Work-specific dev tools if different from personal
  home.packages = with pkgs; [
    # Add semester-specific tools here if needed
  ];
}

File: profiles/environments/work/user/semester.nix

{ pkgs, ... }: {
  # Update this file each semester based on courses
  home.packages = with pkgs; [
    # Example Fall 2024: Data Science
    # python312
    # python312Packages.pandas
    # python312Packages.numpy
    # jupyter
    
    # Example Spring 2025: Systems Programming
    # gcc
    # gdb
    # valgrind
    
    # Current semester tools:
    # Add here...
  ];
}

Environment Profiles - Personal/Gaming

File: profiles/environments/personal/nixos/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.
    ++ [
      ../../../core/nixos         # Core NixOS config
      ../../../nixos/desktop/hyprland  # Shared Hyprland base
    ];
}

File: profiles/environments/personal/nixos/gaming.nix

{ pkgs, ... }: {
  programs = {
    steam = {
      enable = true;
      remotePlay.openFirewall = true;
      dedicatedServer.openFirewall = true;
    };
    gamemode.enable = true;
  };
  
  environment.systemPackages = with pkgs; [
    lutris
    heroic
    protonup-qt
    mangohud
    goverlay
  ];
  
  # Gaming optimizations
  boot.kernel.sysctl = {
    "vm.max_map_count" = 2147483642;
  };
}

File: profiles/environments/personal/nixos/graphics.nix

{ pkgs, ... }: {
  # Latest AMD drivers for gaming
  hardware.graphics = {
    enable = true;
    enable32Bit = true;  # For 32-bit games
  };
  
  # Use latest kernel for gaming performance
  boot.kernelPackages = pkgs.linuxPackages_latest;
}

File: profiles/environments/personal/nixos/packages.nix

{ pkgs, ... }: {
  environment.systemPackages = with pkgs; [
    # Personal desktop packages
    discord
    spotify
  ];
}

File: profiles/environments/personal/user/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.
    ++ [
      ../../../core/home
      ../../../home/development
    ];
}

File: profiles/environments/personal/user/hyprland.nix

{ ... }: {
  imports = [ ../../../home/desktop/hyprland ];
  
  # Override: Full bells and whistles for gaming desktop
  wayland.windowManager.hyprland.settings = {
    animations.enabled = true;  # ENABLED
    
    decoration = {
      blur = {
        enabled = true;          # ENABLED
        size = 8;
        passes = 3;
        new_optimizations = true;
      };
      drop_shadow = true;
      shadow_range = 4;
      shadow_render_power = 3;
      rounding = 10;
    };
    
    misc = {
      vrr = 1;  # Variable refresh rate for gaming
    };
  };
}

File: profiles/environments/personal/user/gaming.nix

{ pkgs, ... }: {
  home.packages = with pkgs; [
    # Gaming-related user packages
    discord
    # Steam managed at system level
    mangohud
    goverlay
  ];
}

File: profiles/environments/personal/user/media.nix

{ pkgs, ... }: {
  home.packages = with pkgs; [
    # grayjay  # Install however you currently do
    vlc
    spotify
    mpv
  ];
}

File: profiles/environments/personal/user/apps.nix

{ pkgs, ... }: {
  home.packages = with pkgs; [
    # Personal desktop applications
    # (Different from work apps)
    gimp
    inkscape
    obs-studio
  ];
}

Shared Home-Manager Building Blocks

File: profiles/home/development/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.;
}

File: profiles/home/development/nvim/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.;
  
  programs.neovim.enable = true;
}

File: profiles/home/development/tools.nix

{ pkgs, ... }: {
  home.packages = with pkgs; [
    # Dev tools common to all environments
    lazygit
    gh
  ];
}

File: profiles/home/desktop/hyprland/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./settings
    ++ [
      ./binds.nix
      ./rules.nix
      ./workspaces.nix
    ];
  
  wayland.windowManager.hyprland.enable = true;
  
  # Base packages
  home.packages = with pkgs; [
    kitty
    rofi-wayland
    waybar
  ];
}

File: profiles/home/desktop/hyprland/settings/default.nix

{ pathLib, ... }: {
  imports = pathLib.scanPaths ./.;
}

File: profiles/home/desktop/hyprland/settings/general.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.general = {
    gaps_in = 5;
    gaps_out = 10;
    border_size = 2;
    # Overridable by environment profiles
  };
}

File: profiles/home/desktop/hyprland/settings/decoration.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.decoration = {
    # Defaults - overridden by environment profiles
    rounding = 10;
  };
}

File: profiles/home/desktop/hyprland/settings/animations.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.animations = {
    enabled = true;  # Default, overridden in work profile to false
    
    bezier = [
      "myBezier, 0.05, 0.9, 0.1, 1.05"
    ];
    
    animation = [
      "windows, 1, 7, myBezier"
      "windowsOut, 1, 7, default, popin 80%"
      "border, 1, 10, default"
      "fade, 1, 7, default"
      "workspaces, 1, 6, default"
    ];
  };
}

File: profiles/home/desktop/hyprland/settings/input.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.input = {
    kb_layout = "us";
    follow_mouse = 1;
    sensitivity = 0;
  };
}

File: profiles/home/desktop/hyprland/binds.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.bind = [
    "SUPER, Return, exec, kitty"
    "SUPER, Q, killactive"
    "SUPER, M, exit"
    "SUPER, E, exec, dolphin"
    "SUPER, V, togglefloating"
    "SUPER, R, exec, rofi -show drun"
    # Your existing binds
  ];
}

File: profiles/home/desktop/hyprland/rules.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.windowrulev2 = [
    # Your existing window rules
  ];
}

File: profiles/home/desktop/hyprland/workspaces.nix

{ ... }: {
  wayland.windowManager.hyprland.settings.workspace = [
    # Your existing workspace config
  ];
}

Migration Strategy

Phase 1: Create Structure & Core Config

  1. Backup everything: git commit -am "backup before restructure"
  2. Create new directory structure (all directories)
  3. Move system/core/* → split into profiles/core/nixos/{boot,nix,users,security}.nix
  4. Move system/network/*profiles/core/nixos/networking.nix
  5. Move basic home/ configs → profiles/core/home/
  6. Update hosts/default.nix imports
  7. Test build: nixos-rebuild build --flake .#aridhol

Phase 2: Create Shared Building Blocks

  1. Move home/programs/git.nixprofiles/core/home/git.nix
  2. Move home/programs/nvim.nixprofiles/home/development/nvim/
  3. Move modules/personalModule/hyprlandConfig/profiles/home/desktop/hyprland/
  4. Split large hyprland config into settings files
  5. Create profiles/hardware/laptop.nix from aridhol's laptop-specific config
  6. Test imports work correctly

Phase 3: Create Environment Profiles

  1. Create profiles/environments/work/{nixos,user}/ directories
  2. Create profiles/environments/personal/{nixos,user}/ directories
  3. Populate work environment with aridhol-specific configs
  4. Populate personal environment with striking-distance-specific configs
  5. Configure work profile: animations disabled, minimal packages
  6. Configure personal profile: gaming, latest drivers, all effects
  7. Use shared building blocks + environment-specific overrides

Phase 4: Update Host Configs

  1. Simplify hosts/aridhol/default.nix to import work environment
  2. Simplify hosts/striking-distance/default.nix to import personal environment
  3. Keep only truly host-specific overrides (monitors, hostname, hardware quirks)
  4. Keep hosts/striking-distance/audio.nix as-is
  5. Test both hosts: nixos-rebuild build --flake .#{aridhol,striking-distance}
  6. Test switch on one host first, then the other

Phase 5: Abstract for hjem (Future - Optional)

  1. Remove HM-specific syntax from shared building blocks where possible
  2. Keep HM wrappers in environment profiles
  3. When ready to migrate, replace HM → hjem in:
    • Environment profile user configs
    • hosts/*/user.nix files
  4. Shared building blocks remain mostly unchanged

Benefits of This Structure

Clear Environment Separation

  • Obvious what's work vs personal
  • Easy to switch laptop to personal or desktop to work if needed
  • Clear what changes per semester vs what's permanent

Clear Organization

  • Obvious what's common vs host-specific
  • Easy to find configurations
  • Scalable to many hosts

Reduced Duplication

  • Common code in one place
  • DRY principle enforced
  • Easier maintenance

Composable

  • Mix and match profiles
  • Easy to add new hosts
  • Reusable components
  • Can test work environment on desktop or vice versa

Migration-Friendly

  • Abstracted user configs
  • Clear separation layers
  • Minimal changes needed for hjem

Testable

  • Can test profiles independently
  • Easy to experiment with new configs
  • Safe to iterate
  • Can build VMs with different environment configs

Mapping Your Current Structure

Current New Location Notes
system/core/boot.nix profiles/core/nixos/boot.nix Split by concern
system/core/users.nix profiles/core/nixos/users.nix
system/core/security.nix profiles/core/nixos/security.nix
system/core/safe.nix profiles/core/nixos/ Merge into relevant files
system/nix/ profiles/core/nixos/nix.nix Consolidate
system/nix/overlays.nix overlays/default.nix
system/network/ profiles/core/nixos/networking.nix
system/hardware/ Split: common → profiles/core/nixos/, laptop → profiles/hardware/
home/programs/cli.nix profiles/core/home/packages.nix Base packages
home/programs/git.nix profiles/core/home/git.nix
home/programs/gtk.nix profiles/home/desktop/gtk.nix
home/programs/nvim.nix profiles/home/development/nvim/ Split into files
home/programs/quickshell.nix profiles/home/desktop/quickshell/
home/programs/zen.nix Environment-specific apps files Work vs personal
home/programs/vesktop.nix profiles/environments/personal/user/apps.nix Personal only
modules/personalModule/hyprlandConfig/ profiles/home/desktop/hyprland/ Shared base
modules/personalModule/gaming.nix profiles/environments/personal/nixos/gaming.nix
hosts/aridhol/ laptop config profiles/hardware/laptop.nix Reusable
hosts/aridhol/home/extra.nix profiles/environments/work/user/ Work-specific
hosts/striking-distance/home/gaming.nix profiles/environments/personal/user/gaming.nix
hosts/striking-distance/audio.nix Keep at hosts/striking-distance/audio.nix Host-specific
modules/nixosModules/ modules/nixos/ Organize
modules/homeManagerModules/ modules/home/

File Organization Best Practices

Split Files When:

  • File exceeds ~200 lines
  • Logically distinct concerns (settings vs binds vs rules)
  • You want to override specific parts in different environments
  • Multiple people might edit different sections

Keep Together When:

  • Tightly coupled settings (less than ~100 lines)
  • Always imported as a unit
  • No need for selective overrides
  • Clear single purpose

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.nix each semester:

{ pkgs, ... }: {
  home.packages = with pkgs; [
    # Fall 2024: Data Science
    python312
    python312Packages.pandas
    python312Packages.numpy
    jupyter
    
    # Uncomment for Spring 2025: Systems Programming
    # gcc
    # gdb
    # valgrind
  ];
}

Switching Environments

If you ever want to test personal config on laptop or work config on desktop:

# In hosts/aridhol/default.nix
# Change:
# ../../profiles/environments/work/nixos
# To:
# ../../profiles/environments/personal/nixos

Then rebuild. Easy environment switching!

Secrets Management

Consider adding for VPN configs, API keys, etc:

secrets/
├── default.nix
└── work/
    └── vpn.nix

Use sops-nix or agenix for encrypted secrets.

Testing Strategy

# Build without switching
nixos-rebuild build --flake .#aridhol

# Build VM for testing
nixos-rebuild build-vm --flake .#aridhol

# Switch after testing
nixos-rebuild switch --flake .#aridhol

Adding a New Host

  1. Create hosts/new-host/{default.nix,hardware.nix,user.nix}
  2. Import appropriate environment profile
  3. Add host-specific overrides (hostname, monitors)
  4. Add to hosts/default.nix
  5. Build and test

Next Steps

  1. Review this proposal - Does it fit your needs?
  2. Backup current config - git commit before starting
  3. Create directory structure - Make all directories
  4. Migrate Phase 1 - Common configs
  5. Migrate Phase 2 - Shared building blocks
  6. Migrate Phase 3 - Environment profiles
  7. Migrate Phase 4 - Simplify host configs
  8. Test thoroughly - Build before switch
  9. Document - Add READMEs to directories explaining purpose
  10. Iterate - Refine organization as you use it

Additional Resources


This document is a living guide. Update it as your configuration evolves!

### 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 - Single user (kruziikrel13) across all hosts, but username configurable - Two environment profiles: **Work/University** and **Personal** - Configuration split into multiple files for organization - **Work profile:** Minimal, performance-optimized Hyprland (animations disabled), no gaming, varies per semester - **Personal profile:** Gaming, latest drivers, Grayjay, full desktop experience with all bells and whistles - **Laptop (aridhol):** Work/University environment - **Desktop (striking-distance):** Personal/Gaming environment --- ## Current Configuration Analysis Your current setup has: - Two hosts: `aridhol` (laptop) and `striking_distance` (desktop) - Home-manager integration - Custom modules in `modules/personalModule/` - Host-specific configs with some duplication - Common system config in `system/` - Common home config in `home/` **Current Pain Points:** - Unclear separation between common and host-specific configs - Home-manager tightly coupled throughout - Difficult to see what's shared vs unique per host/environment - Hyprland monitor settings scattered - No clear environment (work vs personal) separation --- ## Recommended Directory Structure ``` /etc/nixos/ ├── flake.nix # Main flake entry point ├── flake.lock │ ├── hosts/ # Host-specific configurations ONLY │ ├── default.nix # Host definitions (lib.nixosSystem) │ │ │ ├── aridhol/ # Work/University laptop │ │ ├── default.nix # Host config & profile imports │ │ ├── hardware.nix # Hardware-configuration.nix │ │ └── user.nix # User config & profile imports │ │ │ └── striking-distance/ # Personal gaming desktop │ ├── default.nix │ ├── hardware.nix │ ├── audio.nix # Host-specific audio setup │ └── user.nix │ ├── profiles/ # All reusable configuration │ │ │ ├── core/ # Common config for ALL hosts & environments │ │ ├── nixos/ # Common NixOS config │ │ │ ├── default.nix # Main common imports │ │ │ ├── boot.nix # Boot configuration │ │ │ ├── nix.nix # Nix daemon settings, flakes │ │ │ ├── networking.nix # Basic network config │ │ │ ├── security.nix # Security & hardening │ │ │ └── users.nix # User account definition │ │ │ │ │ └── home/ # Common home-manager config (base user) │ │ ├── default.nix │ │ ├── shell.nix # Bash/zsh config │ │ ├── git.nix │ │ ├── xdg.nix │ │ └── packages.nix # Essential CLI tools │ │ │ ├── hardware/ # Hardware-specific profiles │ │ ├── laptop.nix # TLP, thermald, battery │ │ ├── bluetooth.nix │ │ └── printing.nix │ │ │ ├── environments/ # Environment-specific profile bundles │ │ ├── work/ # Work/University environment │ │ │ ├── nixos/ │ │ │ │ ├── default.nix │ │ │ │ ├── packages.nix │ │ │ │ └── hardware.nix # Minimal graphics, drivers │ │ │ └── user/ │ │ │ ├── default.nix │ │ │ ├── hyprland.nix # Performance-optimized │ │ │ ├── development.nix │ │ │ ├── apps.nix │ │ │ └── semester.nix # Update per semester │ │ │ │ │ └── personal/ # Personal/Gaming environment │ │ ├── nixos/ │ │ │ ├── default.nix │ │ │ ├── gaming.nix # Gaming packages, drivers │ │ │ ├── graphics.nix # Latest AMD drivers │ │ │ └── packages.nix │ │ └── user/ │ │ ├── default.nix │ │ ├── hyprland.nix # Full animations & effects │ │ ├── gaming.nix # Steam, Lutris, etc. │ │ ├── media.nix # Grayjay, media apps │ │ └── apps.nix # Desktop apps │ │ │ ├── nixos/ # Shared NixOS building blocks │ │ ├── desktop/ │ │ │ ├── hyprland/ │ │ │ │ ├── default.nix │ │ │ │ ├── base.nix │ │ │ │ └── portals.nix │ │ │ └── audio.nix │ │ │ │ │ └── services/ │ │ ├── openssh.nix │ │ └── docker.nix │ │ │ └── home/ # Shared home-manager building blocks │ ├── development/ │ │ ├── default.nix │ │ ├── nvim/ │ │ │ ├── default.nix │ │ │ ├── plugins.nix │ │ │ └── config.nix │ │ └── tools.nix # Dev tools, LSPs │ │ │ └── desktop/ │ ├── hyprland/ │ │ ├── default.nix │ │ ├── settings/ │ │ │ ├── default.nix │ │ │ ├── general.nix │ │ │ ├── decoration.nix │ │ │ ├── animations.nix │ │ │ └── input.nix │ │ ├── binds.nix │ │ ├── rules.nix │ │ └── workspaces.nix │ │ │ ├── gtk.nix │ └── quickshell/ │ ├── default.nix │ └── config/ │ ├── modules/ # Custom NixOS/HM modules │ ├── nixos/ │ │ ├── default.nix │ │ └── ... │ └── home/ │ ├── default.nix │ └── quickshell.nix │ ├── packages/ # Custom packages │ ├── default.nix │ └── bibata-hyprcursor/ │ ├── lib/ # Helper functions │ └── default.nix │ └── overlays/ # Nixpkgs overlays └── default.nix ``` --- ## Key Design Principles ### 1. **Separation of Concerns** - `hosts/` = host-specific config only (hostname, monitors, hardware quirks) - `profiles/` = reusable, composable configuration chunks - `modules/` = custom module definitions ### 2. **Common vs Specific** - `profiles/core/` = Config shared by ALL hosts and environments - `profiles/environments/{work,personal}/` = Environment-specific bundles - `hosts/` = ONLY truly host-specific config (hostname, monitors, hardware quirks) - Hosts import: core → environment → host-specific overrides ### 3. **Home Manager → hjem Migration Path** - Keep user configs in `profiles/home/` abstracted from HM-specific syntax where possible - When switching to hjem, only modify `profiles/core/home/` and environment wrappers - Shared building blocks in `profiles/home/` remain mostly unchanged ### 4. **Composability** - Profiles are small, focused modules organized by concern - Environment bundles compose shared profiles with environment-specific config - Hosts select one environment bundle + host-specific overrides - Easy to add new hosts or switch environments ### 5. **File Organization** - Split large configurations into multiple files - Group related settings (hyprland settings split into files per category) - Use `default.nix` to import and expose sibling files - Keep individual files focused on one concern --- ## Example Implementation ### Host Configuration (Work Laptop - aridhol) **File:** `hosts/aridhol/default.nix` ```nix { pkgs, ... }: { imports = [ ../../profiles/core/nixos # Common config across all hosts ./hardware.nix # Work environment (NixOS side) ../../profiles/environments/work/nixos # Laptop-specific hardware profile ../../profiles/hardware/laptop.nix ]; networking.hostName = "aridhol"; # Host-specific: Latest kernel for laptop boot.kernelPackages = pkgs.linuxPackages_latest; # Host-specific monitor config (for Hyprland) programs.hyprland.monitors = [ "desc:Chimei Innolux Corporation 0x1553,1920x1080@60.0,0x0,0.9999999999999997,bitdepth,10" ", preferred, auto, 1, mirror, eDP-1" ]; } ``` **File:** `hosts/aridhol/user.nix` (home-manager wrapper) ```nix { ... }: { imports = [ # Work environment (user side) ../../profiles/environments/work/user ]; # Host-specific monitor override wayland.windowManager.hyprland.settings.monitor = [ "eDP-1,1920x1080@60,0x0,0.9999999999999997" ]; } ``` --- ### Host Configuration (Gaming Desktop - striking-distance) **File:** `hosts/striking-distance/default.nix` ```nix { ... }: { imports = [ ../../profiles/core/nixos # Common config across all hosts ./hardware.nix ./audio.nix # Host-specific custom audio setup # Personal/gaming environment (NixOS side) ../../profiles/environments/personal/nixos ]; networking.hostName = "striking-distance"; # Host-specific monitor config programs.hyprland.monitors = [ "DP-1,2560x1440@165,0x0,1" "HDMI-A-1,1920x1080@60,2560x0,1" ]; } ``` **File:** `hosts/striking-distance/user.nix` ```nix { ... }: { imports = [ # Personal/gaming environment (user side) ../../profiles/environments/personal/user ]; # Host-specific monitor config wayland.windowManager.hyprland.settings.monitor = [ "DP-1,2560x1440@165,0x0,1" "HDMI-A-1,1920x1080@60,2560x0,1" ]; # Host-specific gaming overrides if needed programs.steam.gamescopeSession.enable = true; } ``` --- ### Core Configuration (Shared Across All Hosts) **File:** `profiles/core/nixos/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./.; } ``` **File:** `profiles/core/nixos/boot.nix` ```nix { ... }: { boot = { loader.systemd-boot.enable = true; loader.efi.canTouchEfiVariables = true; tmp.cleanOnBoot = true; }; } ``` **File:** `profiles/core/nixos/nix.nix` ```nix { ... }: { nix.settings = { experimental-features = [ "nix-command" "flakes" ]; auto-optimise-store = true; warn-dirty = false; }; nixpkgs.config.allowUnfree = true; } ``` **File:** `profiles/core/nixos/users.nix` ```nix { username, pkgs, ... }: { users.users.${username} = { isNormalUser = true; extraGroups = [ "wheel" "networkmanager" "video" "audio" ]; shell = pkgs.bash; }; # Auto-login services.getty = { autologinUser = username; autologinOnce = true; }; } ``` **File:** `profiles/core/nixos/networking.nix` ```nix { ... }: { networking.networkmanager.enable = true; } ``` **File:** `profiles/core/nixos/security.nix` ```nix { ... }: { security.rtkit.enable = true; # Add your existing security settings here } ``` **File:** `profiles/core/home/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./.; programs.home-manager.enable = true; # or hjem in future xdg.enable = true; home.stateVersion = "24.11"; } ``` **File:** `profiles/core/home/packages.nix` ```nix { pkgs, ... }: { # Essential CLI tools for ALL environments home.packages = with pkgs; [ htop tree fzf ripgrep fd bat eza curl wget ]; } ``` **File:** `profiles/core/home/shell.nix` ```nix { ... }: { programs.bash = { enable = true; # Your bash config }; } ``` **File:** `profiles/core/home/git.nix` ```nix { ... }: { programs.git = { enable = true; userName = "kruziikrel13"; userEmail = "dev@michaelpetersen.io"; # Your git config }; } ``` **File:** `profiles/core/home/xdg.nix` ```nix { ... }: { xdg = { enable = true; userDirs = { enable = true; createDirectories = true; }; }; } ``` --- ### Environment Profiles - Work/University **File:** `profiles/environments/work/nixos/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./. ++ [ ../../../core/nixos # Core NixOS config ../../../nixos/desktop/hyprland # Shared Hyprland base ]; } ``` **File:** `profiles/environments/work/nixos/packages.nix` ```nix { pkgs, ... }: { environment.systemPackages = with pkgs; [ # Work/University specific tools libreoffice zotero thunderbird # NO gaming packages ]; } ``` **File:** `profiles/environments/work/nixos/hardware.nix` ```nix { ... }: { # Minimal graphics - no gaming drivers hardware.graphics.enable = true; # No Steam, no gaming optimizations } ``` **File:** `profiles/environments/work/user/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./. ++ [ ../../../core/home # Core user config for ALL ../../../home/development # Nvim, git, dev tools ]; } ``` **File:** `profiles/environments/work/user/hyprland.nix` ```nix { ... }: { imports = [ ../../../home/desktop/hyprland ]; # Override: Performance-optimized for work/battery wayland.windowManager.hyprland.settings = { animations.enabled = false; # DISABLED for performance decoration = { blur.enabled = false; # DISABLED for battery drop_shadow = false; rounding = 5; # Minimal rounding }; misc = { vfr = true; # Variable refresh rate vrr = 0; }; }; } ``` **File:** `profiles/environments/work/user/apps.nix` ```nix { pkgs, ... }: { home.packages = with pkgs; [ # Minimal desktop apps for work firefox # or zen-browser vscode obsidian ]; } ``` **File:** `profiles/environments/work/user/development.nix` ```nix { pkgs, ... }: { # Work-specific dev tools if different from personal home.packages = with pkgs; [ # Add semester-specific tools here if needed ]; } ``` **File:** `profiles/environments/work/user/semester.nix` ```nix { pkgs, ... }: { # Update this file each semester based on courses home.packages = with pkgs; [ # Example Fall 2024: Data Science # python312 # python312Packages.pandas # python312Packages.numpy # jupyter # Example Spring 2025: Systems Programming # gcc # gdb # valgrind # Current semester tools: # Add here... ]; } ``` --- ### Environment Profiles - Personal/Gaming **File:** `profiles/environments/personal/nixos/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./. ++ [ ../../../core/nixos # Core NixOS config ../../../nixos/desktop/hyprland # Shared Hyprland base ]; } ``` **File:** `profiles/environments/personal/nixos/gaming.nix` ```nix { pkgs, ... }: { programs = { steam = { enable = true; remotePlay.openFirewall = true; dedicatedServer.openFirewall = true; }; gamemode.enable = true; }; environment.systemPackages = with pkgs; [ lutris heroic protonup-qt mangohud goverlay ]; # Gaming optimizations boot.kernel.sysctl = { "vm.max_map_count" = 2147483642; }; } ``` **File:** `profiles/environments/personal/nixos/graphics.nix` ```nix { pkgs, ... }: { # Latest AMD drivers for gaming hardware.graphics = { enable = true; enable32Bit = true; # For 32-bit games }; # Use latest kernel for gaming performance boot.kernelPackages = pkgs.linuxPackages_latest; } ``` **File:** `profiles/environments/personal/nixos/packages.nix` ```nix { pkgs, ... }: { environment.systemPackages = with pkgs; [ # Personal desktop packages discord spotify ]; } ``` **File:** `profiles/environments/personal/user/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./. ++ [ ../../../core/home ../../../home/development ]; } ``` **File:** `profiles/environments/personal/user/hyprland.nix` ```nix { ... }: { imports = [ ../../../home/desktop/hyprland ]; # Override: Full bells and whistles for gaming desktop wayland.windowManager.hyprland.settings = { animations.enabled = true; # ENABLED decoration = { blur = { enabled = true; # ENABLED size = 8; passes = 3; new_optimizations = true; }; drop_shadow = true; shadow_range = 4; shadow_render_power = 3; rounding = 10; }; misc = { vrr = 1; # Variable refresh rate for gaming }; }; } ``` **File:** `profiles/environments/personal/user/gaming.nix` ```nix { pkgs, ... }: { home.packages = with pkgs; [ # Gaming-related user packages discord # Steam managed at system level mangohud goverlay ]; } ``` **File:** `profiles/environments/personal/user/media.nix` ```nix { pkgs, ... }: { home.packages = with pkgs; [ # grayjay # Install however you currently do vlc spotify mpv ]; } ``` **File:** `profiles/environments/personal/user/apps.nix` ```nix { pkgs, ... }: { home.packages = with pkgs; [ # Personal desktop applications # (Different from work apps) gimp inkscape obs-studio ]; } ``` --- ### Shared Home-Manager Building Blocks **File:** `profiles/home/development/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./.; } ``` **File:** `profiles/home/development/nvim/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./.; programs.neovim.enable = true; } ``` **File:** `profiles/home/development/tools.nix` ```nix { pkgs, ... }: { home.packages = with pkgs; [ # Dev tools common to all environments lazygit gh ]; } ``` --- **File:** `profiles/home/desktop/hyprland/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./settings ++ [ ./binds.nix ./rules.nix ./workspaces.nix ]; wayland.windowManager.hyprland.enable = true; # Base packages home.packages = with pkgs; [ kitty rofi-wayland waybar ]; } ``` **File:** `profiles/home/desktop/hyprland/settings/default.nix` ```nix { pathLib, ... }: { imports = pathLib.scanPaths ./.; } ``` **File:** `profiles/home/desktop/hyprland/settings/general.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.general = { gaps_in = 5; gaps_out = 10; border_size = 2; # Overridable by environment profiles }; } ``` **File:** `profiles/home/desktop/hyprland/settings/decoration.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.decoration = { # Defaults - overridden by environment profiles rounding = 10; }; } ``` **File:** `profiles/home/desktop/hyprland/settings/animations.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.animations = { enabled = true; # Default, overridden in work profile to false bezier = [ "myBezier, 0.05, 0.9, 0.1, 1.05" ]; animation = [ "windows, 1, 7, myBezier" "windowsOut, 1, 7, default, popin 80%" "border, 1, 10, default" "fade, 1, 7, default" "workspaces, 1, 6, default" ]; }; } ``` **File:** `profiles/home/desktop/hyprland/settings/input.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.input = { kb_layout = "us"; follow_mouse = 1; sensitivity = 0; }; } ``` **File:** `profiles/home/desktop/hyprland/binds.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.bind = [ "SUPER, Return, exec, kitty" "SUPER, Q, killactive" "SUPER, M, exit" "SUPER, E, exec, dolphin" "SUPER, V, togglefloating" "SUPER, R, exec, rofi -show drun" # Your existing binds ]; } ``` **File:** `profiles/home/desktop/hyprland/rules.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.windowrulev2 = [ # Your existing window rules ]; } ``` **File:** `profiles/home/desktop/hyprland/workspaces.nix` ```nix { ... }: { wayland.windowManager.hyprland.settings.workspace = [ # Your existing workspace config ]; } ``` --- ## Migration Strategy ### Phase 1: Create Structure & Core Config 1. **Backup everything:** `git commit -am "backup before restructure"` 2. Create new directory structure (all directories) 3. Move `system/core/*` → split into `profiles/core/nixos/{boot,nix,users,security}.nix` 4. Move `system/network/*` → `profiles/core/nixos/networking.nix` 5. Move basic `home/` configs → `profiles/core/home/` 6. Update `hosts/default.nix` imports 7. Test build: `nixos-rebuild build --flake .#aridhol` ### Phase 2: Create Shared Building Blocks 1. Move `home/programs/git.nix` → `profiles/core/home/git.nix` 2. Move `home/programs/nvim.nix` → `profiles/home/development/nvim/` 3. Move `modules/personalModule/hyprlandConfig/` → `profiles/home/desktop/hyprland/` 4. Split large hyprland config into settings files 5. Create `profiles/hardware/laptop.nix` from aridhol's laptop-specific config 6. Test imports work correctly ### Phase 3: Create Environment Profiles 1. Create `profiles/environments/work/{nixos,user}/` directories 2. Create `profiles/environments/personal/{nixos,user}/` directories 3. Populate work environment with aridhol-specific configs 4. Populate personal environment with striking-distance-specific configs 5. Configure work profile: animations disabled, minimal packages 6. Configure personal profile: gaming, latest drivers, all effects 7. Use shared building blocks + environment-specific overrides ### Phase 4: Update Host Configs 1. Simplify `hosts/aridhol/default.nix` to import work environment 2. Simplify `hosts/striking-distance/default.nix` to import personal environment 3. Keep only truly host-specific overrides (monitors, hostname, hardware quirks) 4. Keep `hosts/striking-distance/audio.nix` as-is 5. Test both hosts: `nixos-rebuild build --flake .#{aridhol,striking-distance}` 6. Test switch on one host first, then the other ### Phase 5: Abstract for hjem (Future - Optional) 1. Remove HM-specific syntax from shared building blocks where possible 2. Keep HM wrappers in environment profiles 3. When ready to migrate, replace HM → hjem in: - Environment profile user configs - `hosts/*/user.nix` files 4. Shared building blocks remain mostly unchanged --- ## Benefits of This Structure ### ✅ Clear Environment Separation - Obvious what's work vs personal - Easy to switch laptop to personal or desktop to work if needed - Clear what changes per semester vs what's permanent ### ✅ Clear Organization - Obvious what's common vs host-specific - Easy to find configurations - Scalable to many hosts ### ✅ Reduced Duplication - Common code in one place - DRY principle enforced - Easier maintenance ### ✅ Composable - Mix and match profiles - Easy to add new hosts - Reusable components - Can test work environment on desktop or vice versa ### ✅ Migration-Friendly - Abstracted user configs - Clear separation layers - Minimal changes needed for hjem ### ✅ Testable - Can test profiles independently - Easy to experiment with new configs - Safe to iterate - Can build VMs with different environment configs --- ## Mapping Your Current Structure | Current | New Location | Notes | |---------|-------------|-------| | `system/core/boot.nix` | `profiles/core/nixos/boot.nix` | Split by concern | | `system/core/users.nix` | `profiles/core/nixos/users.nix` | | | `system/core/security.nix` | `profiles/core/nixos/security.nix` | | | `system/core/safe.nix` | `profiles/core/nixos/` | Merge into relevant files | | `system/nix/` | `profiles/core/nixos/nix.nix` | Consolidate | | `system/nix/overlays.nix` | `overlays/default.nix` | | | `system/network/` | `profiles/core/nixos/networking.nix` | | | `system/hardware/` | Split: common → `profiles/core/nixos/`, laptop → `profiles/hardware/` | | | `home/programs/cli.nix` | `profiles/core/home/packages.nix` | Base packages | | `home/programs/git.nix` | `profiles/core/home/git.nix` | | | `home/programs/gtk.nix` | `profiles/home/desktop/gtk.nix` | | | `home/programs/nvim.nix` | `profiles/home/development/nvim/` | Split into files | | `home/programs/quickshell.nix` | `profiles/home/desktop/quickshell/` | | | `home/programs/zen.nix` | Environment-specific apps files | Work vs personal | | `home/programs/vesktop.nix` | `profiles/environments/personal/user/apps.nix` | Personal only | | `modules/personalModule/hyprlandConfig/` | `profiles/home/desktop/hyprland/` | Shared base | | `modules/personalModule/gaming.nix` | `profiles/environments/personal/nixos/gaming.nix` | | | `hosts/aridhol/` laptop config | `profiles/hardware/laptop.nix` | Reusable | | `hosts/aridhol/home/extra.nix` | `profiles/environments/work/user/` | Work-specific | | `hosts/striking-distance/home/gaming.nix` | `profiles/environments/personal/user/gaming.nix` | | | `hosts/striking-distance/audio.nix` | Keep at `hosts/striking-distance/audio.nix` | Host-specific | | `modules/nixosModules/` | `modules/nixos/` | Organize | | `modules/homeManagerModules/` | `modules/home/` | | --- ## File Organization Best Practices ### Split Files When: - File exceeds ~200 lines - Logically distinct concerns (settings vs binds vs rules) - You want to override specific parts in different environments - Multiple people might edit different sections ### Keep Together When: - Tightly coupled settings (less than ~100 lines) - Always imported as a unit - No need for selective overrides - Clear single purpose ### 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.nix` each semester: ```nix { pkgs, ... }: { home.packages = with pkgs; [ # Fall 2024: Data Science python312 python312Packages.pandas python312Packages.numpy jupyter # Uncomment for Spring 2025: Systems Programming # gcc # gdb # valgrind ]; } ``` ### Switching Environments If you ever want to test personal config on laptop or work config on desktop: ```nix # In hosts/aridhol/default.nix # Change: # ../../profiles/environments/work/nixos # To: # ../../profiles/environments/personal/nixos ``` Then rebuild. Easy environment switching! ### Secrets Management Consider adding for VPN configs, API keys, etc: ``` secrets/ ├── default.nix └── work/ └── vpn.nix ``` Use `sops-nix` or `agenix` for encrypted secrets. ### Testing Strategy ```bash # Build without switching nixos-rebuild build --flake .#aridhol # Build VM for testing nixos-rebuild build-vm --flake .#aridhol # Switch after testing nixos-rebuild switch --flake .#aridhol ``` ### Adding a New Host 1. Create `hosts/new-host/{default.nix,hardware.nix,user.nix}` 2. Import appropriate environment profile 3. Add host-specific overrides (hostname, monitors) 4. Add to `hosts/default.nix` 5. Build and test --- ## Next Steps 1. ✅ **Review this proposal** - Does it fit your needs? 2. **Backup current config** - `git commit` before starting 3. **Create directory structure** - Make all directories 4. **Migrate Phase 1** - Common configs 5. **Migrate Phase 2** - Shared building blocks 6. **Migrate Phase 3** - Environment profiles 7. **Migrate Phase 4** - Simplify host configs 8. **Test thoroughly** - Build before switch 9. **Document** - Add READMEs to directories explaining purpose 10. **Iterate** - Refine organization as you use it --- ## Additional Resources - [NixOS Module System](https://nixos.wiki/wiki/NixOS_modules) - [Nix Flakes](https://nixos.wiki/wiki/Flakes) - [Home Manager Manual](https://nix-community.github.io/home-manager/) - [hjem Documentation](https://github.com/feel-co/hjem) - [NixOS Options Search](https://search.nixos.org/options) --- *This document is a living guide. Update it as your configuration evolves!*
kruziikrel13 added this to the (deleted) project 2026-05-26 16:26:07 +10:00
kruziikrel13 added this to the v0.2.0 milestone 2026-06-01 16:00:17 +10:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kruziikrel13/NixOS#84
No description provided.