Skip to content

Commit e5f9f47

Browse files
committed
BIOS boot, ESP sync, debug improvements
1 parent ca2dc0e commit e5f9f47

10 files changed

Lines changed: 277 additions & 81 deletions

File tree

.github/workflows/installer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Add kexec installer to release
4444
uses: softprops/action-gh-release@v2
4545
with:
46-
make_latest: false
46+
prerelease: true
4747
files: ./result/xnodeos-kexec-installer-*.tar.gz
4848

4949
# - name: Build iso installer
@@ -52,5 +52,5 @@ jobs:
5252
# - name: Add iso installer to release
5353
# uses: softprops/action-gh-release@v2
5454
# with:
55-
# make_latest: false
55+
# prerelease: true
5656
# files: ./result/iso/xnodeos-iso-installer-*.iso

config/xnode-config/boot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BIOS

install.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
set -e # Stop on error
44

55
# Download and extract kexec archive
6-
curl -L "https://github.com/Openmesh-Network/xnodeos/releases/${VERSION:=latest}/download/xnodeos-kexec-installer-$(uname -m)-linux.tar.gz" | tar -xzf- -C /root
6+
if [[ $VERSION ]]; then
7+
URL="https://github.com/Openmesh-Network/xnodeos/releases/download/${VERSION}/xnodeos-kexec-installer-$(uname -m)-linux.tar.gz"
8+
else
9+
URL="https://github.com/Openmesh-Network/xnodeos/releases/latest/download/xnodeos-kexec-installer-$(uname -m)-linux.tar.gz"
10+
export VERSION="latest"
11+
fi
12+
curl -L "$URL" | tar -xzf- -C /root
713

814
# Boot into kexec
915
/root/xnodeos/install

installer/config.nix

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
config = {
1010
services.getty.greetingLine = ''<<< Welcome to Openmesh XnodeOS Installer ${config.system.nixos.label} (\m) - \l >>>'';
1111
services.getty.autologinUser = lib.mkForce "root";
12-
users.users.root.shell = lib.getExe (
13-
pkgs.writeShellScriptBin "install-xnodeos-progress" ''
14-
${config.systemd.package}/bin/journalctl -u install-xnodeos.service -f
15-
''
16-
);
1712

1813
nix =
1914
let
@@ -35,7 +30,7 @@
3530
};
3631

3732
boot.initrd.systemd.enable = true;
38-
environment.etc."pcrlock.d".source = "${pkgs.systemd}/lib/pcrlock.d";
33+
environment.etc."pcrlock.d".source = "${config.systemd.package}/lib/pcrlock.d";
3934
environment.etc."xnodeos-config-cache".source =
4035
inputs.config.nixosConfigurations.xnode.config.system.build.toplevel;
4136
environment.etc."xnodeos-config-file".text = builtins.readFile ../config/flake.nix;
@@ -44,12 +39,6 @@
4439
services.resolved.enable = true;
4540
zramSwap.enable = true;
4641
services.dbus.implementation = "broker";
47-
boot.swraid = {
48-
enable = true;
49-
mdadmConf = ''
50-
MAILADDR samuel.mens@openmesh.network
51-
'';
52-
};
5342

5443
systemd.services.install-xnodeos = {
5544
wantedBy = [ "multi-user.target" ];
@@ -116,13 +105,43 @@
116105
pkgs.gptfdisk
117106
pkgs.parted
118107
pkgs.dosfstools
119-
# pkgs.mdadm
120108
pkgs.cryptsetup
121109
pkgs.btrfs-progs
122110
];
123111
script = lib.readFile ./install.sh;
124112
};
125113

114+
systemd.paths.esp-sync = {
115+
wantedBy = [ "multi-user.target" ];
116+
description = "Watch for /mnt/boot changes";
117+
pathConfig = {
118+
PathModified = "/mnt/boot/";
119+
};
120+
};
121+
122+
systemd.services.esp-sync = {
123+
description = "Sync /mnt/boot to all ESPs";
124+
serviceConfig = {
125+
KillMode = "none";
126+
};
127+
path = [
128+
pkgs.util-linux
129+
pkgs.rsync
130+
];
131+
script = ''
132+
for target in /mnt/boot*; do
133+
[ "$target" = "/mnt/boot" ] && continue
134+
135+
if mountpoint -q "$target"; then
136+
echo "Syncing /mnt/boot -> $target"
137+
rsync -a --delete --inplace /mnt/boot/ "$target/"
138+
else
139+
echo "Skipping $target (not mounted)"
140+
fi
141+
done
142+
'';
143+
};
144+
126145
system.stateVersion = config.system.nixos.release;
127146

128147
# Reduce closure size (https://github.com/nix-community/nixos-images/blob/main/nix/noninteractive.nix)

installer/install.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ sbctl enroll-keys || true
3333
# Detect if system contains TPM
3434
TPM=$(cat /sys/class/tpm/tpm0/tpm_version_major) || TPM=""
3535

36+
# Detect if system is booted into UEFI or Legacy
37+
[ -d /sys/firmware/efi ] && BOOT="UEFI" || BOOT="BIOS"
38+
3639
# Perform hardware scan
3740
nixos-facter -o /etc/nixos/xnode-config/hardware
3841

@@ -41,13 +44,16 @@ cp /etc/xnodeos-config-file /etc/nixos/flake.nix
4144
cp /etc/xnodeos-config-lock /etc/nixos/flake.lock
4245
if [[ $VERSION == "latest" ]]; then
4346
# Remove version lock
44-
sed -i -e "s|\"github:Openmesh-Network/xnodeos/[^\"]*\"|\"github:Openmesh-Network/xnodeos\"|g" ./config/flake.nix
47+
sed -i -e "s|\"github:Openmesh-Network/xnodeos/[^\"]*\"|\"github:Openmesh-Network/xnodeos\"|g" /etc/nixos/flake.nix
4548
fi
4649

4750
# Apply environmental variable configuration
4851
if [[ $TPM ]]; then
4952
echo -n "${TPM}" > /etc/nixos/xnode-config/tpm
5053
fi
54+
if [[ $BOOT ]]; then
55+
echo -n "${BOOT}" > /etc/nixos/xnode-config/boot
56+
fi
5157
if [[ $OWNER ]]; then
5258
echo -n "${OWNER}" > /etc/nixos/xnode-config/owner
5359
fi
@@ -83,10 +89,15 @@ sleep 1 # /dev/disk/by-label/ROOT isn't available instantly
8389
mount --mkdir /dev/disk/by-label/ROOT /mnt
8490
btrfs subvolume create /mnt/root
8591
btrfs subvolume create /mnt/nix
92+
btrfs subvolume create /mnt/boot
8693
umount /mnt
8794
mount --mkdir -o lazytime,noatime,compress-force=zstd:1,subvol=root /dev/disk/by-label/ROOT /mnt
8895
mount --mkdir -o lazytime,noatime,compress-force=zstd:1,subvol=nix /dev/disk/by-label/ROOT /mnt/nix
89-
mount --mkdir -o umask=0077 /dev/md/BOOT /mnt/boot
96+
mount --mkdir -o lazytime,noatime,compress-force=zstd:1,subvol=boot /dev/disk/by-label/ROOT /mnt/boot
97+
for i in "${!DISKS[@]}"; do
98+
mount --mkdir -o umask=0077 "/dev/disk/by-partlabel/disk-disk${i}-ESP" "/mnt/boot${i}"
99+
done
100+
systemctl restart esp-sync.path
90101

91102
if [[ $TPM == "2" ]]; then
92103
# Define policy of allowed TPM2 values
@@ -132,4 +143,6 @@ EOL
132143
)"
133144

134145
# Boot into new OS
135-
reboot
146+
if [ -z "$DEBUG" ]; then
147+
reboot
148+
fi

installer/kexec.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@
7171
'';
7272
};
7373

74+
users.users.root.shell = lib.getExe (
75+
pkgs.writeShellScriptBin "install-xnodeos-shell" ''
76+
source /xnode-config/env || true
77+
78+
if [[ -n "$DEBUG" ]]; then
79+
exec ${lib.getExe pkgs.bash}
80+
else
81+
exec ${config.systemd.package}/bin/journalctl -u install-xnodeos.service -f
82+
fi
83+
''
84+
);
85+
7486
systemd.services.install-xnodeos.script = lib.mkBefore ''
7587
# Extract environmental variables
7688
source /xnode-config/env

nix/os/base.nix

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
{ inputs }:
2-
{ config, lib, ... }:
2+
{
3+
config,
4+
lib,
5+
pkgs,
6+
...
7+
}:
38
{
49
config = {
510
boot.enableContainers = true; # Enable nixos containers
6-
services.fwupd.enable = true; # Allow applications to update firmware
11+
users.mutableUsers = false; # Prevent non-declarative users
12+
users.allowNoPasswordLogin = true; # Allow a system without any users that can be logged into
13+
services.getty.greetingLine = ''<<< Welcome to Openmesh XnodeOS ${config.system.nixos.label} (\m) - \l >>>''; # Change greeting to specify XnodeOS
714
zramSwap.enable = true; # Compress memory
15+
services.fwupd.enable = true; # Allow applications to update firmware
816
services.dbus.implementation = "broker"; # High performance and reliability implementation of D-Bus
917

10-
# Default limit easily exhausted
18+
# Update limits
1119
boot.kernel.sysctl = {
1220
"fs.inotify.max_user_instances" = 2147483647;
1321
"net.core.rmem_max" = 16777216;
@@ -19,6 +27,7 @@
1927
systemd.services.nginx.serviceConfig.LimitNOFILE = 65536;
2028
systemd.services.dbus-broker.serviceConfig.LimitNOFILE = 65536;
2129

30+
# Nix config
2231
nix =
2332
let
2433
flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs;
@@ -46,10 +55,5 @@
4655
options = "--delete-old";
4756
};
4857
};
49-
50-
users.mutableUsers = false;
51-
users.allowNoPasswordLogin = true;
52-
53-
services.getty.greetingLine = ''<<< Welcome to Openmesh XnodeOS ${config.system.nixos.label} (\m) - \l >>>'';
5458
};
5559
}

0 commit comments

Comments
 (0)