Install NixOS on Online.Net: Difference between revisions
imported>Mic92 No edit summary |
imported>Nix m add Server category |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 7: | Line 7: | ||
==Preparation== | ==Preparation== | ||
===Be root=== | === Be root=== | ||
No reason not to be: | No reason not to be: | ||
< | <syntaxhighlight lang="bash"> | ||
sudo su | sudo su | ||
cd | cd | ||
</ | </syntaxhighlight> | ||
=== Create builders === | |||
<syntaxhighlight lang="bash"> | |||
groupadd nixbld | |||
useradd nixbld1 | |||
useradd nixbld2 | |||
useradd nixbld3 | |||
useradd nixbld4 | |||
gpasswd -a nixbld1 nixbld | |||
gpasswd -a nixbld2 nixbld | |||
gpasswd -a nixbld3 nixbld | |||
gpasswd -a nixbld4 nixbld | |||
</syntaxhighlight> | |||
=== Add missing packages === | |||
<syntaxhighlight lang="bash"> | |||
apt install bzip2 btrfs-tools | |||
</syntaxhighlight> | |||
===Change the UI language=== | ===Change the UI language=== | ||
Line 19: | Line 38: | ||
All the Online.net images are set to French by default, which I don't want: | All the Online.net images are set to French by default, which I don't want: | ||
< | <syntaxhighlight lang="bash"> | ||
export LANG=POSIX | export LANG=POSIX | ||
export LC_ALL=POSIX | export LC_ALL=POSIX | ||
</ | </syntaxhighlight> | ||
===Check your partitions=== | ===Check your partitions=== | ||
Line 28: | Line 47: | ||
Now, make sure your partitions are where you expect them, on /dev/sda. | Now, make sure your partitions are where you expect them, on /dev/sda. | ||
< | <syntaxhighlight lang="bash"> | ||
fdisk -l /dev/sda | fdisk -l /dev/sda | ||
</ | </syntaxhighlight> | ||
Here's what mine look like on a Dedibox XC: | Here's what mine look like on a Dedibox XC: | ||
< | <syntaxhighlight lang="bash"> | ||
/dev/sda1 * 2048 391167 194560 83 Linux | /dev/sda1 * 2048 391167 194560 83 Linux | ||
/dev/sda2 391168 1949523967 974566400 83 Linux | /dev/sda2 391168 1949523967 974566400 83 Linux | ||
/dev/sda3 1949523968 1953523711 1999872 82 Linux swap / Solaris | /dev/sda3 1949523968 1953523711 1999872 82 Linux swap / Solaris | ||
</ | </syntaxhighlight> | ||
===Format your partitions=== | ===Format your partitions=== | ||
Line 44: | Line 63: | ||
This will blast away any existing data on your main disk, so make sure you're okay with that. | This will blast away any existing data on your main disk, so make sure you're okay with that. | ||
< | <syntaxhighlight lang="bash"> | ||
mkfs.ext2 /dev/sda1 | mkfs.ext2 /dev/sda1 | ||
mkfs.ext4 /dev/sda2 -L nixos | mkfs.ext4 /dev/sda2 -L nixos | ||
Line 50: | Line 69: | ||
swapoff -a | swapoff -a | ||
mkswap /dev/sda3 | mkswap /dev/sda3 | ||
</ | </syntaxhighlight> | ||
===Mount your freshly minted filesystems=== | ===Mount your freshly minted filesystems=== | ||
Line 56: | Line 75: | ||
and mount the new ones we made: | and mount the new ones we made: | ||
< | <syntaxhighlight lang="bash"> | ||
mount /dev/sda2 /mnt | mount /dev/sda2 /mnt | ||
mkdir /mnt/boot | mkdir /mnt/boot | ||
mount /dev/sda1 /mnt/boot | mount /dev/sda1 /mnt/boot | ||
swapon /dev/sda3 | swapon /dev/sda3 | ||
</ | </syntaxhighlight> | ||
==Nix-flavored stuff== | ==Nix-flavored stuff== | ||
Line 69: | Line 88: | ||
We'll need some nix packages to install nix on the target: | We'll need some nix packages to install nix on the target: | ||
< | <syntaxhighlight lang="bash"> | ||
bash <(curl https://nixos.org/nix/install) | bash <(curl https://nixos.org/nix/install) | ||
. /root/.nix-profile/etc/profile.d/nix.sh | . /root/.nix-profile/etc/profile.d/nix.sh | ||
nix-channel --remove nixpkgs | nix-channel --remove nixpkgs | ||
nix-channel --add http://nixos.org/channels/nixos- | nix-channel --add http://nixos.org/channels/nixos-17.09 nixos | ||
nix-channel --update | nix-channel --update | ||
Line 85: | Line 104: | ||
export NIXOS_CONFIG=/root/configuration.nix | export NIXOS_CONFIG=/root/configuration.nix | ||
nix-env -i -A config.system.build.nixos-install -A config.system.build.nixos-option -A config.system.build.nixos-generate-config -f "<nixos>" | nix-env -i -A config.system.build.nixos-install -A config.system.build.nixos-option -A config.system.build.nixos-generate-config -f "<nixos>" | ||
</ | </syntaxhighlight> | ||
===Make configuration for your target system=== | ===Make configuration for your target system=== | ||
Line 91: | Line 110: | ||
Generate a default configuration: | Generate a default configuration: | ||
< | <syntaxhighlight lang="bash"> | ||
nixos-generate-config --root /mnt | nixos-generate-config --root /mnt | ||
</ | </syntaxhighlight> | ||
This will generate <tt>/mnt/etc/nixos/configuration.nix</tt> and <tt>/mnt/etc/nixos/hardware-configuration.nix</tt>. Eyeball the latter (nano is preinstalled) to make sure the filesystem config looks reasonable and that it's detected your cores correctly. Then customize the former to your liking. By default it'll use DHCP, which didn't seem to work for me on online.net (please tinker and tell me if you got it working with DHCP though), so make sure to customize the network settings if you don't change anything else. | This will generate <tt>/mnt/etc/nixos/configuration.nix</tt> and <tt>/mnt/etc/nixos/hardware-configuration.nix</tt>. Eyeball the latter (nano is preinstalled) to make sure the filesystem config looks reasonable and that it's detected your cores correctly. Then customize the former to your liking. By default it'll use DHCP, which didn't seem to work for me on online.net (please tinker and tell me if you got it working with DHCP though), so make sure to customize the network settings if you don't change anything else. | ||
Line 101: | Line 120: | ||
Here's a sample config from my box: | Here's a sample config from my box: | ||
< | <syntaxhighlight lang="nix"> | ||
{ config, pkgs, ... }: | { config, pkgs, ... }: | ||
Line 116: | Line 135: | ||
}; | }; | ||
# Not strictly required, but useful to be able to use the serial console | |||
boot.kernelParams = [ "console=ttyS1" ]; | |||
networking.hostName = "yourhostname"; | networking.hostName = "yourhostname"; | ||
networking.interfaces.eth0 = { ipAddress = "your ip address"; prefixLength = 24; }; | networking.interfaces.eth0 = { ipAddress = "your ip address"; prefixLength = 24; }; | ||
networking.defaultGateway = "your gateway"; | networking.defaultGateway = "your gateway"; | ||
networking.nameservers = [ "62.210.16.6" "62.210.16.7" ]; | networking.nameservers = [ "62.210.16.6" "62.210.16.7" ]; | ||
# By default, systemd "predictable interface names" are used for network interfaces. | |||
# Since the Dedibox SC only has one network interface, it is safe to disable this, | |||
# and simply use eth0 as above. | |||
# If you remove this line, you need to replace "eth0" above by the correct interface name. | |||
networking.usePredictableInterfaceNames = false; | |||
i18n.defaultLocale = "en_US.UTF-8"; | i18n.defaultLocale = "en_US.UTF-8"; | ||
Line 144: | Line 172: | ||
}; | }; | ||
} | } | ||
</ | </syntaxhighlight> | ||
===Actually install the system=== | ===Actually install the system=== | ||
< | <syntaxhighlight lang="bash"> | ||
unset NIXOS_CONFIG | unset NIXOS_CONFIG | ||
nixos-install | nixos-install | ||
</ | </syntaxhighlight> | ||
That should spend some time downloading and copying stuff around, and then should fail without error. After that, tell the web console to reboot back into normal mode and your machine will be beautifully nixified. Except for the logo stuck on the Online.net console page. Let me know if you figure out how to get rid of that! | That should spend some time downloading and copying stuff around, and then should fail without error. After that, tell the web console to reboot back into normal mode and your machine will be beautifully nixified. Except for the logo stuck on the Online.net console page. Let me know if you figure out how to get rid of that! | ||
Line 160: | Line 188: | ||
See [https://github.com/NixOS/nixpkgs/commit/6ebe4a6a523bbab3388453ac119ab08e295a7e06 this commit] for the fix. | See [https://github.com/NixOS/nixpkgs/commit/6ebe4a6a523bbab3388453ac119ab08e295a7e06 this commit] for the fix. | ||
[[Category:Server]] |