Skip to content
Back to skills

Nix Run Maintenance

ASecurity

Package recurring multi-step maintenance, such as regenerating lockfiles or hashes for dependencies, as a single `nix run .#<name>` script in the flake instead of a written procedure. The script stops after generating and formatting files and never commits. Use when proposing a multi-step maintenance procedure or adding a maintenance script to a Nix flake.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentsshellgit

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add ncaq/konoka --skill nix-run-maintenance --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Nix Run Maintenance?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Nix Run Maintenance
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ncaq-nix-run-maintenance/badge)](https://www.skillsdirectory.com/skills/ncaq-nix-run-maintenance)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nix-run-maintenance
description: Package recurring multi-step maintenance, such as regenerating lockfiles or hashes for dependencies, as a single `nix run .#<name>` script in the flake instead of a written procedure. The script stops after generating and formatting files and never commits. Use when proposing a multi-step maintenance procedure or adding a maintenance script to a Nix flake.
user-invocable: false
---

# 定型のメンテナンスは`nix run`の1回で済ませる

繰り返し行う定型のメンテナンスは、手順書ではなく、
1回の`nix run`で完結するスクリプトにしてください。
複数のコマンドを順に実行する手順を提案しそうになったら、それをスクリプトにします。
手順書だと、実行の漏れや手順の間違いが起きるためです。

依存のロックファイルやhashの再生成のように、
複数のコマンドとファイルの書き換えを組み合わせる作業が対象です。
既に1つのコマンドで済むものは、そのままそのコマンドを使います。
例えば`flake.lock`の更新は`nix flake update`で済むので、スクリプトにはしません。

## スクリプトの作り方

flakeの`packages`に`writeShellApplication`で載せて、
`nix run .#<name>`で実行できるようにします。
`writeShellApplication`については[nix-tasuke:writer-function](../writer-function/SKILL.md)を参照してください。

```nix
# コミットはしない: 生成物の差分を確かめてから、人がコミットの単位を決めるため。
update-deps = pkgs.writeShellApplication {
  name = "update-deps";
  runtimeInputs = [ pkgs.git ];
  text = ''
    cd "$(git rev-parse --show-toplevel)"
    "$(nix build --no-link --print-out-paths .#my-package.fetch-deps)" deps.json
    nix fmt deps.json
  '';
};
```

- スクリプトの先頭でリポジトリのルートへ移動して、どこから実行しても同じように動くようにします。
  `self`や`./.`はストアにコピーされた読み取り専用のソースを指すので、
  書き換える対象には使いません。
- 使うコマンドは`runtimeInputs`に並べて、実行時の依存を明示します。
  `nix`は`nix run`で起動した環境のものを使うので並べません。
- ネットワークを使う処理も、固定出力のderivationにできるなら、
  サンドボックスの中で実行するderivationにします。
  出力のハッシュを前もって決められない処理や、作業ツリーを書き換える処理は、
  サンドボックスの中では実行できないので、`nix run`で起動するスクリプトにします。
- スクリプトの中で呼ぶ`nix build`などは、その時点の作業ツリーでflakeを評価し直します。
  前の段階で書き換えたファイルを後の段階に反映させたい時は、この順で呼びます。
  flakeはGitが追跡していないファイルを評価しないので、
  スクリプトが新しく作ったファイルを後の段階で使う時は、
  `git add --intent-to-add`で追跡させてから呼びます。

## 生成と整形までで終わる

スクリプトは、ファイルの生成と整形までを行って終わります。

- 生成したファイルは、最後に`nix fmt <files>`でリポジトリのフォーマットに揃えます。
- コミットはしません。
  生成物の差分を確かめてから、他の変更とまとめる単位を人が決めてコミットするためです。

コミットしない理由は、スクリプトの定義のそばにコメントで残します。

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.