Skip to content

Commit

Permalink
feat: add recover module, add recover vm
Browse files Browse the repository at this point in the history
  • Loading branch information
klarkc committed Dec 19, 2023
1 parent 55e09c0 commit e114713
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/result
/recover-efi.img
/recover-efi-bios.img
68 changes: 25 additions & 43 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 42 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
microvm.url = "github:astro/microvm.nix";
generators.url = "github:nix-community/nixos-generators";
};

outputs = { self, ... }@inputs:
let
# TODO add cross-platform build
system = "x86_64-linux";
platform = "x86_64";
os = "linux";
system = "${platform}-${os}";
pkgs = import inputs.nixpkgs { inherit system; };
nixosConfigurations = self.packages.${system};
networking = import ./networking.nix;
users = import ./users.nix;
mkSystem = options:
let
let
inherit (inputs.nixpkgs.lib) nixosSystem;
inherit (builtins) removeAttrs;
unmakeOverridable = r: removeAttrs r [
"override"
"overrideDerivation"
];
in nixosSystem (unmakeOverridable options);
systemOptions =
let
inherit (pkgs.lib) makeOverridable;
inherit (pkgs.lib.trivial) id;
in pkgs.lib.makeOverridable id
{
inherit system;
modules =
[
networking
users
];
};
recover = mkSystem systemOptions;
recover-vm = mkSystem systemOptions.override {
modules = systemOptions.modules ++ [
inputs.microvm.nixosModules.microvm
];
inherit (inputs.generators) nixosGenerate;
inherit (builtins) hasAttr;
in
if hasAttr "format" options then
nixosGenerate options
else
nixosSystem options;
recover = mkSystem {
inherit system;
modules = [ ./recover.nix ];
};

recover-efi = mkSystem {
inherit system;
modules = [ ./recover.nix ];
format = "raw-efi";
};

# TODO: find a faster way to run recover in devShell
recover-vm = pkgs.writeShellApplication {
name = "recover-vm";
text = ''
IMG=recover-efi.img
BIOS=recover-efi-bios.img
cp -ui --reflink=auto ${pkgs.OVMF.fd}/FV/OVMF.fd "$BIOS"
chmod a+w "$BIOS"
cp -ui --reflink=auto ${recover-efi}/nixos.img "$IMG"
chmod a+w "$IMG"
qemu-system-${platform} \
-nographic \
-bios "$BIOS" \
-drive file="$IMG",format=raw \
-m 2G
'';
runtimeInputs = with pkgs; [ tree rsync qemu ];
};
in
{
Expand All @@ -47,20 +57,15 @@
};

packages.${system} = {
inherit recover;
inherit recover-efi;
};

devShells.${system}.default =
pkgs.mkShell
{
packages =
let
inherit (recover-vm.config.microvm.runner) qemu;
in
with pkgs;
[
# adds microvm-*
qemu
recover-vm
];

};
Expand Down
1 change: 0 additions & 1 deletion networking.nix

This file was deleted.

7 changes: 7 additions & 0 deletions recover.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ lib, ... }: {
users.users.root.password = "";
users.mutableUsers = false;
networking.hostName = "recover";
boot.loader.systemd-boot.enable = true;
fileSystems."/".device = lib.mkDefault "none";
}
1 change: 0 additions & 1 deletion users.nix

This file was deleted.

0 comments on commit e114713

Please sign in to comment.