← スキル一覧に戻る

modules
by DaRacci
An idiots nix config
⭐ 17🍴 0📅 2026年1月24日
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
-
Create file at
modules/nixos/<category>/<name>.nix -
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"; }; }; } -
Register in parent
default.nix:# modules/nixos/services/default.nix _: { imports = [ ./existing-service.nix ./my-service.nix # Add this ]; } -
Enable in host config:
# hosts/server/myhost/default.nix { services.myService.enable = true; }
Creating a Home-Manager Module
-
Create file at
modules/home-manager/<category>/<name>.nix -
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 ]; }; } -
Register in parent
default.nix -
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
- Find the module using project-structure skill
- Understand existing options with
nix eval - Add new options or extend config
- Test affected configurations
- Run
nix fmton 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
レビュー
💬
レビュー機能は近日公開予定です