Creating a NixOS live CD: Difference between revisions
imported>Spacekookie m Fixing nameserver option name |
imported>Mic92 isos do now have zfs again |
||
Line 72: | Line 72: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See also== | ==See also== |
Revision as of 17:44, 8 December 2018
Motivation
Creating a modified NixOS LiveCD out of an existing working NixOS installation has a number of benefits:
- Ensures authenticity.
- No need for internet access.
- It is easy to add your own packages and configuration changes to the image.
Building
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 '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix
The resulting image can be found in result
:
$ ls result/iso/
nixos-17.09.git.158ec57-x86_64-linux.iso
SSH
In your iso.nix:
{
...
# Enable SSH in the boot process.
systemd.services.sshd.wantedBy = pkgs.lib.mkForce [ "multi-user.target" ];
users.users.root.openssh.authorizedKeys.keys = [
"ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host"
];
...
}
Static IP Address
Static IP addresses can be set in the image itself. This can be useful 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" ];
};
...
}