Creating a NixOS live CD/ru: Difference between revisions

Unabomberlive (talk | contribs)
Created page with "Чтобы загрузиться в ISO-оьраз в эмуляторе:"
Unabomberlive (talk | contribs)
Replaced content with "== Мотивация =="
 
(44 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<span id="Motivation"></span>
== Мотивация ==
Создвние модифицированного образа NixOS из имеюшийся системы имеет множество преимуществ:
<div lang="en" dir="ltr" class="mw-content-ltr">
<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.
* Ensures authenticity.
* No need for internet access.
* It is easy to add your own packages and configuration changes to the image.
</div>
</div>
* Нет необходимости в интернет доступе.
* В собстенный образ легко добавить пакеты и изменять конфигурацию.
<span id="Building"></span>
== Сборка ==
<div lang="en" dir="ltr" class="mw-content-ltr">
<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.
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>  
</div>  
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ config, pkgs, ... }:
{ config, pkgs, ... }:
Line 23: Line 32:
}
}
</syntaxhighlight>
</syntaxhighlight>
Соберите образ через:
 
Сборка образа с помощью:
 
<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:
В качестве альтернативы используйте Nix [[Flakes]] для создания установочного образа ISO, используя ветку <code>nixos-24.05</code> в качестве источника nixpkgs:
</div>
 
{{file|flake.nix|nix|<nowiki>
{{file|flake.nix|nix|<nowiki>
{
{
Line 49: Line 60:
}
}
</nowiki>}}
</nowiki>}}
Следующие комманды сгенерируют iso-образ:
 
Следующие команды создадут ISO-образ:
 
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
# git init
# git init
Line 55: Line 68:
# 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>:
Готовый образ может быть найден а <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>
<span id="Testing_the_image"></span>
<span id="Testing_the_image"></span>
=== Тестирование образа ===
=== Тестирование образа ===
Чтобы просмотреть содержимое образа ISO, выполните следующие действия:
<div lang="en" dir="ltr" class="mw-content-ltr">
To inspect the contents of the ISO image:
</div>


Чтобы просмотреть содержимое ISO-образа:
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ mkdir mnt
$ mkdir mnt
Line 73: Line 91:
$ umount mnt
$ umount mnt
</syntaxhighlight>
</syntaxhighlight>
Чтобы загрузиться в ISO-оьраз в эмуляторе:
 
Чтобы загрузить образ ISO в эмуляторе:
 
<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 ===
 
<span id="SSH"></span>
===SSH===
В вашем <tt>iso.nix</tt>:
 
В вашем <tt>iso.nix</tt>
В вашем <tt>iso.nix</tt>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
Line 91: Line 116:
}
}
</syntaxhighlight>
</syntaxhighlight>
<span id="Static_IP_Address"></span>
<span id="Static_IP_Address"></span>
=== Статический IP-адрес ===
=== Статический IP-адрес ===
Статические IP-адреса можно задать в самом образе. Это может быть полезно при установке VPS.
Статический IP-адрес может бвть установлен в образе. Это может быть полехно для установки на VPS.


<div lang="en" dir="ltr" class="mw-content-ltr">
Static IP addresses can be set in the image itself. This can be useful for VPS installation.
</div>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
Line 112: Line 138:
}
}
</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">
<span id="Building_faster"></span>
Here are some timings for <code>nix-build</code>:
=== Ускорение сборки ===
</div>
Процесс сборки может быть медленным из-за сжатия.
 
Процессс сборки медленный из-за сжатия.
 
Вот некоторые значения времени для <code>nix-build</code>:
 
{| class="wikitable" style="margin:auto"
{| class="wikitable" style="margin:auto"
|+ Compression results
|+ Результаты сжатия
|-
|-
! squashfsCompression !! Time !! Size
! squashfsCompression !! Время !! Размер
|-
|-
| <code>lz4</code> || 100s || 59%
| <code>lz4</code> || 100s || 59%
Line 131: Line 158:
| <code>gzip</code> || 210s || 49%
| <code>gzip</code> || 210s || 49%
|-
|-
| <code>xz -Xdict-size 100%</code> (default) || 450s || 43%
| <code>xz -Xdict-size 100%</code> (По умолчанию) || 450s || 43%
|}
|}
<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">
Если вам не важен размер файла, вы можете использовать более быстрое сжатие, добавив этот параметр к вашему <code>iso.nix</code>:
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 146: Line 172:
}
}
</syntaxhighlight>
</syntaxhighlight>
<span id="See_also"></span>
==См. Также==
* [https://nixos.org/manual/nixos/stable/index.html#sec-building-image NixOS Manual: Сборка Live-образа NixOS].
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
==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].
</div>
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
[[Category:NixOS]]
[[Category:NixOS]]
[[Category:Deployment]]
[[Category:Deployment]]
[[Category:Cookbook]]
[[Category:Cookbook]]
</div>