From 0e6c2ac691b1db3f975f8dec0ed2089ec47f5b52 Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Tue, 19 Nov 2024 15:18:53 -0500 Subject: [PATCH] feat: add liveusb generator to flake via nixos-generators (#291) create liveusb --- flake.lock | 38 ++++++++++++++++++++++++++++++++++ flake.nix | 6 ++++++ nix/machines/flake-outputs.nix | 22 +++++++++++++++++++- nix/machines/liveusb.nix | 11 ++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 nix/machines/liveusb.nix diff --git a/flake.lock b/flake.lock index 7d5a2930..95fabf9c 100644 --- a/flake.lock +++ b/flake.lock @@ -60,6 +60,43 @@ "type": "github" } }, + "nixlib": { + "locked": { + "lastModified": 1731200463, + "narHash": "sha256-qDaAweJjdFbVExqs8aG27urUgcgKufkIngHW3Rzustg=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e04234d263750db01c78a412690363dc2226e68a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixos-generators": { + "inputs": { + "nixlib": "nixlib", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729472750, + "narHash": "sha256-s93LPHi5BN7I2xSGNAFWiYb8WRsPvT1LE9ZjZBrpFlg=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "7c60ba4bc8d6aa2ba3e5b0f6ceb9fc07bc261565", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "7c60ba4bc8d6aa2ba3e5b0f6ceb9fc07bc261565", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1725001927, @@ -113,6 +150,7 @@ "fenix": "fenix", "flake-utils": "flake-utils", "home-manager": "home-manager", + "nixos-generators": "nixos-generators", "nixpkgs": "nixpkgs", "nixpkgs-23_11": "nixpkgs-23_11", "nixpkgs-unstable": "nixpkgs-unstable", diff --git a/flake.nix b/flake.nix index 20d82980..00e3d9b1 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,12 @@ url = "github:nix-community/home-manager/release-24.05"; inputs.nixpkgs.follows = "nixpkgs"; }; + # Supports generating liveusbs + nixos-generators = { + url = "github:nix-community/nixos-generators/7c60ba4bc8d6aa2ba3e5b0f6ceb9fc07bc261565"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # Replaces the need to have a git submodule. seekSdk = { url = "github:worldcoin/seek-thermal-sdk"; diff --git a/nix/machines/flake-outputs.nix b/nix/machines/flake-outputs.nix index b53807bc..f3b6477a 100644 --- a/nix/machines/flake-outputs.nix +++ b/nix/machines/flake-outputs.nix @@ -3,7 +3,7 @@ # It gets directly combined with the toplevel flake.nix. { inputs, p, ... }: let - inherit (inputs) nixpkgs home-manager; + inherit (inputs) nixpkgs home-manager nixos-generators; in let # Helper function for all worldcoin NixOS machines. @@ -15,6 +15,7 @@ let }; modules = [ ./${hostname}/configuration.nix + inputs.nixos-generators.nixosModules.all-formats # setup home-manager home-manager.nixosModules.home-manager { @@ -51,4 +52,23 @@ in nixosConfigurations."worldcoin-hil-munich-1" = hilConfig { hostname = "worldcoin-hil-munich-1"; }; + packages.x86_64-linux.liveusb = nixos-generators.nixosGenerate { + system = "x86_64-linux"; + modules = [ + { + # Pin nixpkgs to the flake input, so that the packages installed + # come from the flake inputs.nixpkgs.url. + nix.registry.nixpkgs.flake = nixpkgs; + } + ./liveusb.nix + ]; + format = "raw-efi"; + + # optional arguments: + # explicit nixpkgs and lib: + # pkgs = nixpkgs.legacyPackages.x86_64-linux; + # lib = nixpkgs.legacyPackages.x86_64-linux.lib; + # additional arguments to pass to modules: + # specialArgs = { myExtraArg = "foobar"; }; + }; } diff --git a/nix/machines/liveusb.nix b/nix/machines/liveusb.nix new file mode 100644 index 00000000..1c1c667d --- /dev/null +++ b/nix/machines/liveusb.nix @@ -0,0 +1,11 @@ +{ config, pkgs, modulesPath, ... }: +{ + imports = [ + (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix") + ]; + environment.systemPackages = with pkgs; [ + neovim + parted + usbutils + ]; +}