Skip to content

Updated : Generating home config files using autoconfig

Hamzaukw edited this page Sep 9, 2025 · 1 revision

Home Configuration Autoconf Flow (Step-by-Step)

File Tree of All Components Used in Home Autoconf

  • scripts/autoconf-pipeline.py ← Entrypoint

  • ansible/

    • inventory/
      • hosts.ini ← Hosts and group mappings
      • group_vars/ ← Group-based home vars
        • group_home_cli.yml
        • group_home_roles.yml
        • group_home_services.yml
        • group_home_luxnix.yml
        • group_home_desktops.yml
      • host_vars/
        • home/
          • gc-08.yml ← Host-specific home vars
  • autoconf/

    • home_merged_vars/
      • gc-08.yml ← (auto-generated output)
  • homes/

    • x86_64-linux/
      • admin@gc-08/
        • default.nix ← (final output)
  • conf/

    • nix-templates/
      • homes/
        • x86_64-linux/
          • default.nix.j2
  • lx_administration/

    • autoconf/
      • main.py ← entry point that calls ETL + Nix pipelines
      • imports/
        • main.py ← defines home_etl()
        • utils.py ← defines load_home_host_vars()
      • nix/
        • home.py ← defines home_pipe()
        • home_template_renderer.py ← defines render_home_nix_template()
        • utils.py ← defines write_nix_file()
    • models/
      • merged_host_vars.py ← extended with home-specific keys and methods

Ansible Inventory (Input)

  • ansible/inventory/hosts.ini
  • ansible/inventory/group_vars/group_home_*.yml
  • ansible/inventory/host_vars/home/<host>.yml

Steps

Step 1: Merge Home Variables

  • Function: home_etl()
  • File: lx_administration/autoconf/imports/main.py
  • Uses: load_home_host_vars() from lx_administration/autoconf/imports/utils.py
  • Validates with: MergedHostVars from lx_administration/models/merged_host_vars.py
  • Outputs merged YAML to: autoconf/home_merged_vars/<host>.yml

Step 2: Load + Prepare Config

  • Function: home_pipe()
  • File: lx_administration/autoconf/nix/home.py
  • Loads YAML using MergedHostVars.load_home_from_file()
  • Extracts platform via get_host_platform()
  • Gets users from system_users (defaults to ["admin"])
  • Calls prepare_home_config() to create the final structured config

Step 3: Generate Final Config Structure

  • Function: prepare_home_config()
  • File: lx_administration/models/merged_host_vars.py
  • Merges:
  • group_home_cli + host_home_cli
  • group_home_roles + host_home_roles
  • group_home_services + host_home_services
  • group_home_luxnix + host_home_luxnix
  • group_home_desktops + host_home_desktops
  • Applies:
  • strip_common_prefix() to clean up keys like cli.
  • dotkey_to_nested_dict() to create nested attribute sets
  • Returns a final nested dictionary ready for rendering

Step 4: Render Nix Template

  • Function: render_home_nix_template()
  • File: lx_administration/autoconf/nix/home_template_renderer.py
  • Uses Jinja2 templating engine
  • Custom filter: to_nix() converts Python types to Nix literals
  • Template path: conf/nix-templates/homes/<platform>/default.nix.j2

Step 5: Write Final Output File

  • Function: write_nix_file()
  • File: lx_administration/autoconf/nix/utils.py
  • Writes the rendered file to: homes//@/default.nix

Final Output Directory Structure

  • homes/
    • x86_64-linux/
      • admin@gc-08/
        • default.nix

For Ansible Linting

YAML Cleanup for Ansible Inventory

To remove trailing whitespace and ensure each file ends with a newline, run the following command from the project root:

find ansible/inventory/host_vars/home/ -type f -name "*.yml" \
  -exec sed -i 's/[ \t]*$//' {} \; \
  -exec sh -c 'tail -c1 "$1" | read -r _ || echo >> "$1"' _ {} \;
  • Finds all .yml files under the home/ directory (excluding directories and symlinks).
  • Removes trailing spaces or tabs from the end of every line.
  • Checks if the file ends with a newline. If not, it appends one.

Clone this wiki locally