Creating a NixOS live CD: Difference between revisions
imported>Makefu m How-To -> Guide |
imported>HLandau No edit summary |
||
Line 1: | Line 1: | ||
==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 <tt>iso.nix</tt>: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# This module defines a small NixOS installation CD. It does not | # This module defines a small NixOS installation CD. It does not | ||
Line 17: | Line 15: | ||
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 | # Provide an initial copy of the NixOS channel so that the user | ||
# doesn't need to run "nix-channel --update" first. | # doesn't need to run "nix-channel --update" first. | ||
Line 32: | Line 31: | ||
The resulting image can be found in <code>result</code>: | The resulting image can be found in <code>result</code>: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
ls result/iso/ | $ ls result/iso/ | ||
nixos-17.09.git.158ec57-x86_64-linux.iso | nixos-17.09.git.158ec57-x86_64-linux.iso | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | ===SSH=== | ||
In your <tt>iso.nix</tt>: | |||
In your iso.nix: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
# | { | ||
systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ]; | ... | ||
users.users.root.openssh.authorizedKeys.keys [ | # Enable SSH in the boot process. | ||
systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ]; | |||
]; | users.users.root.openssh.authorizedKeys.keys [ | ||
"ssh-ed25519 AaAeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee username@host" | |||
]; | |||
... | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | ===Static IP Address=== | ||
Static IP addresses can be set in the image itself. This can be useful for VPS installation. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
networking = { | { | ||
... | |||
networking = { | |||
usePredictableInterfaceNames = false; | |||
interfaces.eth0.ip4 = [{ | |||
address = "64.137.201.46"; | |||
prefixLength = 24; | |||
}]; | |||
}; | defaultGateway = "64.137.201.1"; | ||
nameServers = [ "8.8.8.8" ]; | |||
}; | |||
... | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== ZFS | ===ZFS Support=== | ||
NixOS ISOs do not contain ZFS tools and kernel modules by default. They can be added via: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
boot.supportedFilesystems = [ "zfs" ]; | { | ||
... | |||
boot.supportedFilesystems = [ "zfs" ]; | |||
... | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See also== | |||
* [https://nixos.org/nixos/manual/index.html#sec-building-cd NixOS Manual: Building your own CD]. | |||
== | |||
* | |||
[[Category:NixOS]] | [[Category:NixOS]] |
Revision as of 20:48, 24 October 2017
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 = 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" ];
};
...
}
ZFS Support
NixOS ISOs do not contain ZFS tools and kernel modules by default. They can be added via:
{
...
boot.supportedFilesystems = [ "zfs" ];
...
}