Search

PythonReactSEOPDF
GitHub Skill

modules

Create and modify NixOS and Home-Manager modules

DaRacci☆ 17 Repository stars0 Repository forks

Installation

Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.

View source ↗Guides

Skill instructions

Modules

Module Structure

Standard module pattern:

{
  config,
  lib,
  pkgs,
  ...
}:
let
  inherit (lib) mkEnableOption mkOption mkIf types;
  cfg = config.services.myService;
in
{
  options.services.myService = {
    enable = mkEnableOption "my service";

    port = mkOption {
      type = types.port;
      default = 8080;
      description = "Port to listen on.";
    };
  };

  config = mkIf cfg.enable {
    # Configuration applied when enabled
  };
}

Creating a NixOS Module

  1. Create file at modules/nixos/<category>/<name>.nix

  2. Define options and config:

    {
      config,
      lib,
      pkgs,
      ...
    }:
    let
      cfg = config.services.myService;
    in
    {
      options.services.myService = {
        enable = lib.mkEnableOption "my service";
      };
    
      config = lib.mkIf cfg.enable {
        systemd.services.my-service = {
          wantedBy = [ "multi-user.target" ];
          serviceConfig.ExecStart = "${pkgs.myPackage}/bin/my-service";
        };
      };
    }
    
  3. Register in parent default.nix:

    # modules/nixos/services/default.nix
    _: {
      imports = [
        ./existing-service.nix
        ./my-service.nix  # Add this
      ];
    }
    
  4. Enable in host config:

    # hosts/server/myhost/default.nix
    { services.myService.enable = true; }
    

Creating a Home-Manager Module

  1. Create file at modules/home-manager/<category>/<name>.nix

  2. Define with optional osConfig access:

    {
      osConfig ? null,
      config,
      lib,
      pkgs,
      ...
    }:
    let
      cfg = config.purpose.myFeature;
    in
    {
      options.purpose.myFeature = {
        enable = lib.mkEnableOption "my feature";
      };
    
      config = lib.mkIf cfg.enable {
        home.packages = [ pkgs.myPackage ];
      };
    }
    
  3. Register in parent default.nix

  4. Enable in user config:

    # home/<user>/hm-config.nix
    { purpose.myFeature.enable = true; }
    

Common Namespaces

Namespace Module Type Purpose
services.<name> NixOS System services
hardware.<name> NixOS Hardware configuration
boot.<name> NixOS Boot configuration
host.<name> NixOS Host-specific options
server.<name> NixOS Server cluster options
purpose.<category> Home-Manager Use-case modules
custom.<name> Home-Manager Custom extensions
user.<name> Home-Manager User-specific options

Directory Index Patterns

Export as attribute set (top-level)
# modules/nixos/default.nix
{
  boot = import ./boot;
  hardware = import ./hardware;
  services = import ./services;
}
Import list (subdirectories)
# modules/nixos/services/default.nix
_: {
  imports = [
    ./service-a.nix
    ./service-b.nix
  ];
}

Modifying Existing Modules

  1. Find the module using project-structure skill
  2. Understand existing options with nix eval
  3. Add new options or extend config
  4. Test affected configurations
  5. Run nix fmt on changed files

Examples

Read the usage examples in the source repository.

View source ↗

Source history

Indexed on
2026-01-20
Index updated
2026-01-26
Branch
main

Index and sync dates describe this directory. View the source repository for code history.

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!