Instantly share code, notes, and snippets.

Embed
What would you like to do?
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | gdisk /dev/sda
n # new partition
1 # partition number 1
2048 # first sector
4095 # end sector
ef02 # BIOS boot partition
n # new partition
2 # partition number 2
4096 # first sector
1028095 # end sector
8300 # Linux filesystem
n # new partition
3 # partition number 3
1028096 # first sector
3125247 # end sector
8200 # Linux swap
n # new partition
4 # partition number 4
3125248 # first sector
# default, use the rest of the disk for our root partition
8300 # linux filesystem
v # verify
w # write
Y # confirm write
EOF
mkfs.ext4 -L nixos /dev/sda4
mkfs.ext4 -L boot /dev/sda2
mkswap -L swap /dev/sda3
mount /dev/sda4 /mnt
mkdir /mnt/boot
mount /dev/sda2 /mnt/boot
swapon /dev/sda3
adduser --disabled-password --gecos "" nix
groupadd -r nixbld
for n in $(seq 1 10); do useradd -c "Nix build user $n" \
-d /var/empty -g nixbld -G nixbld -M -N -r -s "$(which nologin)" \
nixbld$n; done
update-ca-certificates
mkdir /nix
chown -R nix /nix
su - nix << HERE
bash <(curl https://nixos.org/nix/install)
HERE
. ~nix/.nix-profile/etc/profile.d/nix.sh
nix-channel --remove nixpkgs
nix-channel --add http://nixos.org/channels/nixos-15.09 nixos
nix-channel --update
cat <<EOF > /root/configuration.nix
{ fileSystems."/" = {};
boot.loader.grub.enable = false;
}
EOF
export NIX_PATH=nixpkgs=/root/.nix-defexpr/channels/nixos:nixos=/root/.nix-defexpr/channels/nixos/nixos
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>"
# Configure NixOS
export NIX_PATH=nixpkgs=/root/.nix-defexpr/channels/nixos:nixos=/root/.nix-defexpr/channels/nixos/nixos
nixos-generate-config --root /mnt
OLD_IMPORT_LINE=" imports \= \[ \]\;"
NEW_IMPORT_LINE=" imports = [ <nixpkgs\/nixos\/modules\/profiles\/qemu-guest.nix> ];"
sed -i "s#$OLD_IMPORT_LINE#$NEW_IMPORT_LINE#g" /mnt/etc/nixos/hardware-configuration.nix
unset OLD_IMPORT_LINE
unset NEW_IMPORT_LINE
cat <<EOF > /mnt/etc/nixos/configuration.nix
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running 'nixos-help').
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
boot.initrd.availableKernelModules = [ "virtio_net" "virtio_pci" "virtio_blk" "virtio_scsi" "9p" "9pnet_virtio" "ata_piix" "virtio_pci" ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
boot.kernelParams = [ "console=ttyS0" ];
boot.loader.grub.extraConfig = "serial; terminal_input serial; terminal_output serial";
# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
# Define on which hard drive you want to install Grub.
boot.loader.grub.device = "/dev/sda";
# networking.hostName = "nixos"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# Select internationalisation properties.
# i18n = {
# consoleFont = "Lat2-Terminus16";
# consoleKeyMap = "us";
# defaultLocale = "en_US.UTF-8";
# };
# Set your time zone.
# time.timeZone = "Europe/Amsterdam";
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
# environment.systemPackages = with pkgs; [
# wget
# ];
# List services that you want to enable:
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# Enable CUPS to print documents.
# services.printing.enable = true;
# Enable the X11 windowing system.
# services.xserver.enable = true;
# services.xserver.layout = "us";
# services.xserver.xkbOptions = "eurosign:e";
# Enable the KDE Desktop Environment.
# services.xserver.displayManager.kdm.enable = true;
# services.xserver.desktopManager.kde4.enable = true;
# The NixOS release to be compatible with for stateful data such as databases.
system.stateVersion = "15.09";
}
EOF
#systemctl status dev-sda3.swap
unset NIXOS_CONFIG
nixos-install
echo "!!! Set a root-password for your NixOS installation"
echo "!!! Use the tool \`passwd\` to set the password"
nixos-install --chroot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment