Creating a NixOS live CD: Difference between revisions

imported>Nilp0inter
Boot fail because default memory limit is to low. Also without KVM enable the boot is very very slow.
imported>Onny
Add nix flakes example
Line 1: Line 1:
==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.
Line 5: Line 5:
* 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.


==Building==
== Building ==


Create a file <tt>iso.nix</tt>:
Building minimal NixOS installation CD with the <code>nix-build</code> command. In this example with [[Neovim]] preinstalled.
<syntaxhighlight lang="nix">
 
# This module defines a small NixOS installation CD.  It does not
{{file|iso.nix|nix|<nowiki>
# contain any graphical stuff.
{ config, pkgs, ... }:
{ config, pkgs, ... }:
{
{
Line 20: Line 19:
     <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
     <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
   ];
   ];
  environment.systemPackages = [ pkgs.neovim ];
}
}
</syntaxhighlight>
</nowiki>}}


Build the image via:
Build the image via:
Line 27: Line 27:
<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>
Alternativley, use Nix [[Flakes]] to generate a ISO installation image, using the <code>23.11-beta</code> branch as nixpkgs source:
{{file|flake.nix|nix|<nowiki>
{
  description = "Bcachefs enabled installation media";
  inputs.nixos.url = "nixpkgs/23.11-beta";
  outputs = { self, nixos }: {
    nixosConfigurations = {
      exampleIso = nixos.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          "${nixos}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
          ({ pkgs, ... }: {
            environment.systemPackages = [ pkgs.neovim ];
          })
        ];
      };
    };
  };
}
</nowiki>}}
The following commands will generate the iso-image
<syntaxhighlight lang="console">
# git init
# git add flake.nix
# nix build .#nixosConfigurations.exampleIso.config.system.build.isoImage
</syntaxhighlight>
</syntaxhighlight>