diff --git a/.gitignore b/.gitignore index c4a847d..eda69f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /result +/recover-efi.img +/recover-efi-bios.img diff --git a/flake.lock b/flake.lock index ec089a5..67b03df 100644 --- a/flake.lock +++ b/flake.lock @@ -1,54 +1,51 @@ { "nodes": { - "flake-utils": { + "generators": { "inputs": { - "systems": "systems" + "nixlib": "nixlib", + "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "lastModified": 1687183443, + "narHash": "sha256-foX4pkph2AwUdJL3JURa7IHog+YRIheZ54vwHwxqwhU=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "09140f23f5ffce828db4ef040070bdd9595b1f3a", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "nix-community", + "repo": "nixos-generators", "type": "github" } }, - "microvm": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - }, + "nixlib": { "locked": { - "lastModified": 1686962046, - "narHash": "sha256-QE5I3/ONKubR2lvLwUbsS4OaOPc9gTburw9OBcYfgdw=", - "owner": "astro", - "repo": "microvm.nix", - "rev": "484e6e2209a0ead8ea43a9a79b193026026becfc", + "lastModified": 1687049841, + "narHash": "sha256-FBNZQfWtA7bb/rwk92mfiWc85x4hXta2OAouDqO5W8w=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "908af6d1fa3643c5818ea45aa92b21d6385fbbe5", "type": "github" }, "original": { - "owner": "astro", - "repo": "microvm.nix", + "owner": "nix-community", + "repo": "nixpkgs.lib", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1686412476, - "narHash": "sha256-inl9SVk6o5h75XKC79qrDCAobTD1Jxh6kVYTZKHzewA=", - "owner": "nixos", + "lastModified": 1687103638, + "narHash": "sha256-dwy/TK6Db5W7ivcgmcxUykhFwodIg0jrRzOFt7H5NUc=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "21951114383770f96ae528d0ae68824557768e81", + "rev": "91430887645a0953568da2f3e9a3a3bb0a0378ac", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixos-unstable", + "owner": "NixOS", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } @@ -71,24 +68,9 @@ }, "root": { "inputs": { - "microvm": "microvm", + "generators": "generators", "nixpkgs": "nixpkgs_2" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 2cdb779..9fcfd20 100644 --- a/flake.nix +++ b/flake.nix @@ -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 { @@ -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 ]; }; diff --git a/networking.nix b/networking.nix deleted file mode 100644 index c9f3eb8..0000000 --- a/networking.nix +++ /dev/null @@ -1 +0,0 @@ -{ networking.hostName = "klarkc-os"; } diff --git a/recover.nix b/recover.nix new file mode 100644 index 0000000..35c1cd0 --- /dev/null +++ b/recover.nix @@ -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"; +} diff --git a/users.nix b/users.nix deleted file mode 100644 index 60ad8c6..0000000 --- a/users.nix +++ /dev/null @@ -1 +0,0 @@ -{ users.users.root.password = "1234"; }