Skip to content

Commit

Permalink
Improving install-system
Browse files Browse the repository at this point in the history
  • Loading branch information
BCNelson committed Dec 7, 2024
1 parent 54ce20c commit 6c0bffa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ isoTest version='iso_desktop': (isoCreate version)
mkdir -p $(dirname $DISK_IMAGE)
if test -n $DISK_IMAGE && ! test -e $DISK_IMAGE; then
mkdir -p {{ justfile_directory() }}/test_vm
qemu-img create -f qcow2 "$DISK_IMAGE" "4096M"
qemu-img create -f qcow2 "$DISK_IMAGE" "32G"
fi
ISO=$(head -n1 {{ justfile_directory() }}/result/nix-support/hydra-build-products | cut -d'/' -f6)
qemu-system-x86_64 -enable-kvm -m 4096 -cdrom {{ justfile_directory() }}/result/iso/$ISO -drive cache=writeback,file="$DISK_IMAGE",format=qcow2,media=disk
qemu-system-x86_64 -enable-kvm -m 8192 -cdrom {{ justfile_directory() }}/result/iso/$ISO -drive cache=writeback,file="$DISK_IMAGE",format=qcow2,media=disk
isoInstall: isoCreate
#!/usr/bin/env bash
Expand Down
18 changes: 12 additions & 6 deletions pkgs/install-system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ fn main() -> Result<()> {

std::env::set_current_dir(&nix_config)?;

println!("Decrypting Repository");
run_cmd!(gpg --decrypt local.key.asc | git-crypt unlock -)?;

let target_host_prefix = args.target_host.split('-').next().unwrap();

println!("WARNING! The disk {} in {} is about to get wiped",
Expand Down Expand Up @@ -87,15 +90,17 @@ fn main() -> Result<()> {
std::fs::write("flake.nix", flake_content)?;

// Generate SSH keys
run_cmd!(ssh-keygen -t ed25519 -f "$home/id_ed25519" -N "")?;
run_cmd!(ssh-keygen -t ed25519 -N "\"\"" -f "$home/id_ed25519")?;

// read the public key
let public_key = std::fs::read_to_string(format!("{}/id_ed25519.pub", home))?;

let host_def = include_str!("../templates/host.nix")
let host_def_contents = include_str!("../templates/host.nix")
.replace("INSERT_PUBLIC_KEY", &public_key);
// write the host definition
std::fs::write(format!("hosts/data/{}.nix", args.target_host), host_def)?;
let host_def_path = format!("{}/hosts/data/{}.nix", nix_config.display(), args.target_host);
println!("Writing host definition to {}", host_def_path);
std::fs::write(host_def_path, host_def_contents)?;

run_cmd!(
git add -A;
Expand All @@ -114,10 +119,11 @@ fn main() -> Result<()> {

println!("Copying nix-config to /config and /mnt/home/{}", target_user);
run_cmd!(
cp $home/id_ed25519 " /mnt/etc/ssh/ssh_host_ed25519_key"
cp $home/id_ed25519.pub "/mnt/etc/ssh/ssh_host_ed25519_key.pub"
mkdir -p /mnt/etc/ssh;
sudo cp $home/id_ed25519 "/mnt/etc/ssh/ssh_host_ed25519_key";
sudo cp $home/id_ed25519.pub "/mnt/etc/ssh/ssh_host_ed25519_key.pub";
sudo rsync -a "$home/nix-config" "/mnt/config/";
sudo rsync -a --delete "$home/nix-config" "/mnt/home/$target_user"
sudo rsync -a --delete "$home/nix-config" "/mnt/home/$target_user";
)?;

run_cmd!(sudo nixos-enter -c "passwd --expire $target_user")?;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/install-system/templates/default-host.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
imports = [
./hardware-configuration.nix
];
}
}

0 comments on commit 6c0bffa

Please sign in to comment.