nixpkgs-suyu/nixos/lib
obadz 24f8cf08cc nixos/lib/make-disk-image: refactor to use nixos-install
- Replace hand-rolled version of nixos-install in make-disk-image by an
  actual call to nixos-install
- Required a few cleanups of nixos-install
- nixos-install invokes an activation script which the hand-rolled version
  in make-disk-image did not do. We remove /etc/machine-id as that's
  a host-specific, impure, output of the activation script

Testing:

nix-build '<nixpkgs/nixos/release.nix>' -A tests.installer.simple passes

Also tried generating an image with:

nix-build -E 'let
    pkgs = import <nixpkgs> {};
    lib = pkgs.lib;
    nixos = import <nixpkgs/nixos> {
      configuration = {
        fileSystems."/".device = "/dev/disk/by-label/nixos";
        boot.loader.grub.devices = [ "/dev/sda" ];
        boot.loader.grub.extraEntries = '"''"'
          menuentry "Ubuntu" {
             insmod ext2
             search --set=root --label ubuntu
             configfile /boot/grub/grub.cfg
          }
        '"''"';
      };
    };
  in import <nixpkgs/nixos/lib/make-disk-image.nix> {
    inherit pkgs lib;
    config = nixos.config;
    diskSize = 2000;
    partitioned = false;
    installBootLoader = false;
  }'

Then installed the image:
$ sudo df if=./result/nixos.img of=/dev/sdaX bs=1M
$ sudo resize2fs /dev/disk/by-label/nixos
$ sudo mount /dev/disk/by-label/nixos /mnt
$ sudo mount --rbind /proc /mnt/proc
$ sudo mount --rbind /dev /mnt/dev
$ sudo chroot /mnt /nix/var/nix/profiles/system/bin/switch-to-configuration boot

[ … optionally do something about passwords … ]

and successfully rebooted to that image.

Was doing all this from inside a Ubuntu VM with a single user nix install.
2016-08-16 15:31:16 +01:00
..
test-driver nixos/test-driver/Logger: Replace invalid UTF-8 2016-05-26 14:24:33 +02:00
build-vms.nix nixos/lib/testing.nix: make 'config' a free variable 2016-03-29 14:16:54 +01:00
eval-config.nix Revert "Add the tool "nixos-typecheck" that can check an option declaration to:" 2016-03-01 20:52:06 +01:00
from-env.nix
make-channel.nix Unify NixOS and Nixpkgs channel structure 2015-08-05 17:37:11 +02:00
make-disk-image.nix nixos/lib/make-disk-image: refactor to use nixos-install 2016-08-16 15:31:16 +01:00
make-ext4-fs.nix nixos: Add derivations for SD card installation images on ARM 2015-07-26 00:31:20 +03:00
make-iso9660-image.nix Combine ISO generation steps 2016-03-15 14:15:12 +01:00
make-iso9660-image.sh Combine ISO generation steps 2016-03-15 14:15:12 +01:00
make-squashfs.nix
make-system-tarball.nix nixos/make-system-tarball: extra commands to be executed before archive 2014-12-11 23:17:27 +01:00
make-system-tarball.sh nixos/make-system-tarball: extra commands to be executed before archive 2014-12-11 23:17:27 +01:00
qemu-flags.nix
testing.nix Revert "Merge branch 'staging'" due to glibc 2016-06-23 09:25:10 +02:00
utils.nix nixos: throw an error on invalid shell package 2016-07-04 15:12:27 +01:00