Creating a NixOS live CD: Difference between revisions

From NixOS Wiki
imported>Mic92
imported>Mic92
Line 16: Line 16:
   imports = [
   imports = [
       <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
       <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
    # Provide an initial copy of the NixOS channel so that the user
    # doesn't need to run "nix-channel --update" first.
       <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
       <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
   ];
   ];
Line 50: Line 52:
};
};
</syntaxhighlight>
</syntaxhighlight>
=== ZFS support
The default iso does not contain zfs tools and drivers by default. This can be changed by:
<syntaxhighlight lang="nix">
boot.supportedFilesystems = [ "zfs" ];
</syntaxhighlight>
in iso.nix


== software installation inside the 'once' deployed and booted image ==
== software installation inside the 'once' deployed and booted image ==

Revision as of 20:07, 22 August 2017

motivation

creating a modified NIXOS live CD out of a working nixos installation gives you the benefits:

  • verify what is included
  • no need to download it
  • it is easy to add your own programs to the image

how to build your own image

Create a file "iso.nix":

# This module defines a small NixOS installation CD.  It does not
# contain any graphical stuff.
{config, pkgs, ...}:
{
  imports = [
     <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
    # Provide an initial copy of the NixOS channel so that the user
    # doesn't need to run "nix-channel --update" first.
     <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
  ];
}

Build the image via:

 nix-build -A config.system.build.isoImage -I nixos-config=iso.nix  /path/to/nixpkgs/nixos

Start SSH with your SSH key

In your iso.nix:

# enable ssh in the iso boot process
systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ];
users.users.root.openssh.authorizedKeys.keys [
  "ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host"
];

Add static ip addresses

The following snippet is useful, when static ip addresses are required, e.g. for VPS installation

networking = {
  usePredictableInterfaceNames = false;
  interfaces.eth0.ip4 = [{
    address = "64.137.201.46";
    prefixLength = 24;
  }];
  defaultGateway = "64.137.201.1";
  nameServers = [ "8.8.8.8" ];
};


=== ZFS support

The default iso does not contain zfs tools and drivers by default. This can be changed by:

boot.supportedFilesystems = [ "zfs" ];

in iso.nix

software installation inside the 'once' deployed and booted image

in case you have booted from your image you can add software as described here:

references

  • See also section "Building your own NixOS CD" of the NixOS manual.