Skip to content

Commit 0af9b21

Browse files
committed
add risc64 kexec image
1 parent c1e6a5f commit 0af9b21

File tree

4 files changed

+101
-39
lines changed

4 files changed

+101
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ integration into automated nixos installation scripts, since you can cleanly
3636
disconnect from the running machine before the kexec takes place. The tarball
3737
is also designed to be run from NixOS, which can be useful for new installations
3838

39-
## Iso installer images
39+
## ISO installer images
4040

4141
This image allows to boot a NixOS installer off a USB-Stick.
4242
This installer has been optimized for remote installation i.e.

flake.nix

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,39 @@
55
inputs.nixos-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
66

77
nixConfig.extra-substituters = [ "https://nix-community.cachix.org" ];
8-
nixConfig.extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ];
8+
nixConfig.extra-trusted-public-keys = [
9+
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
10+
];
911

10-
outputs = { self, nixos-unstable, nixos-stable }:
12+
outputs =
13+
{
14+
self,
15+
nixos-unstable,
16+
nixos-stable,
17+
}:
1118
let
12-
supportedSystems = [ "aarch64-linux" "x86_64-linux" ];
19+
supportedSystems = [
20+
"aarch64-linux"
21+
"x86_64-linux"
22+
];
1323
forAllSystems = nixos-unstable.lib.genAttrs supportedSystems;
14-
in
15-
{
16-
packages = forAllSystems (system:
24+
25+
packages = forAllSystems (
26+
system:
1727
let
1828
netboot = nixpkgs: (import (nixpkgs + "/nixos/release.nix") { }).netboot.${system};
19-
kexec-installer = nixpkgs: modules: (nixpkgs.legacyPackages.${system}.nixos (modules ++ [ self.nixosModules.kexec-installer ])).config.system.build.kexecTarball;
20-
netboot-installer = nixpkgs: (nixpkgs.legacyPackages.${system}.nixos [ self.nixosModules.netboot-installer ]).config.system.build.netboot;
21-
image-installer = nixpkgs: (nixpkgs.legacyPackages.${system}.nixos [ self.nixosModules.image-installer ]).config.system.build.isoImage;
29+
kexec-installer =
30+
nixpkgs: modules:
31+
(nixpkgs.legacyPackages.${system}.nixos (modules ++ [ self.nixosModules.kexec-installer ]))
32+
.config.system.build.kexecTarball;
33+
netboot-installer =
34+
nixpkgs:
35+
(nixpkgs.legacyPackages.${system}.nixos [ self.nixosModules.netboot-installer ])
36+
.config.system.build.netboot;
37+
image-installer =
38+
nixpkgs:
39+
(nixpkgs.legacyPackages.${system}.nixos [ self.nixosModules.image-installer ])
40+
.config.system.build.isoImage;
2241
in
2342
{
2443
netboot-nixos-unstable = netboot nixos-unstable;
@@ -30,21 +49,40 @@
3049
image-installer-nixos-stable = image-installer nixos-stable;
3150

3251
kexec-installer-nixos-unstable-noninteractive = kexec-installer nixos-unstable [
33-
{
34-
system.kexec-installer.name = "nixos-kexec-installer-noninteractive";
35-
}
52+
{ system.kexec-installer.name = "nixos-kexec-installer-noninteractive"; }
3653
self.nixosModules.noninteractive
3754
];
3855
kexec-installer-nixos-stable-noninteractive = kexec-installer nixos-stable [
39-
{
40-
system.kexec-installer.name = "nixos-kexec-installer-noninteractive";
41-
}
56+
{ system.kexec-installer.name = "nixos-kexec-installer-noninteractive"; }
4257
self.nixosModules.noninteractive
4358
];
4459

4560
netboot-installer-nixos-unstable = netboot-installer nixos-unstable;
4661
netboot-installer-nixos-stable = netboot-installer nixos-stable;
47-
});
62+
}
63+
);
64+
65+
crossPackages = {
66+
x86_64-linux =
67+
let
68+
kexec-installer =
69+
nixpkgs: modules:
70+
(nixpkgs.legacyPackages.x86_64-linux.pkgsCross.riscv64.nixos (
71+
modules
72+
++ [
73+
self.nixosModules.kexec-installer
74+
self.nixosModules.noninteractive
75+
]
76+
)).config.system.build.kexecTarball;
77+
in
78+
{
79+
kexec-installer-nixos-unstable-noninteractive-risc64 = kexec-installer nixos-unstable [ ];
80+
kexec-installer-nixos-stable-noninteractive-risc64 = kexec-installer nixos-stable [ ];
81+
};
82+
};
83+
in
84+
{
85+
packages = nixos-unstable.lib.recursiveUpdate packages crossPackages;
4886
nixosModules = {
4987
kexec-installer = ./nix/kexec-installer/module.nix;
5088
noninteractive = ./nix/noninteractive.nix;
@@ -55,7 +93,12 @@
5593
checks =
5694
let
5795
# re-export the packages as checks
58-
packages = forAllSystems (system: nixos-unstable.lib.mapAttrs' (n: nixos-unstable.lib.nameValuePair "package-${n}") self.packages.${system});
96+
packages = forAllSystems (
97+
system:
98+
nixos-unstable.lib.mapAttrs' (
99+
n: nixos-unstable.lib.nameValuePair "package-${n}"
100+
) self.packages.${system}
101+
);
59102
checks =
60103
let
61104
pkgs = nixos-unstable.legacyPackages.x86_64-linux;
@@ -64,16 +107,13 @@
64107
kexec-installer-unstable = pkgs.callPackage ./nix/kexec-installer/test.nix {
65108
kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-unstable-noninteractive;
66109
};
67-
shellcheck = pkgs.runCommand "shellcheck"
68-
{
69-
nativeBuildInputs = [ pkgs.shellcheck ];
70-
} ''
71-
shellcheck ${(pkgs.nixos [self.nixosModules.kexec-installer]).config.system.build.kexecRun}
110+
shellcheck = pkgs.runCommand "shellcheck" { nativeBuildInputs = [ pkgs.shellcheck ]; } ''
111+
shellcheck ${(pkgs.nixos [ self.nixosModules.kexec-installer ]).config.system.build.kexecRun}
72112
touch $out
73113
'';
74-
kexec-installer-stable = nixos-stable.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix {
75-
kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-stable-noninteractive;
76-
};
114+
kexec-installer-stable =
115+
nixos-stable.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix
116+
{ kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-stable-noninteractive; };
77117
};
78118
in
79119
nixos-unstable.lib.recursiveUpdate packages { x86_64-linux = checks; };

nix/kexec-installer/module.nix

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
{ config, lib, modulesPath, pkgs, ... }:
1+
{
2+
config,
3+
lib,
4+
modulesPath,
5+
pkgs,
6+
...
7+
}:
28
let
3-
restore-network = pkgs.writers.writePython3 "restore-network" { flakeIgnore = [ "E501" ]; }
4-
./restore_routes.py;
9+
restore-network = pkgs.writers.writePython3 "restore-network" {
10+
flakeIgnore = [ "E501" ];
11+
} ./restore_routes.py;
512

613
# does not link with iptables enabled
714
iprouteStatic = pkgs.pkgsStatic.iproute2.override { iptables = null; };
15+
16+
kexec-tools = pkgs.pkgsStatic.kexec-tools.overrideAttrs (old: {
17+
patches = [
18+
(pkgs.fetchpatch {
19+
url = "https://marc.info/?l=kexec&m=166636009110699&q=mbox";
20+
hash = "sha256-wi0/Ajy/Ac+7npKEvDsMzgNhEWhOMFeoUWcpgGrmVDc=";
21+
})
22+
];
23+
meta = old.meta // {
24+
badPlatforms = [ ]; # allow riscv64
25+
};
26+
});
827
in
928
{
1029
imports = [
@@ -27,23 +46,25 @@ in
2746
config = {
2847
# This is a variant of the upstream kexecScript that also allows embedding
2948
# a ssh key.
30-
system.build.kexecRun = pkgs.runCommand "kexec-run" { } ''
31-
install -D -m 0755 ${./kexec-run.sh} $out
49+
system.build.kexecRun =
50+
pkgs.runCommand "kexec-run" { nativeBuildInputs = [ pkgs.buildPackages.shellcheck ]; }
51+
''
52+
install -D -m 0755 ${./kexec-run.sh} $out
3253
33-
sed -i \
34-
-e 's|@init@|${config.system.build.toplevel}/init|' \
35-
-e 's|@kernelParams@|${lib.escapeShellArgs config.boot.kernelParams}|' \
36-
$out
54+
sed -i \
55+
-e 's|@init@|${config.system.build.toplevel}/init|' \
56+
-e 's|@kernelParams@|${lib.escapeShellArgs config.boot.kernelParams}|' \
57+
$out
3758
38-
${pkgs.shellcheck}/bin/shellcheck $out
39-
'';
59+
shellcheck $out
60+
'';
4061

4162
system.build.kexecTarball = pkgs.runCommand "kexec-tarball" { } ''
4263
mkdir kexec $out
4364
cp "${config.system.build.netbootRamdisk}/initrd" kexec/initrd
4465
cp "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}" kexec/bzImage
4566
cp "${config.system.build.kexecRun}" kexec/run
46-
cp "${pkgs.pkgsStatic.kexec-tools}/bin/kexec" kexec/kexec
67+
cp "${kexec-tools}/bin/kexec" kexec/kexec
4768
cp "${iprouteStatic}/bin/ip" kexec/ip
4869
${lib.optionalString (pkgs.hostPlatform == pkgs.buildPlatform) ''
4970
kexec/ip -V

nix/zfs-minimal.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ let
55
# this overrides saves 10MB
66
samba = pkgs.coreutils;
77
};
8+
hasZfs = lib.meta.availableOn pkgs.stdenv.hostPlatform config.boot.zfs.package;
89
in
9-
{
10+
lib.mkIf hasZfs {
1011
services.udev.packages = [ zfs ]; # to hook zvol naming, etc.
1112
# unsure if need this, but in future udev rules could potentially point to systemd services.
1213
systemd.packages = [ zfs ];

0 commit comments

Comments
 (0)