Creating a NixOS live CD: Difference between revisions
Marked this version for translation Tags: Mobile edit Mobile web edit |
m Improvements for translations |
||
| Line 2: | Line 2: | ||
<!--T:19--> | <!--T:19--> | ||
== Motivation == | == Motivation == | ||
Creating a modified NixOS LiveCD out of an existing working NixOS installation has a number of benefits: | Creating a modified NixOS LiveCD out of an existing working NixOS installation has a number of benefits: | ||
* Ensures authenticity. | * Ensures authenticity. | ||
* No need for internet access. | * No need for internet access. | ||
* It is easy to add your own packages and configuration changes to the image. | * It is easy to add your own packages and configuration changes to the image. | ||
<!--T:20--> | <!--T:20--> | ||
== Building == | == Building == | ||
Building minimal NixOS installation CD with the <code>nix-build</code> command by creating this <code>iso.nix</code>-file. In this example with [[Neovim]] preinstalled. | Building minimal NixOS installation CD with the <code>nix-build</code> command by creating this <code>iso.nix</code>-file. In this example with [[Neovim]] preinstalled. | ||
</translate> | </translate> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 26: | Line 31: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:21--> | <!--T:21--> | ||
Build the image via: | Build the image via: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 33: | Line 40: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:22--> | <!--T:22--> | ||
Alternatively, use Nix [[Flakes]] to generate a ISO installation image, using the <code>nixos-24.05</code> branch as nixpkgs source: | Alternatively, use Nix [[Flakes]] to generate a ISO installation image, using the <code>nixos-24.05</code> branch as nixpkgs source: | ||
</translate> | </translate> | ||
{{file|flake.nix|nix|<nowiki> | {{file|flake.nix|nix|<nowiki> | ||
| Line 56: | Line 65: | ||
</nowiki>}} | </nowiki>}} | ||
<translate> | <translate> | ||
<!--T:23--> | <!--T:23--> | ||
The following commands will generate the iso-image: | The following commands will generate the iso-image: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
| Line 65: | Line 76: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:24--> | <!--T:24--> | ||
The resulting image can be found in <code>result</code>: | The resulting image can be found in <code>result</code>: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
| Line 73: | Line 86: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:7--> | <!--T:7--> | ||
=== Testing the image === | === Testing the image === | ||
To inspect the contents of the ISO image: | To inspect the contents of the ISO image: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
| Line 85: | Line 101: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:25--> | <!--T:25--> | ||
To boot the ISO image in an emulator: | To boot the ISO image in an emulator: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
| Line 93: | Line 111: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:26--> | <!--T:26--> | ||
===SSH=== | ===SSH=== | ||
In your <tt>iso.nix</tt>: | In your <tt>iso.nix</tt>: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 109: | Line 130: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:11--> | <!--T:11--> | ||
===Static IP Address=== | ===Static IP Address=== | ||
Static IP addresses can be set in the image itself. This can be useful for VPS installation. | Static IP addresses can be set in the image itself. This can be useful for VPS installation. | ||
</translate> | </translate> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 129: | Line 153: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:27--> | <!--T:27--> | ||
=== Building faster === | === Building faster === | ||
The build process is slow because of compression. | The build process is slow because of compression. | ||
<!--T:28--> | <!--T:28--> | ||
Here are some timings for <code>nix-build</code>: | Here are some timings for <code>nix-build</code>: | ||
<!--T:29--> | <!--T:29--> | ||
{| class="wikitable" style="margin:auto" | {| class="wikitable" style="margin:auto" | ||
| Line 151: | Line 176: | ||
| <code>xz -Xdict-size 100%</code> (default) || 450s || 43% | | <code>xz -Xdict-size 100%</code> (default) || 450s || 43% | ||
|} | |} | ||
<!--T:30--> | <!--T:30--> | ||
See also: [https://gist.github.com/baryluk/70a99b5f26df4671378dd05afef97fce mksquashfs benchmarks] | See also: [https://gist.github.com/baryluk/70a99b5f26df4671378dd05afef97fce mksquashfs benchmarks] | ||
| Line 159: | Line 183: | ||
If you don't care about file size, you can use a faster compression | If you don't care about file size, you can use a faster compression | ||
by adding this to your <code>iso.nix</code>: | by adding this to your <code>iso.nix</code>: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 166: | Line 191: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | <translate> | ||
<!--T:32--> | <!--T:32--> | ||
==See also== | ==See also== | ||
* [https://nixos.org/manual/nixos/stable/index.html#sec-building-image NixOS Manual: Building a NixOS (Live) ISO]. | * [https://nixos.org/manual/nixos/stable/index.html#sec-building-image NixOS Manual: Building a NixOS (Live) ISO]. | ||
</translate> | </translate> | ||
[[Category:NixOS]] | [[Category:NixOS]] | ||
[[Category:Deployment]] | [[Category:Deployment]] | ||
[[Category:Cookbook]] | [[Category:Cookbook]] | ||