nix-lib-usage

Apply inline prefixes, inherit patterns, and scoped with patterns to Nix configurations.

340|18|Updated May 11, 2023
One-click install
npx skills add https://github.com/khaneliman/khanelinix --skill nix-lib-usage
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nix-lib-usage
Source: https://github.com/khaneliman/khanelinix/tree/main/modules/common/ai-tools/skills/lib-usage
Command: npx skills add https://github.com/khaneliman/khanelinix --skill nix-lib-usage

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Nix library usage patterns help developers avoid the with lib anti-pattern and encourage safer, more analyzable Nix code by promoting inline prefixes, inherit patterns, and scoped usage of lib.

Core Features & Use Cases

  • Inline Prefix guidance for small, low-risk lib usage.
  • Inherit Pattern guidance for larger, multi-function usage.
  • Scoped with patterns and practical refactor examples to improve static analysis and maintainability.

Quick Start

Apply these lib usage patterns when editing Nix configuration to ensure clearer, analyzable expressions.

Frequently Asked Questions about nix-lib-usage

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why is using with lib considered an anti-pattern in Nix configurations?

Using with lib in Nix creates an anti-pattern because it makes static analysis difficult and scopes ambiguous. Applying inline prefixes or inherit patterns ensures your Nix code remains analyzable and maintainable.

How do I refactor Nix expressions to avoid the with lib anti-pattern?

Refactor Nix expressions by replacing unscoped with lib statements with inline prefixes for small usage or the inherit pattern for multiple functions. This scoped approach improves static analysis and code clarity.

What is the best way to use nixpkgs lib functions safely in a large project?

The best way to use nixpkgs lib functions safely in large projects is the inherit pattern. Inheriting specific lib functions explicitly avoids dynamic scope pollution and keeps your Nix configuration maintainable.

When should I use inline prefixes versus the inherit pattern in Nix code?

Use inline prefixes in Nix code for small, low-risk lib usage to keep expressions clear. Switch to the inherit pattern when working with larger, multi-function lib usage to maintain static analyzability.

Does scoping with lib in NixOS modules improve static analysis compared to global usage?

Scoping with lib in NixOS modules improves static analysis compared to global usage. Scoped with patterns limit the dynamic binding surface, allowing static analysis tools to better trace and validate your Nix code.

Can I apply these Nix library patterns to existing nixpkgs configurations?

You can apply these Nix library patterns to existing nixpkgs configurations when editing. Applying inline prefixes, inherit patterns, and scoped with usage refactors your code for safer, more analyzable expressions across projects.