nixos-kexec-installer/flake.nix

96 lines
2.9 KiB
Nix

{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = nixpkgs.legacyPackages.${system};
nixosConfig = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
"${nixpkgs}/nixos/modules/installer/netboot/netboot-minimal.nix"
({ pkgs, ... }: {
services.openssh = {
enable = true;
startWhenNeeded = true;
};
users.users.root.openssh.authorizedKeys.keyFiles = [
(pkgs.fetchurl {
url = "https://github.com/eboskma.keys";
sha256 = "uwK4FSLSHiwCJU9U7RBFHIoCmr7uUQLM0JM1u0bi4xo=";
})
];
networking = {
useDHCP = true;
};
system.stateVersion = "23.05";
})
];
};
kexecScript = pkgs.writeScript "kexec-installer" ''
#!/bin/sh
if ! kexec -v >/dev/null 2>&1; then
echo "kexec not found: please install kexec-tools" 2>&1
exit 1
fi
kexec --load ./bzImage \
--initrd=./initrd.zst \
--command-line "init=${nixosConfig.config.system.build.toplevel}/init ${toString nixosConfig.config.boot.kernelParams}"
if systemctl --version >/dev/null 2>&1; then
systemctl kexec
else
kexec -e
fi
'';
in
{
formatter = pkgs.nixpkgs-fmt;
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
deadnix.enable = true;
statix.enable = true;
shellcheck = {
enable = true;
types_or = [ "executable" ];
};
shfmt.enable = true;
};
};
};
devShells.default = with pkgs; mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
name = "kexec-installer";
};
packages.kexec-installer = pkgs.linkFarm "netboot" [
{ name = "initrd.zst"; path = "${nixosConfig.config.system.build.netbootRamdisk}/initrd.zst"; }
{ name = "bzImage"; path = "${nixosConfig.config.system.build.kernel}/bzImage"; }
{ name = "kexec-installer"; path = kexecScript; }
];
packages.default = self.packages.${system}.kexec-installer;
});
}