Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions kexec/autojustdoit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ config, lib, ... }:

{
options = {
kexec.autoJustdoit = lib.mkOption {
default = true;
description = "automatically run justdoit on boot";
type = lib.types.bool;
};
};
config = lib.mkIf config.kexec.autoJustdoit {
systemd.units.justdoit = {
wantedBy = [ "multi-user.target" ];
};
systemd.services.justdoit = {
script = "${config.system.build.justdoit}/justdoit";
};
};
}
3 changes: 2 additions & 1 deletion kexec/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
with lib;

{
imports = [ <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix> ./autoreboot.nix ./kexec.nix ./justdoit.nix ];
imports = [ <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix> ./autoreboot.nix ./autojustdoit.nix ./kexec.nix ./justdoit.nix ];

nixpkgs.localSystem.system = "x86_64-linux";
boot.supportedFilesystems = [ "zfs" ];
boot.loader.grub.enable = false;
boot.kernelParams = [
Expand Down
10 changes: 9 additions & 1 deletion kexec/justdoit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ in {
system.build.justdoit = pkgs.writeScriptBin "justdoit" ''
#!${pkgs.stdenv.shell}

SSH_KEY=$(cat /root/.ssh/authorized_keys)

set -e

vgchange -a n
Expand Down Expand Up @@ -124,10 +126,16 @@ in {
{ name = "root"; device = "${cfg.rootDevice}${x}2"; preLVM = true; }
];
''}
users.users.root.openssh.authorizedKeys.keys = [
"$SSH_KEY"
];
}
EOF

nixos-install
echo ">>> your generated nix config is:"
cat /mnt/etc/nixos/generated.nix

nixos-install --no-root-passwd

umount /mnt/home /mnt/nix /mnt/boot /mnt
zpool export ${cfg.poolName}
Expand Down
1 change: 1 addition & 0 deletions kexec/target-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{
imports = [ ./hardware-configuration.nix ./generated.nix ];
nixpkgs.localSystem.system = "x86_64-linux";
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
services.openssh.enable = true;
Expand Down