← Back to list

nix-module-template
by khaneliman
Nix configuration for my systems supporting macOS, NixOS, and WSL.
⭐ 303🍴 14📅 Jan 23, 2026
SKILL.md
name: nix-module-template description: "Basic Nix module structure template. Use when creating new NixOS, Home Manager, or nix-darwin modules from scratch."
Module Template
Standard Structure
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkIf mkEnableOption;
cfg = config.namespace.moduleName;
in
{
options.namespace.moduleName = {
enable = mkEnableOption "module description";
};
config = mkIf cfg.enable {
# Configuration here
};
}
NixOS System Module
# modules/nixos/services/my-service.nix
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkIf mkEnableOption;
cfg = config.services.myService;
in
{
options.services.myService = {
enable = mkEnableOption "My Service";
port = lib.mkOption {
type = lib.types.port;
default = 8080;
};
};
config = mkIf cfg.enable {
systemd.services.my-service = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "...";
};
};
}
Home Manager Module
# modules/home/programs/my-app.nix
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkIf mkEnableOption;
cfg = config.programs.myApp;
in
{
options.programs.myApp = {
enable = mkEnableOption "My App";
};
config = mkIf cfg.enable {
home.packages = [ pkgs.myApp ];
xdg.configFile."myapp/config".text = "...";
};
}
nix-darwin Module
# modules/darwin/system/defaults.nix
{
config,
lib,
...
}:
let
inherit (lib) mkIf mkEnableOption;
cfg = config.myproject.macosDefaults;
in
{
options.myproject.macosDefaults = {
enable = mkEnableOption "macOS defaults";
};
config = mkIf cfg.enable {
system.defaults.dock.autohide = true;
};
}
Key Points
- Always use
cfgpattern for accessing options - Wrap config in
mkIf cfg.enable - Use
mkEnableOptionfor enable flags - Keep modules self-contained
Score
Total Score
65/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
✓人気
GitHub Stars 100以上
+5
✓最近の活動
1ヶ月以内に更新
+10
✓フォーク
10回以上フォークされている
+5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
Reviews
💬
Reviews coming soon
