mirror of
https://codeberg.org/muon/home.git
synced 2025-12-05 23:57:46 +00:00
Fix install script
This commit is contained in:
parent
4750f4ea9d
commit
0b2342ff13
5 changed files with 121 additions and 69 deletions
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
inputs,
|
||||
system,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
# Hardware
|
||||
|
|
@ -10,6 +12,13 @@
|
|||
+ "/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix")
|
||||
];
|
||||
|
||||
# Install
|
||||
environment.etc.sops-key = {
|
||||
source = "/home/muon/.config/sops-nix/secrets/sops-key";
|
||||
target = "sops-nix/key.txt";
|
||||
};
|
||||
sops.age.keyFile = lib.mkForce "/etc/sops-nix/key.txt";
|
||||
|
||||
# System
|
||||
mods.user.name = "muon";
|
||||
networking.hostName = "murk";
|
||||
|
|
|
|||
|
|
@ -8,24 +8,25 @@
|
|||
modulesPath,
|
||||
...
|
||||
}: {
|
||||
# imports =
|
||||
# [ (modulesPath + "/installer/scan/not-detected.nix")
|
||||
# ];
|
||||
#
|
||||
# hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||
imports = [
|
||||
(modulesPath + "/installer/scan/not-detected.nix")
|
||||
];
|
||||
|
||||
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||
|
||||
boot.supportedFilesystems = ["btrfs"];
|
||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||
networking.useDHCP = lib.mkForce true;
|
||||
|
||||
imports = [
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
];
|
||||
|
||||
virtualisation.vmVariant = {
|
||||
# following configuration is added only when building VM with build-vm
|
||||
virtualisation = {
|
||||
memorySize = 4096; # Use 2048MiB memory.
|
||||
cores = 3;
|
||||
};
|
||||
};
|
||||
# imports = [
|
||||
# (modulesPath + "/profiles/qemu-guest.nix")
|
||||
# ];
|
||||
#
|
||||
# virtualisation.vmVariant = {
|
||||
# # following configuration is added only when building VM with build-vm
|
||||
# virtualisation = {
|
||||
# memorySize = 4096; # Use 2048MiB memory.
|
||||
# cores = 3;
|
||||
# };
|
||||
# };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,53 +10,85 @@
|
|||
installScript = pkgs.writeShellApplication {
|
||||
name = "install-flake";
|
||||
text = ''
|
||||
echo "Cloning config..."
|
||||
git clone https://codeberg.org/muon/home
|
||||
msg() {
|
||||
printf "\033[01;32minstall-flake: \033[0m%s\n" "$1"
|
||||
}
|
||||
|
||||
msg "Cloning config..."
|
||||
if [[ ! "$PWD" == "$HOME" ]]; then
|
||||
cd
|
||||
fi
|
||||
if [[ ! -d "home" ]]; then
|
||||
git clone https://codeberg.org/muon/home
|
||||
else
|
||||
msg "Already cloned!"
|
||||
fi
|
||||
cd home
|
||||
nvim hosts/"$(hostname)"/disk-config.nix
|
||||
|
||||
echo "Running disko..."
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount hosts/"$(hostname)"/disk-config.nix
|
||||
msg "Running disko..."
|
||||
if ! mount | grep "on /mnt" ; then
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount hosts/"$(hostname)"/disk-config.nix
|
||||
else
|
||||
msg "Already mounted!"
|
||||
fi
|
||||
|
||||
echo "Making blank root snapshot..."
|
||||
msg "Making blank root snapshot..."
|
||||
sudo mkdir -p /tmp/mnt
|
||||
sudo mount /dev/mapper/crypted /tmp/mnt
|
||||
sudo btrfs subvolume snapshot -r /tmp/mnt/root /tmp/mnt/root-blank
|
||||
if [[ ! -e /tmp/mnt/root-blank ]]; then
|
||||
sudo btrfs subvolume snapshot -r /tmp/mnt/root /tmp/mnt/root-blank
|
||||
else
|
||||
msg "Already snapshotted!"
|
||||
fi
|
||||
sudo umount /tmp/mnt
|
||||
|
||||
echo "Retrieving sops key..."
|
||||
rbw config set email admin@muon.host
|
||||
rbw config set base_url https://vault.muon.host
|
||||
rbw login
|
||||
msg "Retrieving sops key..."
|
||||
sudo mkdir -p /mnt/persist/var/lib/sops-nix
|
||||
if [[ ! -e /mnt/persist/var/lib/sops-nix/key.txt ]]; then
|
||||
rbw config set email admin@muon.host
|
||||
rbw config set base_url https://vault.muon.host
|
||||
rbw login
|
||||
rbw get sops | sudo tee /mnt/persist/var/lib/sops-nix/key.txt
|
||||
# sudo cp /etc/sops-nix/key.txt /mnt/persist/var/lib/sops-nix/key.txt
|
||||
sudo chown muon:users /mnt/persist/var/lib/sops-nix -R
|
||||
else
|
||||
msg "Already retrieved!"
|
||||
fi
|
||||
|
||||
sudo mkdir -p /persist/var/lib/sops-nix
|
||||
rbw get sops > /mnt/persist/var/lib/sops-nix/key.txt
|
||||
sudo chown muon:users /mnt/persist/var/lib/sops-nix -R
|
||||
|
||||
echo "Setting hardware config..."
|
||||
msg "Setting hardware config..."
|
||||
sudo nixos-generate-config --no-filesystems --root /mnt
|
||||
cp /mnt/etc/nixos/hardware-configuration.nix hosts/"$(hostname)"/hardware-configuration.nix
|
||||
|
||||
echo "Installing NixOS config..."
|
||||
msg "Installing NixOS config..."
|
||||
sudo nixos-install --root /mnt --no-root-passwd --flake .#"$(hostname)"
|
||||
|
||||
echo "Edit persistent filesystem..."
|
||||
PERSIST="$HOME/persist"
|
||||
msg "Edit persistent filesystem..."
|
||||
PERSIST="$HOME/persist.sh"
|
||||
if [[ ! -e $PERSIST ]]; then
|
||||
sudo cp "$HOME/persist.txt" "$PERSIST"
|
||||
sudo chmod +w "$PERSIST"
|
||||
fi
|
||||
nvim "$PERSIST"
|
||||
|
||||
echo "Copying persistent filesystem..."
|
||||
msg "Copying persistent filesystem..."
|
||||
make_persist() {
|
||||
F="/mnt$1"
|
||||
P="/mnt/persist$1"
|
||||
if [[ -d "$F" ]]; then
|
||||
mkdir -p "$F" "$P"
|
||||
elif [[ -f "$F" ]]; then
|
||||
mkdir -p "$(dirname "$F")" "$(dirname "$P")"
|
||||
F="$1"
|
||||
P="/mnt/persist''${1#/mnt}"
|
||||
echo "$P"
|
||||
if [[ -e "$F" ]]; then
|
||||
sudo mkdir -p "$(dirname "$P")"
|
||||
else
|
||||
echo "Error: $F does not exist!"
|
||||
return 1
|
||||
msg "Error: $F does not exist!"
|
||||
return 0
|
||||
fi
|
||||
if [[ -d "$F" ]]; then
|
||||
if [[ -n "$( ls -A "$F")" ]]; then
|
||||
sudo cp -r "$F/"* "$P"
|
||||
fi
|
||||
elif [[ -f "$F" ]]; then
|
||||
sudo cp "$F" "$P"
|
||||
fi
|
||||
cp -r "$F" "$P"
|
||||
}
|
||||
grep -v '^#' "$PERSIST" | while read -r file ; do
|
||||
make_persist "$file"
|
||||
|
|
@ -65,14 +97,16 @@
|
|||
};
|
||||
in {
|
||||
# Install
|
||||
# sops.age.keyFile = lib.mkForce "/etc/sops-nix/key.txt";
|
||||
programs.atuin.enable = lib.mkForce false;
|
||||
home.file.persist = {
|
||||
target = "persist.txt";
|
||||
text = ''
|
||||
/var/lib/nixos
|
||||
/var/lib/systemd/coredump
|
||||
/mnt/var/lib/nixos
|
||||
/mnt/var/lib/systemd/coredump
|
||||
/mnt/etc/machine-id
|
||||
/etc/NetworkManager
|
||||
/var/lib/NetworkManager
|
||||
/etc/machine-id
|
||||
'';
|
||||
};
|
||||
home.packages = with pkgs;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue