def _mount_disks(host: DeployHost, device: str) -> None: host.run(f"zpool import -af") # and finally mount host.run(f"mount -t zfs zroot/root/nixos /mnt") host.run(f"mkdir -p /mnt/home /mnt/boot") host.run(f"mount -t zfs zroot/root/home /mnt/home") host.run(f"mount /dev/disk/by-label/NIXOS_BOOT /mnt/boot")
def deploy(h: DeployHost) -> None: h.run_local( f"rsync {' --exclude '.join([''] + RSYNC_EXCLUDES)} -vaF --delete -e ssh . {h.user}@{h.host}:/etc/nixos" ) # FIXME: build03 has itself as a builder and deadlocks building packages. h.run( f"nixos-rebuild switch --builders '' --option accept-flake-config true" )
def deploy_homemanager(host: DeployHost) -> None: host.run( f"""sudo -u joerg zsh <<'EOF' cd $HOME source $HOME/.zshrc homeshick pull homeshick symlink homeshick cd dotfiles nix build --out-link $HOME/.hm-activate ".#hmConfigurations.{host.meta["flake_attr"]}.activation-script" $HOME/.hm-activate/activate EOF""" )
def deploy(h: DeployHost) -> None: h.run_local( f"rsync --exclude=`git ls-files --exclude-standard -oi --directory` --exclude='.git/' -vaF --delete -e ssh . {h.user}@{h.host}:/etc/nixos", ) flake_path = "/etc/nixos" flake_attr = h.meta.get("flake_attr") if flake_attr: flake_path += "#" + flake_attr target_host = h.meta.get("target_host", "localhost") h.run( f"nixos-rebuild switch --build-host localhost --target-host {target_host} --flake {flake_path}" )
def deploy(h: DeployHost) -> None: h.run_local( f"rsync {' --exclude '.join([''] + RSYNC_EXCLUDES)} -vaF --delete -e ssh . {h.user}@{h.host}:/etc/nixos" ) flake_path = "/etc/nixos" flake_attr = h.meta.get("flake_attr") if flake_attr: flake_path += "#" + flake_attr target_host = h.meta.get("target_host", "localhost") h.run( f"nixos-rebuild switch --build-host localhost --target-host {target_host} --flake {flake_path}" )
def _format_disks(host: DeployHost, devices: List[str]) -> None: assert (len(devices) == 1 or len(devices) == 2 ), "we only support single devices or mirror raids at the moment" # format disk with as follow: # - partition 1 will be the boot partition, needed for legacy (BIOS) boot # - partition 2 is for boot partition # - partition 3 takes up the rest of the space and is for the system for device in devices: host.run( f"sgdisk -Z -n 1:2048:4095 -n 2:4096:+2G -N 3 -t 1:ef02 -t 2:8304 -t 3:8304 {device}" ) # create mdadm raid for /boot with ext4 if len(devices) == 2: boot_parts = [] root_parts = [] for dev in devices: # use partuuids as they are more stable than device names partitions = sfdisk_json(host, dev) boot_parts.append(partitions[1]["node"]) root_parts.append( f"/dev/disk/by-partuuid/{partitions[2]['uuid'].lower()}") host.run( f"mdadm --create --verbose /dev/md127 --raid-devices=2 --level=1 {' '.join(boot_parts)}" ) host.run( f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 mirror {' '.join(root_parts)}" ) boot = "/dev/md127" else: partitions = sfdisk_json(host, devices[0]) boot = partitions[1]["node"] uuid = partitions[2]["uuid"].lower() root_part = f"/dev/disk/by-partuuid/{uuid}" host.run( f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 -O atime=off {root_part}" ) host.run(f"partprobe") host.run(f"mkfs.ext4 -F {boot}") # setup zfs dataset host.run(f"zfs create -o mountpoint=none zroot/root") host.run(f"zfs create -o mountpoint=legacy zroot/root/nixos") host.run(f"zfs create -o mountpoint=legacy zroot/root/home") ## and finally mount host.run(f"mount -t zfs zroot/root/nixos /mnt") host.run(f"mkdir /mnt/home /mnt/boot") host.run(f"mount -t zfs zroot/root/home /mnt/home") host.run(f"mount -t ext4 /dev/md127 /mnt/boot")
def sfdisk_json(host: DeployHost, dev: str) -> List[Any]: out = host.run(f"sfdisk --json {dev}", stdout=subprocess.PIPE) data = json.loads(out.stdout) return data["partitiontable"]["partitions"]
def _format_disks(host: DeployHost, device: str) -> None: # format disk with as follow: # - partition 1 will be the boot partition # - partition 2 takes up the rest of the space and is for the system host.run(f"blkdiscard -f {device}") host.run(f"sgdisk -Z -n 1:2048:+1G -N 2 -t 1:ef00 -t 2:8304 {device}") partitions = sfdisk_json(host, device) boot = partitions[0]["node"] uuid = partitions[1]["uuid"].lower() root_part = f"/dev/disk/by-partuuid/{uuid}" host.run( f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 -O atime=off {root_part}" ) host.run(f"partprobe") host.run(f"mkfs.vfat {boot} -n NIXOS_BOOT") # setup zfs dataset host.run(f"zfs create -o mountpoint=none zroot/root") host.run(f"zfs create -o mountpoint=none zroot/docker") host.run(f"zfs create -o mountpoint=legacy zroot/root/nixos") host.run(f"zfs create -o mountpoint=legacy zroot/root/home")