Benutzer-Werkzeuge

Webseiten-Werkzeuge


notiz:nixos-tarball

NixOS als Tarball

{ config, pkgs, modulesPath, ... }:

let
  # format target device with `mkfs.ext4 -L NIXOS_ROOT`
  rootfsLabel = "NIXOS_ROOT";
in {
  imports = [
    (modulesPath + "/installer/cd-dvd/system-tarball.nix")
    # (modulesPath + "/profiles/base.nix")
  ];

  tarball.contents = [
    {
      source = pkgs.writeText "grub.cfg" ''
        insmod gfxterm
        insmod png
        set gfxpayload=keep
        menuentry "NixOS" {
          search --set=drive1 --label ${rootfsLabel}
          linux ($drive1)${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile} init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
          initrd ($drive1)${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}
        }
      '';
      target = "/boot/grub.cfg";
    }
  ];

  fileSystems."/" = {
    device = "/dev/disk/by-label/${rootfsLabel}";
    fsType = "ext4";
  };
}
nix-build "<nixpkgs/nixos>" -A config.system.build.tarball -I nixos-config=tarball.nix
{ hostName }:

let
  # format target device with `mkfs.ext4 -L NIXOS_ROOT`
  rootfsLabel = "NIXOS_ROOT";

  configuration =
    { config, pkgs, lib, modulesPath, ... }:

    {
      imports = [
        (modulesPath + "/installer/cd-dvd/system-tarball.nix")
        (./configuration/hosts + "/${hostName}/configuration.nix")
      ];
    
      tarball.contents = [
        {
          source = pkgs.writeText "grub.cfg" ''
            insmod gfxterm
            insmod png
            set gfxpayload=keep
            menuentry "NixOS" {
              search --set=drive1 --label ${rootfsLabel}
              linux ($drive1)${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile} init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
              initrd ($drive1)${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}
            }
          '';
          target = "/boot/grub.cfg";
        }
      ];

      fileSystems."/" = lib.mkForce {
        device = "/dev/disk/by-label/${rootfsLabel}";
        fsType = "ext4";
      };
    };

  evaluatedHost = import <nixpkgs/nixos> {
    inherit configuration;
  };
in
  evaluatedHost.config.system.build.tarball
nix-build tarball.nix --argstr hostName myhost
notiz/nixos-tarball.txt · Zuletzt geändert: 2021/01/14 19:51 von clerie