Creating a NixOS live CD: Difference between revisions

Unabomberlive (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit
Makefu (talk | contribs)
export iso as package output, build with path:$PWD instead of git init
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<translate>
<translate>
== Motivation ==
== Motivation == <!--T:19-->
</translate>
 
<translate>
<!--T:33-->
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:
<!--T:34-->
* Ensures authenticity.
* Ensures authenticity.
<!--T:35-->
* No need for internet access.
* No need for internet access.
<!--T:36-->
* 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.
</translate>
 
<translate>
== Building == <!--T:20-->
== Building ==
 
</translate>
<!--T:37-->
<translate>
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 28: Line 34:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--T:21-->
Build the image via:
Build the image via:
</translate>
</translate>
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 34: Line 43:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--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 41: Line 53:
   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 56: Line 69:
</nowiki>}}
</nowiki>}}
<translate>
<translate>
<!--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">
# git init
 
# git add flake.nix
# nix build path:$PWD
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--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 71: Line 89:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
=== Testing the image === <!--T:7-->
=== Testing the image === <!--T:7-->
</translate>
 
<translate>
<!--T:38-->
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 84: Line 104:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
<!--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 91: Line 114:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
===SSH===
 
</translate>
===SSH=== <!--T:26-->
<translate>
 
<!--T:39-->
In your <tt>iso.nix</tt>:
In your <tt>iso.nix</tt>:
</translate>
</translate>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 108: Line 133:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
===Static IP Address=== <!--T:11-->
===Static IP Address=== <!--T:11-->
</translate>
 
<translate>
<!--T:40-->
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="1">
{
{
   ...
   ...
   networking = {
   networking = {
     usePredictableInterfaceNames = false;
     usePredictableInterfaceNames = false;
     interfaces.eth0.ip4 = [{
     interfaces.eth0.ipv4.addresses = [{
       address = "64.137.201.46";
       address = "64.137.201.46";
       prefixLength = 24;
       prefixLength = 24;
Line 129: Line 156:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
=== Building faster ===
 
</translate>
=== Building faster === <!--T:27-->
<translate>
 
<!--T:41-->
The build process is slow because of compression.
The build process is slow because of compression.


<!--T:28-->
Here are some timings for <code>nix-build</code>:
Here are some timings for <code>nix-build</code>:
</translate>
 
<translate>
<!--T:29-->
{| class="wikitable" style="margin:auto"
{| class="wikitable" style="margin:auto"
|+ Compression results
|+ Compression results
Line 150: Line 179:
| <code>xz -Xdict-size 100%</code> (default) || 450s || 43%
| <code>xz -Xdict-size 100%</code> (default) || 450s || 43%
|}
|}
</translate>
 
<translate>
<!--T:30-->
See also: [https://gist.github.com/baryluk/70a99b5f26df4671378dd05afef97fce mksquashfs benchmarks]
See also: [https://gist.github.com/baryluk/70a99b5f26df4671378dd05afef97fce mksquashfs benchmarks]


<!--T:31-->
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 163: Line 194:
</syntaxhighlight>
</syntaxhighlight>
<translate>
<translate>
==See also==
 
</translate>
==See also== <!--T:32-->
<translate>
 
<!--T:42-->
* [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>
<translate>
 
[[Category:NixOS]]
[[Category:NixOS]]
[[Category:Deployment]]
[[Category:Deployment]]
[[Category:Cookbook]]
[[Category:Cookbook]]
</translate>