Back to list
khaneliman

nix-lib-usage

by khaneliman

Nix configuration for my systems supporting macOS, NixOS, and WSL.

303🍴 14📅 Jan 23, 2026

SKILL.md


name: nix-lib-usage description: "Nix library usage patterns: with, inherit, and inline lib. prefixes. Use when deciding how to access lib functions, avoiding the with lib anti-pattern, or writing analysis-friendly Nix code."

Library Usage Patterns

The Rule

Avoid high-scope with lib; - it breaks static analysis for all nested code

Decision Guide

SituationPattern
1-2 lib functionsInline lib. prefix
3+ lib functionsinherit (lib) ... in let
Single-line listwith pkgs; [...] is OK
Module-level scopeNEVER use with lib;

Inline Prefix (1-2 uses)

config = lib.mkIf cfg.enable {
  setting = lib.mkDefault "value";
};

Inherit Pattern (3+ uses)

let
  inherit (lib) mkIf mkEnableOption mkOption types;
  cfg = config.namespace.module;
in
{
  # Now use directly: mkIf, types.str, etc.
}

Acceptable Single-Line With

# OK - tightly scoped to single expression
environment.systemPackages = with pkgs; [ git vim curl ];

# OK - limited scope
meta = with lib; { license = licenses.mit; };

Anti-Pattern: High-Scope With

# WRONG - breaks analysis for everything inside
{ config, lib, pkgs, ... }:
with lib;
{
  # IDE can't help, shadowing bugs, unclear origins
}

Why This Matters

  • Static analyzers (nixd, nil) lose visibility
  • IDE auto-completion breaks
  • Shadowing bugs become possible
  • Code origins unclear in nested expressions

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