スキル一覧に戻る
knoopx

nix-flakes

by knoopx

pi.ai config

2🍴 0📅 2026年1月21日
GitHubで見るManusで実行

SKILL.md


name: nix-flakes description: Achieve reproducible builds, dependency management, and project isolation with Nix Flakes. Use when creating reproducible environments, managing dependencies, building packages, or initializing Nix projects.

Nix Flakes Skill

Flakes are the modern way to manage Nix projects, providing hermeticity and reproducibility through a flake.lock file.

Core Commands

Project Management

# Initialize a new flake in the current directory
nix flake init

# Update flake.lock (updates all inputs)
nix flake update

# Check flake for syntax and common errors
nix flake check

# Show flake outputs
nix flake show

Running and Building

Always prefix local flake paths with path: (e.g., path:.) to ensure Nix uses all files in the directory without requiring them to be staged in Git.

# Build the default package
nix build path:.

# Build a specific output
nix build path:.#packageName

# Run the default app
nix run path:.

# Run a specific app from a flake
nix run path:.#appName

# Run an app from a remote flake
nix run github:numtide/treefmt

Development Environments

In a headless environment, use nix develop with --command to run tasks within the environment.

# Run a command inside the devShell
nix develop path:. --command make build

# Check if current environment matches devShell
nix develop path:. --command env

Flake Structure (flake.nix)

A basic flake.nix pattern:

{
  description = "A basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      packages.${system}.default = pkgs.hello;

      devShells.${system}.default = pkgs.mkShell {
        buildInputs = [ pkgs.git pkgs.vim ];
      };
    };
}

Best Practices

  • Locking: Manage the flake.lock file to ensure reproducibility.
  • Purity: Flakes are "pure" by default. They cannot access files outside the flake directory unless they are tracked (e.g. in the git tree if using git).
  • Non-Interactive: When using nix develop, always use the --command flag to ensure scripts remain non-interactive.

Debugging Flakes

# Inspect inputs
nix flake metadata path:.

# Evaluate a specific output
nix eval path:.#packages.x86_64-linux.default.name
  • nix: Run applications without installation and create development environments using Nix.
  • nh: Manage NixOS and Home Manager operations with improved output using nh.
  • search-nix-packages: Search for packages available in the NixOS package repository when working with flakes.
  • search-nix-options: Find configuration options available in NixOS for flake configurations.
  • search-home-manager-options: Find configuration options for Home Manager in flake setups.

スコア

総合スコア

50/100

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

SKILL.md

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

+20
LICENSE

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

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

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

0/5
Issue管理

オープンIssueが50未満

+5
言語

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

+5
タグ

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

0/5

レビュー

💬

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