Flakes/ja: Difference between revisions

Haruki7049 (talk | contribs)
Created page with "* また、Flakesは参照(Gitのrefsの事)とバージョンを固定することができ、それらをプログラムによって照会したり更新したりすることができます。"
Natsukium (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit
 
(27 intermediate revisions by 2 users not shown)
Line 7: Line 7:
Nix flakesはNixのプロジェクトに一定の構造を強制し、ロックファイルを用いて依存するプロジェクトのバージョンを指定することでより便利に再現可能なNix式を記述できるようにします。
Nix flakesはNixのプロジェクトに一定の構造を強制し、ロックファイルを用いて依存するプロジェクトのバージョンを指定することでより便利に再現可能なNix式を記述できるようにします。


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html#description Flake]とは<code>flake.nix</code>というのNixファイルをルートに持つファイルシステムツリーを指します。
* A [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html#description flake] refers to a file-system tree whose root directory contains the Nix file specification called <code>flake.nix</code>.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* <code>flake.nix</code>ファイルの内容は、Nix言語でパッケージとその依存関係を宣言するための統一された命名スキーマに従っています。
* The contents of <code>flake.nix</code> file follow a uniform naming schema for declaring packages and their dependencies in the Nix language.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Flakeは外部のソースを指定するために[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references URLのような構文]を提供しています。
Flakes introduce a [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references URL-like syntax] for specifying remote sources.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* 長いURL構文を簡易にするために[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html Flakeはレジストリを使用]して短い記号として登録できます。
* To simplify the long URL syntax with shorter names, [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html flakes uses a registry] of symbolic identifiers.
</div>


* また、Flakesは参照(Gitのrefsの事)とバージョンを固定することができ、それらをプログラムによって照会したり更新したりすることができます。
* また、Flakesは参照(Gitのrefsの事)とバージョンを固定することができ、それらをプログラムによって照会したり更新したりすることができます。


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html 実験的なコマンドラインインタフェース]はFlakeの参照を受け取りパッケージのビルド、実行やデプロイができます。
* An [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html experimental command-line interface] accepts flake references for expressions that build, run, and deploy packages.
</div>


<span id="Enable_flakes_temporarily"></span>
<span id="Enable_flakes_temporarily"></span>
Line 69: Line 59:
===基本的なFlakeの使用方法===
===基本的なFlakeの使用方法===


<div lang="en" dir="ltr" class="mw-content-ltr">
この時点でnixコマンドを実行する前に、以下の2つの警告に注意してください。1つは暗号化に関するもの、もう1つはgitに関するものです。
Before running any nix commands at this point, please note the two warnings below: one for encryption and the other for git.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Encryption_WARNING"></span>
====Encryption WARNING====
====暗号化に関する警告====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{Warning | flakeファイルの内容は世界的に読み取り可能なNix storeフォルダにコピーされるため、暗号化されていない機密情報はflakeファイルに置かないでください。代わりに[[Comparison of secret managing schemes|secret managing scheme]]を使うべきです。}}
{{Warning | Since contents of flake files are copied to the world-readable Nix store folder, do not put any unencrypted secrets in flake files. You should instead use a [[Comparison of secret managing schemes|secret managing scheme]].}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Git_WARNING"></span>
====Git WARNING====
====Gitに関する警告====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Gitリポジトリ内のフレークでは、作業ツリー内のファイルのみがNix storeにコピーされます。
For flakes in git repos, only files in the working tree will be copied to the store.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
したがって、flakeに<code>git</code>を使用する場合は、プロジェクトファイルを作成した後、必ず<code>git add</code>を実行してください。
Therefore, if you use <code>git</code> for your flake, ensure to <code>git add</code> any project files after you first create them.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 97: Line 77:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Generate_flake.nix_file"></span>
====Generate flake.nix file====
====flake.nixファイルを生成する====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
基本的な方法でFlakeを使い始めるにはプロジェクトディレクトリでflakeコマンドを実行します:
To start the basic usage of flake, run the flake command in the project directory:
</div>


<syntaxHighlight lang=text>
<syntaxHighlight lang=text>
Line 109: Line 86:
</syntaxHighlight>
</syntaxHighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
== Flake schema ==
== Flake schema ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
flake.nixファイルはNixファイルですが、特殊な制限が設けられています(これについては後述します)。
The flake.nix file is a Nix file but that has special restrictions (more on that later).
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Flakeは4つのトップレベルアトリビュートを持ちます:
It has 4 top-level attributes:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* <code>description</code>はflakeを説明する文字列です。
* <code>description</code> is a string describing the flake.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* <code>inputs</code>はflakeの依存関係をアトリビュートセットとして記述したものです。下にスキーマを記述しています。
* <code>inputs</code> is an attribute set of all the dependencies of the flake. The schema is described below.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* <code>outputs</code>はすべてのrealizeされたinputを受け取り、下に記述されたスキーマのようにアトリビュートセットを返す関数です。
* <code>outputs</code> is a function of one argument that takes an attribute set of all the realized inputs, and outputs another attribute set whose schema is described below.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* <code>nixConfig</code>[https://nixos.org/manual/nix/stable/command-ref/conf-file.html nix.confに使用できる値]を反映しています。これを用いてこのflake特有の設定を反映させることができます。例としてバイナリキャッシュを設定できます。
* <code>nixConfig</code> is an attribute set of values which reflect the [https://nixos.org/manual/nix/stable/command-ref/conf-file.html values given to nix.conf]. This can extend the normal behavior of a user's nix experience by adding flake-specific configuration, such as a binary cache.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Input_schema"></span>
=== Input schema ===
=== Input スキーマ ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs Nixのflake inputsのマニュアル].
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual].
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references Nix flake referencesのマニュアル].
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual].
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
inputsアトリビュートはflakeの依存関係を定義します。例えば、システムflakeではシステムをビルドするためにnixpkgsに依存しています。
The inputs attribute defines the dependencies of the flake. For example, nixpkgs has to be defined as a dependency for a system flake in order for the system to build properly.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Nixpkgsは以下のコードで定義できます:
Nixpkgs can be defined using the following code:
</div>


<code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code>
<code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code>