auto: bootstrapping sparky
This commit is contained in:
parent
748a03aa7b
commit
920aa6e8f6
78
flake.lock
78
flake.lock
|
@ -29,11 +29,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1716431128,
|
"lastModified": 1716773194,
|
||||||
"narHash": "sha256-t3T8HlX3udO6f4ilLcN+j5eC3m2gqsouzSGiriKK6vk=",
|
"narHash": "sha256-rskkGmWlvYFb+CXedBiL8eWEuED0Es0XR4CkJ11RQKY=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "disko",
|
"repo": "disko",
|
||||||
"rev": "7ffc4354dfeb37c8c725ae1465f04a9b45ec8606",
|
"rev": "10986091e47fb1180620b78438512b294b7e8f67",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -126,11 +126,38 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"git-hooks": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat_2",
|
||||||
|
"gitignore": "gitignore",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixvim",
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"nixpkgs-stable": [
|
||||||
|
"nixvim",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1716213921,
|
||||||
|
"narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=",
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "git-hooks.nix",
|
||||||
|
"rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "git-hooks.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"gitignore": {
|
"gitignore": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixvim",
|
"nixvim",
|
||||||
"pre-commit-hooks",
|
"git-hooks",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -228,11 +255,11 @@
|
||||||
"nix-secrets": {
|
"nix-secrets": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1716758960,
|
"lastModified": 1716818667,
|
||||||
"narHash": "sha256-CcI0sEjih/z9ChQg81QY0+fyY//gx9KZ6CoMxAwWJBA=",
|
"narHash": "sha256-t5TG+Y+T+U/a84pILOJgLBQwP6lE4MOMT1+W0+q26a8=",
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"rev": "d0f16258f5867769ed35445b24286cc831ff730c",
|
"rev": "658287451387f15166fe7266b411aba50d520a61",
|
||||||
"revCount": 60,
|
"revCount": 61,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git"
|
"url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git"
|
||||||
},
|
},
|
||||||
|
@ -291,20 +318,20 @@
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
"flake-root": "flake-root",
|
"flake-root": "flake-root",
|
||||||
|
"git-hooks": "git-hooks",
|
||||||
"home-manager": "home-manager_2",
|
"home-manager": "home-manager_2",
|
||||||
"nix-darwin": "nix-darwin",
|
"nix-darwin": "nix-darwin",
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"pre-commit-hooks": "pre-commit-hooks",
|
|
||||||
"treefmt-nix": "treefmt-nix"
|
"treefmt-nix": "treefmt-nix"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1716746631,
|
"lastModified": 1716814660,
|
||||||
"narHash": "sha256-0/G9FQaVm321BoCKREwRqr4l93ZwtvW+4x8gjN67bWs=",
|
"narHash": "sha256-lDy4PXkwQs3qBxVCdwOcNDJbWBCMJcoGfsHnr3U3Okg=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "nixvim",
|
"repo": "nixvim",
|
||||||
"rev": "9697385115fe557468b2ddcbd1277602b3e58d5e",
|
"rev": "4175fac0ea144679b9818bfc3c7becfbd68e25a4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -313,33 +340,6 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pre-commit-hooks": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-compat": "flake-compat_2",
|
|
||||||
"gitignore": "gitignore",
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixvim",
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"nixpkgs-stable": [
|
|
||||||
"nixvim",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1716213921,
|
|
||||||
"narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=",
|
|
||||||
"owner": "cachix",
|
|
||||||
"repo": "pre-commit-hooks.nix",
|
|
||||||
"rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "cachix",
|
|
||||||
"repo": "pre-commit-hooks.nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"disko": "disko",
|
"disko": "disko",
|
||||||
|
|
|
@ -3,17 +3,26 @@ let
|
||||||
pubKeys = lib.filesystem.listFilesRecursive (../common/users/keys);
|
pubKeys = lib.filesystem.listFilesRecursive (../common/users/keys);
|
||||||
secretsDirectory = builtins.toString inputs.nix-secrets;
|
secretsDirectory = builtins.toString inputs.nix-secrets;
|
||||||
secretsFile = "${secretsDirectory}/secrets.yaml";
|
secretsFile = "${secretsDirectory}/secrets.yaml";
|
||||||
|
|
||||||
|
# Disko setup
|
||||||
|
fsType = "btrfs";
|
||||||
|
dev = "/dev/vda";
|
||||||
|
encrypted = false;
|
||||||
|
btrfsMountDevice = "/dev/mapper/crypted";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
# Disk configuration
|
# Disk configuration
|
||||||
inputs.sops-nix.nixosModules.sops
|
inputs.sops-nix.nixosModules.sops
|
||||||
|
|
||||||
|
# Disk configuration
|
||||||
inputs.disko.nixosModules.disko
|
inputs.disko.nixosModules.disko
|
||||||
(import ../common/disks/luks-btrfs-subvolumes.nix { device = "/dev/vda" ; })
|
(import ../common/disks { device = dev; fsType = fsType; encrypted = encrypted; })
|
||||||
#(import ../common/disks/std-disk-config.nix { device = "/dev/vda" ; })
|
|
||||||
../common/optional/btrfs-impermanence.nix
|
# Impermanence
|
||||||
inputs.impermanence.nixosModules.impermanence
|
inputs.impermanence.nixosModules.impermanence
|
||||||
|
(import ../common/disks/btrfs-impermanence.nix { btrfsMountDevice = btrfsMountDevice; lib = lib; })
|
||||||
|
|
||||||
# Import core options
|
# Import core options
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
|
@ -43,7 +52,6 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
i18n.defaultLocale = "en_GB.UTF-8";
|
i18n.defaultLocale = "en_GB.UTF-8";
|
||||||
console = {
|
console = {
|
||||||
font = "Lat2-Terminus16";
|
font = "Lat2-Terminus16";
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
{lib, ...}:
|
{lib, btrfsMountDevice, ...}:
|
||||||
|
let
|
||||||
|
device = btrfsMountDevice;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
boot.initrd.postDeviceCommands = lib.mkAfter ''
|
boot.initrd.postDeviceCommands = lib.mkAfter ''
|
||||||
mkdir /btrfs_tmp
|
mkdir /btrfs_tmp
|
||||||
mount /dev/mapper/crypted /btrfs_tmp
|
mount ${device} /btrfs_tmp
|
||||||
if [[ -e /btrfs_tmp/root ]]; then
|
if [[ -e /btrfs_tmp/root ]]; then
|
||||||
mkdir -p /btrfs_tmp/old_roots
|
mkdir -p /btrfs_tmp/old_roots
|
||||||
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
|
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
|
|
@ -0,0 +1,7 @@
|
||||||
|
{ device, fsType, encrypted, ... }:
|
||||||
|
let
|
||||||
|
ext4 = import ./gpt-bios-compact.nix { inherit device; };
|
||||||
|
|
||||||
|
btrfs = import ./luks-btrfs-subvolumes.nix { inherit device; };
|
||||||
|
in
|
||||||
|
if fsType == "ext4" then ext4 else btrfs
|
|
@ -25,12 +25,7 @@
|
||||||
content = {
|
content = {
|
||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted";
|
name = "crypted";
|
||||||
# disable settings.keyFile if you want to use interactive password entry
|
|
||||||
passwordFile = "/tmp/luks_secret.key"; # Interactive
|
passwordFile = "/tmp/luks_secret.key"; # Interactive
|
||||||
# settings = {
|
|
||||||
# allowDiscards = true;
|
|
||||||
# keyFile = "${sopsHashedPasswordFile}";
|
|
||||||
# };
|
|
||||||
content = {
|
content = {
|
||||||
type = "btrfs";
|
type = "btrfs";
|
||||||
extraArgs = ["-f"];
|
extraArgs = ["-f"];
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"/var/lib/nixos"
|
"/var/lib/nixos"
|
||||||
"/var/lib/systemd/coredump"
|
"/var/lib/systemd/coredump"
|
||||||
"/etc/NetworkManager/system-connections"
|
"/etc/NetworkManager/system-connections"
|
||||||
|
"/var/lib/flatpak"
|
||||||
];
|
];
|
||||||
files = [
|
files = [
|
||||||
"/etc/ssh/ssh_host_ed25519_key"
|
"/etc/ssh/ssh_host_ed25519_key"
|
||||||
|
|
|
@ -1,24 +1,55 @@
|
||||||
{ pkgs, inputs, config, lib, ... }:
|
{ pkgs, inputs, config, lib, ... }:
|
||||||
let
|
let
|
||||||
|
username = "admin";
|
||||||
pubKeys = lib.filesystem.listFilesRecursive (../keys);
|
pubKeys = lib.filesystem.listFilesRecursive (../keys);
|
||||||
|
hostname = config.networking.hostName;
|
||||||
|
sopsHashedPasswordFile = lib.optionalString (lib.hasAttr "sops-nix" inputs) config.sops.secrets."passwords/${username}".path;
|
||||||
|
secretsDirectory = builtins.toString inputs.nix-secrets;
|
||||||
|
secretsFile = "${secretsDirectory}/secrets.yaml";
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
users.users.admin = {
|
users.users.${username} = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
password = "nixos"; # Overridden if sops is working
|
|
||||||
shell = pkgs.zsh; # default shell
|
shell = pkgs.zsh; # default shell
|
||||||
|
hashedPasswordFile = sopsHashedPasswordFile;
|
||||||
openssh.authorizedKeys.keys = lib.lists.forEach pubKeys (key: builtins.readFile key);
|
openssh.authorizedKeys.keys = lib.lists.forEach pubKeys (key: builtins.readFile key);
|
||||||
|
|
||||||
extraGroups =
|
extraGroups =
|
||||||
[ "qemu-libvirtd" "libvirtd"
|
[
|
||||||
"wheel" "video" "audio" "disk" "networkmanager"
|
"wheel"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
packages = with pkgs; [
|
||||||
|
flatpak
|
||||||
|
gnome.gnome-software
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
sops.secrets = {
|
||||||
|
"passwords/${username}" = {
|
||||||
|
sopsFile = "${secretsFile}";
|
||||||
|
neededForUsers = true;
|
||||||
|
};
|
||||||
|
"ssh_keys/${username}/id_ed25519" = {
|
||||||
|
path = "/home/${username}/.ssh/id_ed25519";
|
||||||
|
mode = "0600";
|
||||||
|
owner = "${username}";
|
||||||
|
};
|
||||||
|
"ssh_keys/${username}/id_ed25519.pub" = {
|
||||||
|
path = "/home/${username}/.ssh/id_ed25519.pub";
|
||||||
|
mode = "0644";
|
||||||
|
owner = "${username}";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.zsh.enable = true;
|
programs.zsh.enable = true;
|
||||||
|
programs.fuse.userAllowOther = true;
|
||||||
|
|
||||||
environment.systemPackages = [
|
home-manager = {
|
||||||
];
|
extraSpecialArgs = { inherit inputs; };
|
||||||
|
users = {
|
||||||
|
${username} = import ../../../../home/${hostname}.nix;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
{ inputs, config, lib, pkgs, outputs,... }:
|
{ inputs, config, lib, pkgs, outputs,... }:
|
||||||
let
|
|
||||||
dev = "/dev/vda";
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
# Disk configuration
|
|
||||||
inputs.disko.nixosModules.disko
|
|
||||||
(import ../common/disks/luks-btrfs-subvolumes.nix { device = "/dev/vda" ; })
|
|
||||||
../common/optional/btrfs-impermanence.nix
|
|
||||||
|
|
||||||
# Create users for this host
|
# Create users for this host
|
||||||
../common/users/media
|
../common/users/media
|
||||||
|
|
||||||
|
@ -31,13 +23,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.persistence."/persist" = {
|
|
||||||
hideMounts = true;
|
|
||||||
directories = [
|
|
||||||
"/var/lib/flatpak"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
networking = {
|
networking = {
|
||||||
hostName = "sparky";
|
hostName = "sparky";
|
||||||
networkmanager.enable = true;
|
networkmanager.enable = true;
|
||||||
|
|
|
@ -60,16 +60,11 @@ sed -i "{
|
||||||
/&hosts:/{n; p; s/\(.*- &\).*/\1$hostname $HOST_AGE_KEY/}
|
/&hosts:/{n; p; s/\(.*- &\).*/\1$hostname $HOST_AGE_KEY/}
|
||||||
}" $SOPS_FILE
|
}" $SOPS_FILE
|
||||||
|
|
||||||
just update-sops-secrets && just update-flake-secrets && just update-flake
|
|
||||||
|
|
||||||
# Extract luks key from secrets
|
# Extract luks key from secrets
|
||||||
luks_secret=$(nix-shell -p sops --run "SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt sops -d --extract '[""\"luks_passphrase""\"][""\"sparky""\"]' ../nix-secrets/secrets.yaml")
|
luks_secret=$(nix-shell -p sops --run "SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt sops -d --extract '[""\"luks_passphrase""\"][""\"$hostname""\"]' ../nix-secrets/secrets.yaml")
|
||||||
echo "$luks_secret" > /tmp/luks_secret.key
|
echo "$luks_secret" > /tmp/luks_secret.key
|
||||||
|
|
||||||
# Install Nixos to target
|
# Install Nixos to target
|
||||||
cd "$HOME/nixos"
|
|
||||||
git add . && git commit -m "auto: bootstrapping $hostname" && git push
|
|
||||||
|
|
||||||
SHELL=/bin/sh nix run github:nix-community/nixos-anywhere/242444d228636b1f0e89d3681f04a75254c29f66 -- --extra-files "$temp_ssh" --disk-encryption-keys /tmp/luks_secret.key /tmp/luks_secret.key --flake .#"$config" root@"$ip" -i "$HOME/.ssh/id_ed25519"
|
SHELL=/bin/sh nix run github:nix-community/nixos-anywhere/242444d228636b1f0e89d3681f04a75254c29f66 -- --extra-files "$temp_ssh" --disk-encryption-keys /tmp/luks_secret.key /tmp/luks_secret.key --flake .#"$config" root@"$ip" -i "$HOME/.ssh/id_ed25519"
|
||||||
[ $? != 0 ] && echo "Error installing Nixos" && exit 1
|
[ $? != 0 ] && echo "Error installing Nixos" && exit 1
|
||||||
|
|
||||||
|
@ -91,6 +86,10 @@ do
|
||||||
done
|
done
|
||||||
echo "$ip is now online and port 22 is open!"
|
echo "$ip is now online and port 22 is open!"
|
||||||
|
|
||||||
|
# Commit and push changes
|
||||||
|
just update-sops-secrets && just update-flake-secrets && just update-flake
|
||||||
|
git add . && git commit -m "auto: bootstrapping $hostname" && git push
|
||||||
|
|
||||||
# Authorise source public key
|
# Authorise source public key
|
||||||
echo "Copying pubkey to target host"
|
echo "Copying pubkey to target host"
|
||||||
ssh-copy-id -i "$(readlink -f "$HOME/.ssh/id_ed25519.pub")" "root@$ip"
|
ssh-copy-id -i "$(readlink -f "$HOME/.ssh/id_ed25519.pub")" "root@$ip"
|
||||||
|
|
Loading…
Reference in New Issue