Creating a NixOS live CD/ru: Difference between revisions
Created page with "Создание Live CD образа NixOS" |
Updating to match new version of source page |
||
| (52 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"> | ||
* Ensures authenticity. | * Ensures authenticity. | ||
</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 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> | ||
В качестве альтернативы используйте Nix [[Flakes]] для создания установочного образа ISO, используя ветку <code>nixos-24.05</code> в качестве источника nixpkgs: | |||
{{file|flake.nix|nix|<nowiki> | {{file|flake.nix|nix|<nowiki> | ||
{ | { | ||
| Line 37: | Line 46: | ||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | ||
outputs = { self, nixpkgs }: { | outputs = { self, nixpkgs }: { | ||
packages.x86_64-linux.default = self.nixosConfigurations.exampleIso.config.system.build.isoImage; | |||
nixosConfigurations = { | nixosConfigurations = { | ||
exampleIso = nixpkgs.lib.nixosSystem { | exampleIso = nixpkgs.lib.nixosSystem { | ||
| Line 51: | Line 61: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
Следующие команды создадут ISO-образ: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# nix build path:$PWD | |||
# nix build | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Готовый образ может быть найден а <code>result</code>: | |||
<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> | ||
=== Тестирование образа === | |||
Чтобы просмотреть содержимое образа ISO, выполните следующие действия: | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To inspect the contents of the ISO image: | To inspect the contents of the ISO image: | ||
</div> | </div> | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
$ mkdir mnt | $ mkdir mnt | ||
| Line 80: | Line 91: | ||
$ umount mnt | $ umount mnt | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Чтобы загрузить образ 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> | ||
< | |||
<span id="SSH"></span> | |||
===SSH=== | ===SSH=== | ||
В вашем <tt>iso.nix</tt>: | |||
</ | |||
В вашем <tt>iso.nix</tt> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
| Line 102: | Line 116: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
< | <span id="Static_IP_Address"></span> | ||
=== Статический IP-адрес === | |||
Статические IP-адреса можно задать в самом образе. Это может быть полезно при установке VPS. | |||
<syntaxhighlight lang="nix"> | |||
Статический IP-адрес может бвть установлен в образе. Это может быть полехно для установки на VPS. | |||
<syntaxhighlight lang="nix" line="1"> | |||
{ | { | ||
... | ... | ||
networking = { | networking = { | ||
usePredictableInterfaceNames = false; | usePredictableInterfaceNames = false; | ||
interfaces.eth0. | interfaces.eth0.ipv4.addresses = [{ | ||
address = "64.137.201.46"; | address = "64.137.201.46"; | ||
prefixLength = 24; | prefixLength = 24; | ||
| Line 124: | Line 138: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
< | <span id="Building_faster"></span> | ||
=== Ускорение сборки === | |||
Процесс сборки может быть медленным из-за сжатия. | |||
Процессс сборки медленный из-за сжатия. | |||
Вот некоторые значения времени для <code>nix-build</code>: | |||
{| class="wikitable" style="margin:auto" | {| class="wikitable" style="margin:auto" | ||
|+ | |+ Результаты сжатия | ||
|- | |- | ||
! squashfsCompression !! | ! squashfsCompression !! Время !! Размер | ||
|- | |- | ||
| <code>lz4</code> || 100s || 59% | | <code>lz4</code> || 100s || 59% | ||
| Line 143: | Line 158: | ||
| <code>gzip</code> || 210s || 49% | | <code>gzip</code> || 210s || 49% | ||
|- | |- | ||
| <code>xz -Xdict-size 100%</code> ( | | <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> | ||
Если вам не важен размер файла, вы можете использовать более быстрое сжатие, добавив этот параметр к вашему <code>iso.nix</code>: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
| Line 158: | 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"> | ||
* [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> | ||
[[Category:NixOS]] | [[Category:NixOS]] | ||
[[Category:Deployment]] | [[Category:Deployment]] | ||
[[Category:Cookbook]] | [[Category:Cookbook]] | ||