-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
89 lines (89 loc) · 2.53 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
description = "NixOS-based rescue drive";
inputs.nixos.url = "nixpkgs/nixos-22.11";
outputs = {
self,
nixos,
}: let
system = "x86_64-linux";
in {
nixosModules = rec {
default = rescue;
rescue.imports = [./configuration.nix];
};
packages.x86_64-linux = rec {
default = rescue.config.system.build.isoImage;
rescue = nixos.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.default
./hardware-configuration.nix
];
};
vm =
(nixos.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.default
./hardware-configuration.nix
(nixos + "/nixos/modules/virtualisation/qemu-vm.nix")
(nixos + "/nixos/modules/profiles/qemu-guest.nix")
({
config,
pkgs,
...
}: let
isoimage = pkgs.runCommandLocal "rescue.iso" {} ''
set -Eeuf -o pipefail
set -x
rescue=${self.outputs.packages.x86_64-linux.default}/iso/rescue.iso
if [ "${toString config.isoImage.compressImage}" ]; then
${pkgs.zstd}/bin/zstd --decompress --keep --stdout "''${rescue}.zst" > $out
else
ln -s "$rescue" $out
fi
'';
in {
virtualisation = {
memorySize = 2048;
graphics = false;
useDefaultFilesystems = false;
diskImage = "/dev/null";
fileSystems."/" = {
fsType = "tmpfs";
options = ["mode=0755"];
};
forwardPorts = [
{
from = "host";
host.port = 2222;
guest.port = 22;
}
];
qemu = {
drives = [
{
file = "${isoimage}";
driveExtraOpts = {
media = "cdrom";
format = "raw";
readonly = "on";
};
}
];
};
};
})
];
})
.config
.system
.build
.vm;
};
apps.x86_64-linux.default = {
type = "app";
program = "${self.outputs.packages.x86_64-linux.vm}/bin/run-rescue-vm";
};
};
}