スキル一覧に戻る
DaRacci

modules

by DaRacci

An idiots nix config

17🍴 0📅 2026年1月24日
GitHubで見るManusで実行

SKILL.md


name: modules description: Create and modify NixOS and Home-Manager modules

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

NamespaceModule TypePurpose
services.<name>NixOSSystem services
hardware.<name>NixOSHardware configuration
boot.<name>NixOSBoot configuration
host.<name>NixOSHost-specific options
server.<name>NixOSServer cluster options
purpose.<category>Home-ManagerUse-case modules
custom.<name>Home-ManagerCustom extensions
user.<name>Home-ManagerUser-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

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です