nixos-config: add vm-install-iso
This commit is contained in:
parent
ee9b955545
commit
56f42e96f7
2 changed files with 94 additions and 0 deletions
2
nixos-configuration/vm-install-iso/Justfile
Normal file
2
nixos-configuration/vm-install-iso/Justfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
build:
|
||||
nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix
|
92
nixos-configuration/vm-install-iso/iso.nix
Normal file
92
nixos-configuration/vm-install-iso/iso.nix
Normal file
|
@ -0,0 +1,92 @@
|
|||
# This module defines a small NixOS installation CD. It does not
|
||||
# contain any graphical stuff.
|
||||
{config, pkgs, lib, ...}:
|
||||
|
||||
let nixos-init-script = ''
|
||||
#!${pkgs.stdenv.shell}
|
||||
|
||||
export HOME=/root
|
||||
export PATH=${pkgs.lib.makeBinPath [
|
||||
config.nix.package pkgs.systemd pkgs.gnugrep pkgs.gnused config.system.build.nixos-rebuild
|
||||
config.system.build.nixos-install pkgs.utillinux pkgs.e2fsprogs pkgs.coreutils pkgs.hdparm
|
||||
]}:$PATH
|
||||
export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
|
||||
|
||||
set -xe
|
||||
|
||||
fdisk -w always -W always /dev/vda <<EOF
|
||||
g
|
||||
n
|
||||
1
|
||||
|
||||
+8M
|
||||
n
|
||||
2
|
||||
|
||||
+1G
|
||||
n
|
||||
3
|
||||
|
||||
|
||||
t
|
||||
1
|
||||
4
|
||||
w
|
||||
EOF
|
||||
lsblk
|
||||
|
||||
mkfs.ext4 -m0 -L nixos /dev/vda3
|
||||
mount -L nixos /mnt
|
||||
mkswap -L swap /dev/vda2
|
||||
swapon -L swap
|
||||
|
||||
mkdir /mnt/etc/nixos -p
|
||||
cp /dev/vdb /mnt/etc/nixos/configuration.nix
|
||||
|
||||
nix-channel --update
|
||||
nixos-install
|
||||
reboot
|
||||
'';
|
||||
in {
|
||||
imports = [
|
||||
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel.nix>
|
||||
|
||||
# Provide an initial copy of the NixOS channel so that the user
|
||||
# doesn't need to run "nix-channel --update" first.
|
||||
# <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
|
||||
];
|
||||
|
||||
isoImage.isoName = lib.mkForce "${config.isoImage.isoBaseName}-${pkgs.stdenv.hostPlatform.system}.iso";
|
||||
boot.loader.timeout = lib.mkForce 0;
|
||||
boot.postBootCommands = ''
|
||||
'';
|
||||
|
||||
environment.systemPackages = [];
|
||||
|
||||
users.users.root = {
|
||||
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4RFtHz0sE5y0AyZZm/tH7bBBgsx55gLPt5tGsl9yZlOzih6n4qbJE/9OOdwnOY2AHRe2lrlTekbW5ewWSBBCbiBE3Vux86sLgy7LM9zoKaNC+E3hmxaoS9SExn0BTkb3kNlOcj2k6UyJhkZWEsqVMV5C21R8EWmMlLY/qm3AxptNjOyzKDwNX2zlHZ5IyjgzO4ZjIxjawmJlUrVEn7/m+M7qK3I1Tyg/ZvDSfmxVJS97sVzseYE0rVwLEWJQOnHh0wnfl27smr2McAB7Cy6sxKyPKvEGyXbNqqb8fqk4okZlRRxhq/XkKlC7IZr+uqYxlL4HN8vjkTRNlgenDUSVT cardno:000604870382" ];
|
||||
};
|
||||
|
||||
services.gpm.enable = true;
|
||||
systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ];
|
||||
|
||||
systemd.services.nixos-init = {
|
||||
script = nixos-init-script;
|
||||
path = with pkgs; [ ];
|
||||
|
||||
description = "Initialize /dev/vda from configuration.nix found at /dev/vdb";
|
||||
enable = true;
|
||||
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "multi-user.target" ];
|
||||
requires = [ "network-online.target" ];
|
||||
|
||||
restartIfChanged = false;
|
||||
unitConfig.X-StopOnRemoval = false;
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue