Creating a NixOS live CD/ru: Difference between revisions
Created page with "== Сборка == Сборка минимального установочного компакт-диска NixOS с помощью комманды <code>nix-build</code> создав этот <code>iso.nix</code>-файл. В данном примере с предустановленным Neovim." Tags: Mobile edit Mobile web edit |
Updating to match new version of source page |
||
| Line 1: | Line 1: | ||
== | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
== Motivation == | |||
* | Creating a modified NixOS LiveCD out of an existing working NixOS installation has a number of benefits: | ||
* | * Ensures authenticity. | ||
* | * No need for internet access. | ||
== | * It is easy to add your own packages and configuration changes to the image. | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
== 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. | |||
</div> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
| Line 19: | Line 23: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
Build the image via: | |||
</div> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix | nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
Alternatively, use Nix [[Flakes]] to generate a ISO installation image, using the <code>nixos-24.05</code> branch as nixpkgs source: | |||
</div> | |||
{{file|flake.nix|nix|<nowiki> | {{file|flake.nix|nix|<nowiki> | ||
{ | { | ||
| Line 43: | Line 51: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
The following commands will generate the iso-image: | |||
</div> | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# git init | # git init | ||
| Line 49: | Line 59: | ||
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage | # nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
The resulting image can be found in <code>result</code>: | |||
</div> | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
$ ls result/iso/ | $ ls result/iso/ | ||
nixos-24.05.20240721.63d37cc-x86_64-linux.iso | nixos-24.05.20240721.63d37cc-x86_64-linux.iso | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Тестирование образа === | === Тестирование образа === | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
$ mkdir mnt | $ mkdir mnt | ||
| Line 65: | Line 74: | ||
$ umount mnt | $ umount mnt | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
To boot the ISO image in an emulator: | |||
</div> | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
$ nix-shell -p qemu | $ nix-shell -p qemu | ||
$ qemu-system-x86_64 -enable-kvm -m 256 -cdrom result/iso/nixos-*.iso | $ qemu-system-x86_64 -enable-kvm -m 256 -cdrom result/iso/nixos-*.iso | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== SSH === | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
===SSH=== | |||
In your <tt>iso.nix</tt>: | |||
</div> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
| Line 83: | Line 96: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Статический IP-адрес === | === Статический IP-адрес === | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
| Line 102: | Line 112: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Building faster === | |||
The build process is slow because of compression. | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
Here are some timings for <code>nix-build</code>: | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
{| class="wikitable" style="margin:auto" | {| class="wikitable" style="margin:auto" | ||
|+ Compression results | |+ Compression results | ||
| Line 119: | Line 134: | ||
| <code>xz -Xdict-size 100%</code> (default) || 450s || 43% | | <code>xz -Xdict-size 100%</code> (default) || 450s || 43% | ||
|} | |} | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
See also: [https://gist.github.com/baryluk/70a99b5f26df4671378dd05afef97fce mksquashfs benchmarks] | See also: [https://gist.github.com/baryluk/70a99b5f26df4671378dd05afef97fce mksquashfs benchmarks] | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
If you don't care about file size, you can use a faster compression | |||
by adding this to your <code>iso.nix</code>: | |||
</div> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
| Line 129: | Line 148: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [https://nixos.org/manual/nixos/stable/index.html#sec-building-image | ==See also== | ||
* [https://nixos.org/manual/nixos/stable/index.html#sec-building-image NixOS Manual: Building a NixOS (Live) ISO]. | |||
</div> | |||
[[Category:NixOS]] | [[Category:NixOS]] | ||
[[Category:Deployment]] | [[Category:Deployment]] | ||
[[Category:Cookbook]] | [[Category:Cookbook]] | ||