Skip to content

Instantly share code, notes, and snippets.

@jmettes
Last active June 4, 2021 06:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmettes/abc57a018be70efed9876f5529ff8a1c to your computer and use it in GitHub Desktop.
Save jmettes/abc57a018be70efed9876f5529ff8a1c to your computer and use it in GitHub Desktop.
NixOS ISO
nix-build --attr system "./nixos.nix" -o result-closure
readlink -f result-closure > closure-nix-store-path.txt
rm -r system
mkdir system
nix copy ./result-closure --to file://./system
nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix -o result-iso
{ config, pkgs, ... }:
{
imports =
[
./hardware-configuration.nix
];
boot.loader.grub.device = "/dev/sda";
services.openssh = {
enable = true;
permitRootLogin = "no";
};
networking = {
defaultGateway = {
address = "192.168.1.1";
interface = "enp3s0";
};
interfaces.enp3s0 = {
useDHCP = false;
ipv4.addresses = [{
address = "192.168.1.2";
prefixLength = 24;
}];
};
nameservers = ["8.8.8.8" "8.8.4.4"];
};
users.users.myuser = {
isNormalUser = true;
extraGroups = [ "wheel" ];
password = "mypassword";
};
environment.systemPackages = [
pkgs.vim
];
system.stateVersion = "19.03";
}
{ config, lib, pkgs, ... }:
{
imports = [ ];
boot.initrd.availableKernelModules = [ "ata_piix" "ohci_pci" "sd_mod" "sr_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
swapDevices = [ ];
nix.maxJobs = lib.mkDefault 1;
}
echo "create MBR partition"
parted --script /dev/sda -- mklabel msdos
echo "create root partition"
parted --script -a opt /dev/sda mkpart primary ext4 0% 100%
echo "format partition"
mkfs.ext4 -L nixos /dev/sda1 -F
sleep 1
echo "mount target filesystem"
mount /dev/disk/by-label/nixos /mnt
echo "copy closure to nix store"
nix copy --from file:///etc/system $(cat /etc/closure-nix-store-path.txt) --option binary-caches "" --no-check-sigs
echo "install nix"
nixos-install --no-root-passwd --option binary-caches "" --system $(cat /etc/closure-nix-store-path.txt)
{ config, pkgs, ... }:
{
imports = [
# https://nixos.wiki/wiki/Creating_a_NixOS_live_CD
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
<nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
];
# add the automated installation files
environment.etc = {
"install.sh" = {
source = ./install.sh;
mode = "0700";
};
"closure-nix-store-path.txt" = {
source = ./closure-nix-store-path.txt;
};
"system" = {
source = ./system;
};
};
# automatically run install script
environment.etc."profile.local".text = ''
/etc/install.sh
reboot
'';
}
# http://www.haskellforall.com/2018/08/nixos-in-production.html
let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/b74b1cdb2fecc31ff7a127c5bc89771f887c93bb.tar.gz";
sha256 = "0ncr4g29220amqm4riaa1xf4jz55v2nmh9fi16f1gzhww1gplk8h";
};
in
import "${nixpkgs}/nixos" {
configuration = {
imports = [
./configuration.nix
];
};
system = "x86_64-linux";
}
@eigengrau
Copy link

It looks like it is possible to install the closure without copying it into the installation CDs nix store first, via:

nixos-install \
  --root /mnt \
  --system $(cat /etc/closure-nix-store-path.txt) \
  --option binary-caches file:///etc/system \
  --option require-sigs false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment