From 950e7ae77144f629f1a2bda9b1643815e7afae5f Mon Sep 17 00:00:00 2001 From: phaer Date: Mon, 14 Apr 2025 14:13:36 +0200 Subject: [PATCH] archive nixos-generators in favor of nixos-rebuild build-image See README.md for details --- LICENSE | 21 -- Makefile | 15 - README.md | 393 ++++-------------------- all-formats.nix | 82 ----- checks/is-formatted.nix | 5 - checks/test-all-formats-flake/flake.nix | 58 ---- checks/test-all-formats.nix | 33 -- checks/test-customize-format.nix | 27 -- configuration.nix | 13 - default.nix | 5 - flake.lock | 43 --- flake.nix | 182 ----------- format-module.nix | 26 -- formats/amazon.nix | 8 - formats/azure.nix | 8 - formats/cloudstack.nix | 28 -- formats/do.nix | 8 - formats/docker.nix | 16 - formats/gce.nix | 8 - formats/hyperv.nix | 8 - formats/install-iso-hyperv.nix | 11 - formats/install-iso.nix | 16 - formats/iso.nix | 17 - formats/kexec-bundle.nix | 6 - formats/kexec.nix | 103 ------- formats/kubevirt.nix | 8 - formats/linode.nix | 60 ---- formats/lxc-metadata.nix | 16 - formats/lxc.nix | 16 - formats/openstack.nix | 11 - formats/proxmox-lxc.nix | 13 - formats/proxmox.nix | 7 - formats/qcow-efi.nix | 56 ---- formats/qcow.nix | 39 --- formats/raw-efi.nix | 30 -- formats/raw.nix | 30 -- formats/sd-aarch64-installer.nix | 12 - formats/sd-aarch64.nix | 14 - formats/sd-x86_64.nix | 14 - formats/vagrant-virtualbox.nix | 7 - formats/virtualbox.nix | 8 - formats/vm-bootloader.nix | 7 - formats/vm-nogui.nix | 21 -- formats/vm.nix | 11 - formats/vmware.nix | 8 - garnix.yaml | 5 - lib.nix | 32 -- nixos-generate | 199 ------------ nixos-generate.nix | 30 -- package.nix | 20 -- shell.nix | 5 - 51 files changed, 53 insertions(+), 1766 deletions(-) delete mode 100644 LICENSE delete mode 100644 Makefile delete mode 100644 all-formats.nix delete mode 100644 checks/is-formatted.nix delete mode 100644 checks/test-all-formats-flake/flake.nix delete mode 100644 checks/test-all-formats.nix delete mode 100644 checks/test-customize-format.nix delete mode 100644 configuration.nix delete mode 100644 default.nix delete mode 100644 flake.lock delete mode 100644 flake.nix delete mode 100644 format-module.nix delete mode 100644 formats/amazon.nix delete mode 100644 formats/azure.nix delete mode 100644 formats/cloudstack.nix delete mode 100644 formats/do.nix delete mode 100644 formats/docker.nix delete mode 100644 formats/gce.nix delete mode 100644 formats/hyperv.nix delete mode 100644 formats/install-iso-hyperv.nix delete mode 100644 formats/install-iso.nix delete mode 100644 formats/iso.nix delete mode 100644 formats/kexec-bundle.nix delete mode 100644 formats/kexec.nix delete mode 100644 formats/kubevirt.nix delete mode 100644 formats/linode.nix delete mode 100644 formats/lxc-metadata.nix delete mode 100644 formats/lxc.nix delete mode 100644 formats/openstack.nix delete mode 100644 formats/proxmox-lxc.nix delete mode 100644 formats/proxmox.nix delete mode 100644 formats/qcow-efi.nix delete mode 100644 formats/qcow.nix delete mode 100644 formats/raw-efi.nix delete mode 100644 formats/raw.nix delete mode 100644 formats/sd-aarch64-installer.nix delete mode 100644 formats/sd-aarch64.nix delete mode 100644 formats/sd-x86_64.nix delete mode 100644 formats/vagrant-virtualbox.nix delete mode 100644 formats/virtualbox.nix delete mode 100644 formats/vm-bootloader.nix delete mode 100644 formats/vm-nogui.nix delete mode 100644 formats/vm.nix delete mode 100644 formats/vmware.nix delete mode 100644 garnix.yaml delete mode 100644 lib.nix delete mode 100755 nixos-generate delete mode 100644 nixos-generate.nix delete mode 100644 package.nix delete mode 100644 shell.nix diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3a3af1a5..00000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 lassulus and the nixos-generators contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/Makefile b/Makefile deleted file mode 100644 index 50acd4e2..00000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -PREFIX ?= /usr/local -SHARE ?= $(PREFIX)/share/nixos-generator - -all: - -SOURCES = formats format-module.nix configuration.nix lib.nix nixos-generate.nix - -install: - mkdir -p $(PREFIX)/bin $(SHARE) - sed \ - -e "s|libexec_dir=\".*\"|libexec_dir=\"$(SHARE)\"|" \ - -e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \ - nixos-generate > $(PREFIX)/bin/nixos-generate - chmod 755 $(PREFIX)/bin/nixos-generate - cp -r $(SOURCES) $(SHARE) diff --git a/README.md b/README.md index 702a0009..c326879a 100644 --- a/README.md +++ b/README.md @@ -1,362 +1,75 @@ -# nixos-generators - one config, multiple formats +Starting with NixOS 25.05, most of nixos-generators has been upstreamed into nixpkgs. -The nixos-generators project allows to take the same NixOS configuration, and -generate outputs for different target formats. +So we believe it's time to retire nixos-generators, a good 7 years after its initial commit and after countless built images. +Please let us know if you run into any trouble, such as missing features, during the migration. -Just put your stuff into the configuration.nix and then call one of the image builders. +The main, user-visible difference is the new `nixos-rebuild build-image` command, which replaces the venerable `nixos-generate`. +Check its [manual section](https://nixos.org/manual/nixos/stable/#sec-image-nixos-rebuild-build-image) or below to see how it works. -For example: -``` -nixos-generate -f iso -``` - -or - -``` -nixos-generate -f iso -c /etc/nixos/configuration.nix -``` - -it echoes the path to a iso image, which you then can flash onto an usb-stick -or mount & boot in a virtual machine. - -# Installation +# Usage of `nixos-rebuild build-images` -nixos-generators is part of [nixpkgs](https://search.nixos.org/packages?channel=unstable&show=nixos-generators&from=0&size=50&sort=relevance&type=packages&query=nixos-generator) and can be installed from there. +To build an ISO image, using the new `nixos-rebuild build-image`, run: -nixos-generators can be also installed from source into the user profile like this: - -```console -nix-env -f https://github.com/nix-community/nixos-generators/archive/master.tar.gz -i -``` - -or for flakes users like this: - -```console -nix profile install github:nix-community/nixos-generators ``` - -or run from the nix flake without installing: - +nixos-rebuild build-image --image-variant iso ``` -nix run github:nix-community/nixos-generators -- --help -``` - -## Supported formats -format | description ---- | --- -amazon | Amazon EC2 image -azure | Microsoft azure image (Generation 1 / VHD) -cloudstack | qcow2 image for cloudstack. -do | Digital Ocean image -docker | Docker image (uses systemd to run, probably only works in podman) -gce | Google Compute image -hyperv | Hyper-V Image (Generation 2 / VHDX) -install-iso | Installer ISO -install-iso-hyperv | Installer ISO with enabled hyper-v support -iso | ISO -kexec | kexec tarball (extract to / and run /kexec_nixos) -kexec-bundle | same as before, but it's just an executable -kubevirt | KubeVirt image -linode | Linode image -lxc | create a tarball which is importable as an lxc container, use together with lxc-metadata -lxc-metadata | the necessary metadata for the lxc image to start, usage: `lxc image import $(nixos-generate -f lxc-metadata) $(nixos-generate -f lxc)` -openstack | qcow2 image for openstack -proxmox | [VMA](https://pve.proxmox.com/wiki/VMA) file for proxmox -proxmox-lxc | LXC template for proxmox -qcow | qcow2 image -qcow-efi | qcow2 image with efi support -raw | raw image with bios/mbr. for physical hardware, see the 'raw and raw-efi' section -raw-efi | raw image with efi support. for physical hardware, see the 'raw and raw-efi' section -sd-aarch64 | Like sd-aarch64-installer, but does not use default installer image config. -sd-aarch64-installer | create an installer sd card for aarch64. For cross compiling use `--system aarch64-linux` and read the cross-compile section. -sd-x86_64 | sd card image for x86_64 systems -vagrant-virtualbox | VirtualBox image for [Vagrant](https://www.vagrantup.com/) -virtualbox | virtualbox VM -vm | only used as a qemu-kvm runner -vm-bootloader | same as vm, but uses a real bootloader instead of netbooting -vm-nogui | same as vm, but without a GUI -vmware | VMWare image (VMDK) - -## Usage - -Run `nixos-generate --help` for detailed usage information. - -## select a specific nixpkgs channel +Or to explicitly specifiy the path to your NixOS configuration as well as the nixpkgs checkout to use: -Adds ability to select a specific channel version. - -Example: ``` -nix-shell --command './nixos-generate -f iso -I nixpkgs=channel:nixos-19.09' +NIX_PATH=nixpkgs=../nixpkgs NIXOS_CONFIG="/etc/nixos/nixos-configuration.nix" nixos-rebuild build-image --image-variant iso ``` -## Using a particular nixpkgs +## ...with Flakes -To use features found in a different nixpkgs (for instance the Digital Ocean -image was recently merged in nixpkgs): +To build a simple ISO image, from a `nixosConfigurations.myhost` output of your flake, run: ``` -NIX_PATH=nixpkgs=../nixpkgs nixos-generate -f do -``` - -## Setting the disk image size - -To specify the size of the generated disk image, use the `--disk-size` argument, -specifying the size in megabytes. This is currently supported by the following -formats. If this argument is unspecified it defaults to automatic sizing based -on the generated NixOS build. - -- hyperv -- proxmox -- qcow -- raw-efi -- raw -- vm -- vm-nogui -- vmware - -Example (20GB disk): - -```bash -nixos-generate -c -f --disk-size 20480 +nixos-rebuild build-image --image-variant iso --flake .#myhost ``` -To set the disk size in `flake.nix`, set the `virtualisation.diskSize` module option. - -```nix -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; - nixos-generators = { - url = "github:nix-community/nixos-generators"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - xc = { - url = "github:joerdav/xc"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; +Or, if you prefer to expose an installable similar to the old `nixos-generators.nixosGenerate` nix function, +you could use the right attribute of `system.build.images`: - outputs = { nixpkgs, nixos-generators, xc, ... }: - let - pkgsForSystem = system: import nixpkgs { - inherit system; - overlays = [ - (final: prev: { xc = xc.packages.${system}.xc; }) - ]; - }; - allVMs = [ "x86_64-linux" "aarch64-linux" ]; - forAllVMs = f: nixpkgs.lib.genAttrs allVMs (system: f { - inherit system; - pkgs = pkgsForSystem system; - }); - in - { - packages = forAllVMs ({ system, pkgs }: { - vm = nixos-generators.nixosGenerate { - system = system; - specialArgs = { - pkgs = pkgs; - }; - modules = [ - { - # Pin nixpkgs to the flake input, so that the packages installed - # come from the flake inputs.nixpkgs.url. - nix.registry.nixpkgs.flake = nixpkgs; - # set disk size to to 20G - virtualisation.diskSize = 20 * 1024; - } - # Apply the rest of the config. - ./configuration.nix - ]; - format = "raw"; - }; - }); - }; -} +``` nix +packages.x86_64-linux.myhost-iso = self.nixosConfigurations.myhost.config.system.build.images.iso ``` -## Cross Compiling - -To cross compile nixos images for other architectures you have to configure -`boot.binfmt.emulatedSystems` or `boot.binfmt.registrations` on your host system. - -In your system `configuration.nix`: - -```nix -{ - # Enable binfmt emulation of aarch64-linux. - boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; -} -``` +# Formats of `nixos-generators` -Alternatively, if you want to target other architectures: +The third column describes whether they are supported image variants in `nixos-rebuild build-image`: -```nix -# Define qemu-arm-static source. -let qemu-arm-static = pkgs.stdenv.mkDerivation { - name = "qemu-arm-static"; - src = builtins.fetchurl { - url = "https://github.com/multiarch/qemu-user-static/releases/download/v6.1.0-8/qemu-arm-static"; - sha256 = "06344d77d4f08b3e1b26ff440cb115179c63ca8047afb978602d7922a51231e3"; - }; - dontUnpack = true; - installPhase = "install -D -m 0755 $src $out/bin/qemu-arm-static"; -}; -in { - # Enable binfmt emulation of extra binary formats (armv7l-linux, for exmaple). - boot.binfmt.registrations.arm = { - interpreter = "${qemu-arm-static}/bin/qemu-arm-static"; - magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00''; - mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff''; - }; - - # Define additional settings for nix. - nix.extraOptions = '' - extra-platforms = armv7l-linux - ''; - nix.sandboxPaths = [ "/run/binfmt/arm=${qemu-arm-static}/bin/qemu-arm-static" ]; -} -``` - -For more details on configuring `binfmt`, have a look at: -[binfmt options](https://search.nixos.org/options?channel=unstable&query=boot.binfmt), -[binfmt.nix](https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/binfmt.nix), -[this comment](https://github.com/NixOS/nixpkgs/issues/109661#issuecomment-762629438) and -[clevers qemu-user](https://github.com/cleverca22/nixos-configs/blob/master/qemu.nix). - -Once you've run `nixos-rebuild` with these options, -you can use the `--system` option to create images for other architectures. - -## Using as a nixos-module - -`nixos-generators` can be included as a `NixOS module` into your existing `configuration.nix` making all available formats available through `config.formats` and configurable through `config.formatConfigs`. New formats can be defined by adding a new entry like `config.formatConfigs.my-new-format = {config, ...}: {}`. - -An example `flake.nix` demonstrating this approach is below. - -Images can be built from that flake by running: - -- `nix build .#nixosConfigurations.my-machine.config.formats.vmware` or -- `nix build .#nixosConfigurations.my-machine.config.formats.my-custom-format` or -- `nix build .#nixosConfigurations.my-machine.config.formats.` - -```nix -{ - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - nixos-generators = { - url = "github:nix-community/nixos-generators"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - outputs = { self, nixpkgs, nixos-generators, ... }: { - - # A single nixos config outputting multiple formats. - # Alternatively put this in a configuration.nix. - nixosModules.myFormats = { config, ... }: { - imports = [ - nixos-generators.nixosModules.all-formats - ]; - - nixpkgs.hostPlatform = "x86_64-linux"; - - # customize an existing format - formatConfigs.vmware = { config, ... }: { - services.openssh.enable = true; - }; - - # define a new format - formatConfigs.my-custom-format = { config, modulesPath, ... }: { - imports = [ "${toString modulesPath}/installer/cd-dvd/installation-cd-base.nix" ]; - formatAttr = "isoImage"; - fileExtension = ".iso"; - networking.wireless.networks = { - # ... - }; - }; - }; - - # a machine consuming the module - nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem { - modules = [ self.nixosModules.myFormats ]; - }; - }; -} -``` - -## Using in a Flake - -`nixos-generators` can be included as a `Flake` input and provides -a `nixosGenerate` function for building images as `Flake` outputs. This -approach pins all dependencies and allows for conveniently defining multiple -output types based on one config. - -An example `flake.nix` demonstrating this approach is below. `vmware` or -`virtualbox` images can be built from the same `configuration.nix` by running -`nix build .#vmware` or `nix build .#virtualbox` - -Custom formats can be defined by building a format module (see the -[formats](./formats) directory for examples) and passing it to `nixosGenerate` -via an the `customFormats` argument. `customFormats` should be in the form of -an attribute sets of the form ` = ` and can define -multiple custom formats. `nixosGenerate` will then match against these custom formats as well as the built in ones. - -```nix -{ - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - nixos-generators = { - url = "github:nix-community/nixos-generators"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - outputs = { self, nixpkgs, nixos-generators, ... }: { - packages.x86_64-linux = { - vmware = nixos-generators.nixosGenerate { - system = "x86_64-linux"; - modules = [ - # you can include your own nixos configuration here, i.e. - # ./configuration.nix - ]; - format = "vmware"; - - # 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"; }; - - # you can also define your own custom formats - # customFormats = { "myFormat" = ; ... }; - # format = "myFormat"; - }; - vbox = nixos-generators.nixosGenerate { - system = "x86_64-linux"; - format = "virtualbox"; - }; - }; - }; -} -``` - -## Format-specific notes - -### `raw` and `raw-efi` - -`raw` and `raw-efi` images can be used on physical hardware, but benefit from some tweaks. -* These images are configured to log to the serial console, and not to your display. One workaround for this is to add `boot.kernelParams = [ "console=tty0" ];` to your configuration, which will override the image's default `console=ttyS0`. -* By default, grub will timeout after 1 second. To extend this, set `boot.loader.timeout = 5;` (or longer) -* If boot fails for some reason, you will not get a recovery shell unless the root user is enabled, which you can do by setting a password for them (`users.users.root.password = "something";`, possibly `users.mutableUsers = true;` so you can interactively change the passwords after boot) -* After booting, if you intend to use `nixos-switch`, consider using `nixos-generate-config`. - -### License - -This project is licensed under the [MIT License](LICENSE). - -# FAQ - -#### No space left on device - -This means either /tmp, /run/user/$UID or your TMPFS runs full. Sometimes setting TMPDIR to some other location can help, sometimes /tmp needs to be on a bigger partition (not a tmpfs). +format | description | supported in nixpkgs +--- | --- | --- +amazon | Amazon EC2 image | ✅ +azure | Microsoft azure image (Generation 1 / VHD) | ✅ +cloudstack | qcow2 image for cloudstack. | [Not yet merged](https://github.com/NixOS/nixpkgs/pull/398556) at time of writing. +do | Digital Ocean image | ✅ +docker | Docker image (uses systemd to run, probably only works in podman) +gce | Google Compute image | ✅ +hyperv | Hyper-V Image (Generation 2 / VHDX) | ✅ +install-iso | Installer ISO | ✅ (called `iso-installer`) +install-iso-hyperv | Installer ISO with enabled hyper-v support | use the `hyperv` variant and [customize it](https://nixos.org/manual/nixos/stable/#sec-image-nixos-rebuild-build-image-customize). +iso | ISO | ✅ +kexec | kexec tarball (extract to / and run /kexec_nixos) | ✅ +kexec-bundle | same as before, but it's just an executable | Use the `kexec` variant above. +kubevirt | KubeVirt image | ✅ +linode | Linode image | ✅ +lxc | create a tarball which is importable as an lxc container, use together with lxc-metadata | ✅ +lxc-metadata | the necessary metadata for the lxc image to start, usage: `lxc image import $(nixos-generate -f lxc-metadata) $(nixos-generate -f lxc)` | ✅ +openstack | qcow2 image for openstack | ✅ +proxmox | [VMA](https://pve.proxmox.com/wiki/VMA) file for proxmox | ✅ +proxmox-lxc | LXC template for proxmox | ✅ +qcow | qcow2 image | ✅ +qcow-efi | qcow2 image with efi support | ✅ +raw | raw image with bios/mbr. for physical hardware, see the 'raw and raw-efi' section | ✅ +raw-efi | raw image with efi support. for physical hardware, see the 'raw and raw-efi' section | ✅ +sd-aarch64 | Like sd-aarch64-installer, but does not use default installer image config. | use `sd-card` and set `system` to `aarch64-linux` +sd-aarch64-installer | create an installer sd card for aarch64. For cross compiling use `--system aarch64-linux` and read the cross-compile section. | use `sd-card` and set `system` to `aarch64-linux` +sd-x86_64 | sd card image for x86_64 systems | use `sd-card` and set `system` to `x86_64-linux` +vagrant-virtualbox | VirtualBox image for [Vagrant](https://www.vagrantup.com/)| ✅ +virtualbox | virtualbox VM| ✅ +vm | only used as a qemu-kvm runner | use `nixos-rebuild build-vm` +vm-bootloader | same as vm, but uses a real bootloader instead of netbooting | use `nixos-rebuild build-vm-with-bootloader` +vm-nogui | same as vm, but without a GUI | use `nixos-rebuild build-vm` and [customize it](https://nixos.org/manual/nixos/stable/#sec-image-nixos-rebuild-build-image-customize). +vmware | VMWare image (VMDK) | ✅ diff --git a/all-formats.nix b/all-formats.nix deleted file mode 100644 index b96e4c80..00000000 --- a/all-formats.nix +++ /dev/null @@ -1,82 +0,0 @@ -{ - config, - lib, - pkgs, - extendModules, - ... -}: let - inherit - (lib) - types - ; - # attrs of all format modules from ./formats - formatModules = - lib.flip lib.mapAttrs' (builtins.readDir ./formats) - (fname: type: { - name = lib.removeSuffix ".nix" fname; - value = ./formats + "/${fname}"; - }); - - # function to evaluate a given format to a config - evalFormat = formatModule: - extendModules { - modules = [ - ./format-module.nix - formatModule - ]; - }; - - # evaluated configs for all formats - allConfigs = lib.mapAttrs (formatName: evalFormat) config.formatConfigs; - - # adds an evaluated `config` to the derivation attributes of a format for introspection - exposeConfig = conf: output: - output.overrideAttrs (old: { - passthru.config = conf.config; - }); - - # attrset of formats to be exposed under config.system.formats - formats = lib.flip lib.mapAttrs allConfigs ( - formatName: conf: - exposeConfig conf ( - pkgs.runCommand "${conf.config.system.build.${conf.config.formatAttr}.name}" {} '' - set -efu - target=$(find '${conf.config.system.build.${conf.config.formatAttr}}' -name '*${conf.config.fileExtension}' -xtype f -print -quit) - if [ -z "$target" ]; then - echo "No target file found for ${conf.config.formatAttr} format" - echo "Check the content of this build path: ${conf.config.system.build.${conf.config.formatAttr}}" - exit 1 - fi - mkdir $out - ln -s "$target" "$out/$(basename "$target")" - '' - ) - ); -in { - _file = ./all-formats.nix; - # This deliberate key makes sure this module will be deduplicated - # regardless of the accessor path: either via flake's nixosModule - # or as part of the nixos-generate command. These two store paths - # of the module may differ and hence don't serve as a key - key = "github:nix-community/nixos-generators/all-formats.nix"; - - # declare option for exposing all formats - options.formats = lib.mkOption { - type = lib.types.lazyAttrsOf lib.types.raw; - description = '' - Different target formats generated for this NixOS configuration. - ''; - }; - - options.formatConfigs = lib.mkOption { - type = types.attrsOf types.deferredModule; - }; - - # expose all formats - config.formats = formats; - - # - config.formatConfigs = lib.flip lib.mapAttrs formatModules (name: module: { - imports = [module]; - }); -} diff --git a/checks/is-formatted.nix b/checks/is-formatted.nix deleted file mode 100644 index 43d4e38e..00000000 --- a/checks/is-formatted.nix +++ /dev/null @@ -1,5 +0,0 @@ -{pkgs ? import {}}: -pkgs.runCommand "check-format" {} '' - ${pkgs.alejandra}/bin/alejandra -c ${./.} - touch $out -'' diff --git a/checks/test-all-formats-flake/flake.nix b/checks/test-all-formats-flake/flake.nix deleted file mode 100644 index 45442174..00000000 --- a/checks/test-all-formats-flake/flake.nix +++ /dev/null @@ -1,58 +0,0 @@ -/* -Tests using the all-formats module through a flake. -- Tests if foramts can be customized. -- Tests if new foramts can be added -*/ -{ - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - nixos-generators = { - url = "github:nix-community/nixos-generators"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - outputs = { - self, - nixpkgs, - nixos-generators, - ... - }: { - nixosModules.my-machine = {config, ...}: { - imports = [ - nixos-generators.nixosModules.all-formats - ]; - - nixpkgs.hostPlatform = "x86_64-linux"; - - # customize an existing format - formatConfigs.vmware = {config, ...}: { - services.openssh.enable = false; - }; - - # define a new format - formatConfigs.my-custom-format = { - config, - modulesPath, - ... - }: { - imports = ["${toString modulesPath}/installer/cd-dvd/installation-cd-base.nix"]; - formatAttr = "isoImage"; - fileExtension = ".iso"; - networking.wireless.networks = { - # ... - }; - }; - }; - - nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem { - modules = [self.nixosModules.my-machine]; - }; - - checks.x86_64-linux = { - test-flake_vmware = - self.nixosConfigurations.my-machine.config.formats.vmware; - test-flake_my-custom-format = - self.nixosConfigurations.my-machine.config.formats.my-custom-format; - }; - }; -} diff --git a/checks/test-all-formats.nix b/checks/test-all-formats.nix deleted file mode 100644 index edfcb65f..00000000 --- a/checks/test-all-formats.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ - nixpkgs ? , - system ? builtins.currentSystem, - lib ? import (nixpkgs + /lib), -}: let - nixosSystem = import (nixpkgs + /nixos/lib/eval-config.nix); - - conf = nixosSystem { - inherit system; - modules = [ - ../configuration.nix - ../all-formats.nix - ]; - }; - - exclude = - (lib.optionalAttrs (system != "aarch64-linux") { - sd-aarch64 = true; - sd-aarch64-installer = true; - }) - // (lib.optionalAttrs (system != "x86_64-linux") { - azure = true; - vagrant-virtualbox = true; - virtualbox = true; - vmware = true; - }); - - testedFormats = - lib.filterAttrs - (name: _: ! exclude ? ${name}) - conf.config.formats; -in - testedFormats diff --git a/checks/test-customize-format.nix b/checks/test-customize-format.nix deleted file mode 100644 index b26d65f9..00000000 --- a/checks/test-customize-format.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ - nixpkgs ? , - system ? builtins.currentSystem, - lib ? import (nixpkgs + /lib), -}: let - nixosSystem = import (nixpkgs + /nixos/lib/eval-config.nix); - - userModule1 = {...}: { - formatConfigs.amazon.amazonImage.name = "xyz"; - }; - - userModule2 = {...}: { - formatConfigs.amazon.amazonImage.name = lib.mkForce "custom-name"; - }; - - conf = nixosSystem { - inherit system; - modules = [ - ../configuration.nix - ../all-formats.nix - userModule1 - userModule2 - ]; - }; -in - assert lib.hasInfix "custom-name" "${conf.config.formats.amazon}"; - conf.config.formats.amazon diff --git a/configuration.nix b/configuration.nix deleted file mode 100644 index 9c8dc448..00000000 --- a/configuration.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ config, lib, ... }: -{ - services.sshd.enable = true; - services.nginx.enable = true; - - networking.firewall.allowedTCPPorts = [ 80 ]; - - system.stateVersion = config.system.nixos.release; - - users.users.root.password = "nixos"; - services.openssh.settings.PermitRootLogin = lib.mkOverride 999 "yes"; - services.getty.autologinUser = lib.mkOverride 999 "root"; -} diff --git a/default.nix b/default.nix deleted file mode 100644 index 5e919f79..00000000 --- a/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -(import (builtins.fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz") { - src = ./.; -}) -.defaultNix -.default diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 1b183a03..00000000 --- a/flake.lock +++ /dev/null @@ -1,43 +0,0 @@ -{ - "nodes": { - "nixlib": { - "locked": { - "lastModified": 1736643958, - "narHash": "sha256-tmpqTSWVRJVhpvfSN9KXBvKEXplrwKnSZNAoNPf/S/s=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "1418bc28a52126761c02dd3d89b2d8ca0f521181", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1736657626, - "narHash": "sha256-FWlPMUzp0lkQBdhKlPqtQdqmp+/C+1MBiEytaYfrCTY=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "2f9e2f85cb14a46410a1399aa9ea7ecf433e422e", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixlib": "nixlib", - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 7e402fb8..00000000 --- a/flake.nix +++ /dev/null @@ -1,182 +0,0 @@ -{ - description = "nixos-generators - one config, multiple formats"; - - # Lib dependency - inputs.nixlib.url = "github:nix-community/nixpkgs.lib"; - - # Bin dependency - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - - outputs = { - self, - nixpkgs, - nixlib, - } @ inputs: let - lib = nixpkgs.lib; - - callFlake = flake: let - args = - inputs - // { - nixos-generators = self; - self = subFlake; - }; - subFlake = (import flake).outputs args; - in - subFlake; - - # Ensures a derivation's name can be accessed without evaluating it deeply. - # Prevents `nix flake show` from being very slow. - makeLazyDrv = name: drv: { - inherit name; - inherit - (drv) - drvPath - outPath - outputName - system - ; - type = "derivation"; - }; - in - # Library modules (depend on nixlib) - { - # export all generator formats in ./formats - nixosModules = - { - all-formats = ./all-formats.nix; - } - // (nixlib.lib.mapAttrs' (file: _: { - name = nixlib.lib.removeSuffix ".nix" file; - # The exported module should include the internal format* options - value.imports = [(./formats + "/${file}") ./format-module.nix]; - }) (builtins.readDir ./formats)); - - # example usage in flakes: - # outputs = { self, nixpkgs, nixos-generators, ...}: { - # vmware = nixos-generators.nixosGenerate { - # system = "x86_64-linux"; - # modules = [./configuration.nix]; - # format = "vmware"; - # }; - # } - - nixosGenerate = { - pkgs ? null, - lib ? nixpkgs.lib, - nixosSystem ? nixpkgs.lib.nixosSystem, - format, - system ? null, - specialArgs ? {}, - modules ? [], - customFormats ? {}, - }: let - extraFormats = - lib.mapAttrs' ( - name: value: - lib.nameValuePair - name - { - imports = [ - value - ./format-module.nix - ]; - } - ) - customFormats; - formatModule = builtins.getAttr format (self.nixosModules // extraFormats); - image = nixosSystem { - inherit pkgs specialArgs; - system = - if system != null - then system - else pkgs.system; - lib = - if lib != null - then lib - else pkgs.lib; - modules = - [ - formatModule - ] - ++ modules; - }; - in - image.config.system.build.${image.config.formatAttr}; - } - // - # Binary and Devshell outputs (depend on nixpkgs) - ( - let - forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "x86_64-darwin" "i686-linux" "aarch64-linux" "aarch64-darwin"]; - in { - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra); - - packages = forAllSystems (system: let - pkgs = nixpkgs.legacyPackages."${system}"; - in rec { - default = nixos-generate; - nixos-generate = pkgs.callPackage ./package.nix {}; - }); - - checks = - lib.recursiveUpdate - (callFlake ./checks/test-all-formats-flake/flake.nix).checks - ( - lib.genAttrs [ - "x86_64-linux" - # We currently don't have kvm support on our builder - #"aarch64-linux" - ] - ( - system: let - allFormats = import ./checks/test-all-formats.nix { - inherit nixpkgs system; - }; - test-customize-format = import ./checks/test-customize-format.nix { - inherit nixpkgs system; - }; - in - lib.mapAttrs makeLazyDrv ( - { - inherit - (self.packages.${system}) - nixos-generate - ; - - inherit test-customize-format; - - is-formatted = import ./checks/is-formatted.nix { - pkgs = nixpkgs.legacyPackages.${system}; - }; - } - // allFormats - ) - ) - ); - - devShells = forAllSystems (system: let - pkgs = nixpkgs.legacyPackages."${system}"; - in { - default = pkgs.mkShell { - buildInputs = with pkgs; [jq coreutils findutils]; - }; - }); - - # Make it runnable with `nix run` - apps = forAllSystems (system: let - nixos-generate = { - type = "app"; - program = "${self.packages."${system}".nixos-generate}/bin/nixos-generate"; - }; - in { - inherit nixos-generate; - - # Nix >= 2.7 flake output schema uses `apps..default` instead - # of `defaultApp.` to signify the default app (the thing that - # gets run with `nix run . -- `) - default = nixos-generate; - }); - } - ); -} diff --git a/format-module.nix b/format-module.nix deleted file mode 100644 index fb58ef5c..00000000 --- a/format-module.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ - lib, - modulesPath, - ... -}: { - _file = ./format-module.nix; - # This deliberate key makes sure this module will be deduplicated - # regardless of the accessor path: either via flake's nixosModule - # or as part of the nixos-generate command. These two store paths - # of the module may differ and hence don't serve as a key - key = "github:nix-community/nixos-generators/format-module.nix"; - - imports = ["${modulesPath}/virtualisation/disk-size-option.nix"]; - - options = { - fileExtension = lib.mkOption { - type = lib.types.str; - description = "Declare the path of the wanted file in the output directory"; - default = ""; - }; - formatAttr = lib.mkOption { - type = lib.types.str; - description = "Declare the default attribute to build"; - }; - }; -} diff --git a/formats/amazon.nix b/formats/amazon.nix deleted file mode 100644 index 85f9da1a..00000000 --- a/formats/amazon.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/../maintainers/scripts/ec2/amazon-image.nix" - ]; - - formatAttr = "amazonImage"; - fileExtension = ".vhd"; -} diff --git a/formats/azure.nix b/formats/azure.nix deleted file mode 100644 index 84d0c3b6..00000000 --- a/formats/azure.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/azure-image.nix" - ]; - - formatAttr = "azureImage"; - fileExtension = ".vhd"; -} diff --git a/formats/cloudstack.nix b/formats/cloudstack.nix deleted file mode 100644 index 8d0c985b..00000000 --- a/formats/cloudstack.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/cloudstack-config.nix" - ]; - - fileSystems."/".fsType = lib.mkDefault "ext4"; - - system.build.cloudstackImage = import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - inherit (config.virtualisation) diskSize; - format = "qcow2"; - configFile = - pkgs.writeText "configuration.nix" - '' - { - imports = [ "${toString modulesPath}/virtualisation/cloudstack-config.nix" ]; - } - ''; - }; - - formatAttr = "cloudstackImage"; -} diff --git a/formats/do.nix b/formats/do.nix deleted file mode 100644 index 5d6aee87..00000000 --- a/formats/do.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/digital-ocean-image.nix" - ]; - - formatAttr = "digitalOceanImage"; - fileExtension = ".qcow2.gz"; -} diff --git a/formats/docker.nix b/formats/docker.nix deleted file mode 100644 index 2c74acb3..00000000 --- a/formats/docker.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - modulesPath, - lib, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/docker-image.nix" - ]; - - boot.loader.grub.enable = lib.mkForce false; - boot.loader.systemd-boot.enable = lib.mkForce false; - services.journald.console = "/dev/console"; - - formatAttr = "tarball"; - fileExtension = ".tar.xz"; -} diff --git a/formats/gce.nix b/formats/gce.nix deleted file mode 100644 index 4a4b03d4..00000000 --- a/formats/gce.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/google-compute-image.nix" - ]; - - formatAttr = "googleComputeImage"; - fileExtension = ".raw.tar.gz"; -} diff --git a/formats/hyperv.nix b/formats/hyperv.nix deleted file mode 100644 index 340898dd..00000000 --- a/formats/hyperv.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/hyperv-image.nix" - ]; - - formatAttr = "hypervImage"; - fileExtension = ".vhdx"; -} diff --git a/formats/install-iso-hyperv.nix b/formats/install-iso-hyperv.nix deleted file mode 100644 index 8ae73ce2..00000000 --- a/formats/install-iso-hyperv.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - lib, - ... -}: { - imports = [ - ./install-iso.nix - ]; - - systemd.services.wpa_supplicant.wantedBy = lib.mkOverride 40 []; - virtualisation.hypervGuest.enable = true; -} diff --git a/formats/install-iso.nix b/formats/install-iso.nix deleted file mode 100644 index e55cdeb7..00000000 --- a/formats/install-iso.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - lib, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/installer/cd-dvd/installation-cd-base.nix" - ]; - - # override installation-cd-base and enable wpa and sshd start at boot - systemd.services.wpa_supplicant.wantedBy = lib.mkForce ["multi-user.target"]; - systemd.services.sshd.wantedBy = lib.mkForce ["multi-user.target"]; - - formatAttr = "isoImage"; - fileExtension = ".iso"; -} diff --git a/formats/iso.nix b/formats/iso.nix deleted file mode 100644 index 1bcb2c68..00000000 --- a/formats/iso.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/installer/cd-dvd/iso-image.nix" - ]; - - # EFI booting - isoImage.makeEfiBootable = true; - - # USB booting - isoImage.makeUsbBootable = true; - - formatAttr = "isoImage"; - fileExtension = ".iso"; -} diff --git a/formats/kexec-bundle.nix b/formats/kexec-bundle.nix deleted file mode 100644 index 9bf67b9d..00000000 --- a/formats/kexec-bundle.nix +++ /dev/null @@ -1,6 +0,0 @@ -{lib, ...}: { - imports = [./kexec.nix]; - - formatAttr = lib.mkForce "kexec_bundle"; - fileExtension = lib.mkForce "-kexec_bundle"; -} diff --git a/formats/kexec.nix b/formats/kexec.nix deleted file mode 100644 index afdacef6..00000000 --- a/formats/kexec.nix +++ /dev/null @@ -1,103 +0,0 @@ -{ - config, - pkgs, - lib, - modulesPath, - options, - ... -}: let - inherit (import ../lib.nix {inherit lib options;}) maybe; -in { - imports = [ - "${toString modulesPath}/installer/netboot/netboot-minimal.nix" - ]; - - system.build = rec { - image = pkgs.runCommand "image" {buildInputs = [pkgs.nukeReferences];} '' - mkdir $out - cp ${config.system.build.kernel}/${config.system.boot.loader.kernelFile} $out/kernel - cp ${config.system.build.netbootRamdisk}/initrd $out/initrd - echo "init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}" > $out/cmdline - nuke-refs $out/kernel - ''; - - kexec_script = pkgs.writeTextFile { - executable = true; - name = "kexec-nixos"; - text = '' - #!${pkgs.stdenv.shell} - export PATH=${pkgs.kexec-tools}/bin:${pkgs.cpio}/bin:$PATH - set -x - set -e - cd $(mktemp -d) - pwd - mkdir initrd - pushd initrd - if [ -e /ssh_pubkey ]; then - cat /ssh_pubkey >> authorized_keys - fi - find -type f | cpio -o -H newc | gzip -9 > ../extra.gz - popd - cat ${image}/initrd extra.gz > final.gz - - kexec -l ${image}/kernel --initrd=final.gz --append="init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}" - sync - echo "executing kernel, filesystems will be improperly umounted" - kexec -e - ''; - }; - - kexec_tarball = maybe.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" { - storeContents = [ - { - object = config.system.build.kexec_script; - symlink = "/kexec_nixos"; - } - ]; - contents = []; - }); - - kexec_tarball_self_extract_script = pkgs.writeTextFile { - executable = true; - name = "kexec-nixos"; - text = '' - #!/bin/sh - set -eu - ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ { print NR + 1; exit 0; }' $0` - - tail -n+$ARCHIVE $0 | tar xJ -C / - /kexec_nixos - - exit 1 - - __ARCHIVE_BELOW__ - ''; - }; - - kexec_bundle = pkgs.runCommand "kexec_bundle" {} '' - cat \ - ${kexec_tarball_self_extract_script} \ - ${config.system.build.kexec_tarball}/tarball/nixos-system-${config.system.build.kexec_tarball.system}.tar.xz \ - > $out - chmod +x $out - ''; - }; - - boot.loader.grub.enable = lib.mkForce false; - boot.loader.systemd-boot.enable = lib.mkForce false; - boot.kernelParams = [ - "console=ttyS0,115200" # allows certain forms of remote access, if the hardware is setup right - "panic=30" - "boot.panic_on_fail" # reboot the machine upon fatal boot issues - ]; - systemd.services.sshd.wantedBy = lib.mkForce ["multi-user.target"]; - networking.hostName = lib.mkDefault "kexec"; - - formatAttr = "kexec_tarball"; - fileExtension = ".tar.xz"; - - boot.initrd.postMountCommands = '' - mkdir -p /mnt-root/root/.ssh/ - cp /authorized_keys /mnt-root/root/.ssh/ - ''; -} diff --git a/formats/kubevirt.nix b/formats/kubevirt.nix deleted file mode 100644 index a49b2652..00000000 --- a/formats/kubevirt.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/kubevirt.nix" - ]; - - formatAttr = "kubevirtImage"; - fileExtension = ".qcow2"; -} diff --git a/formats/linode.nix b/formats/linode.nix deleted file mode 100644 index 6bdd222f..00000000 --- a/formats/linode.nix +++ /dev/null @@ -1,60 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/linode-image.nix" - ]; - - formatAttr = "linodeImage"; - fileExtension = ".img.gz"; - - system.build.linodeImage = lib.mkForce (import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - partitionTableType = "none"; - format = "raw"; - postVM = '' - ${pkgs.pigz}/bin/pigz -9 $out/nixos.img - ''; - }); - - # Enable LISH and Linode booting w/ GRUB - boot = { - growPartition = true; - - loader = { - grub = { - fsIdentifier = "label"; - - # Link /boot/grub2 to /boot/grub: - extraInstallCommands = '' - ${pkgs.coreutils}/bin/ln -fs /boot/grub /boot/grub2 - ''; - - # Remove GRUB splash image: - splashImage = null; - }; - }; - }; - - # Hardware option detected by nixos-generate-config: - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; - - # Install diagnostic tools for Linode support: - environment.systemPackages = with pkgs; [ - linode-cli - ]; - - networking = { - enableIPv6 = true; - interfaces.eth0 = { - tempAddress = "disabled"; - useDHCP = true; - }; - }; - - services.qemuGuest.enable = true; -} diff --git a/formats/lxc-metadata.nix b/formats/lxc-metadata.nix deleted file mode 100644 index cdb9f80d..00000000 --- a/formats/lxc-metadata.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - config, - lib, - modulesPath, - pkgs, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/lxc-container.nix" - ]; - - boot.loader.grub.enable = lib.mkForce false; - boot.loader.systemd-boot.enable = lib.mkForce false; - formatAttr = "metadata"; - fileExtension = ".tar.xz"; -} diff --git a/formats/lxc.nix b/formats/lxc.nix deleted file mode 100644 index 42191c77..00000000 --- a/formats/lxc.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - config, - pkgs, - lib, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/lxc-container.nix" - ]; - - boot.loader.grub.enable = lib.mkForce false; - boot.loader.systemd-boot.enable = lib.mkForce false; - formatAttr = "tarball"; - fileExtension = ".tar.xz"; -} diff --git a/formats/openstack.nix b/formats/openstack.nix deleted file mode 100644 index 91bd098e..00000000 --- a/formats/openstack.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - modulesPath, - ... -}: -{ - imports = [ - "${toString modulesPath}/../maintainers/scripts/openstack/openstack-image.nix" - ]; - formatAttr = "openstackImage"; - fileExtension = ".qcow2"; -} diff --git a/formats/proxmox-lxc.nix b/formats/proxmox-lxc.nix deleted file mode 100644 index b3389bbd..00000000 --- a/formats/proxmox-lxc.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - lib, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/proxmox-lxc.nix" - ]; - boot.loader.grub.enable = lib.mkForce false; - boot.loader.systemd-boot.enable = lib.mkForce false; - formatAttr = "tarball"; - fileExtension = ".tar.xz"; -} diff --git a/formats/proxmox.nix b/formats/proxmox.nix deleted file mode 100644 index 429bf046..00000000 --- a/formats/proxmox.nix +++ /dev/null @@ -1,7 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/proxmox-image.nix" - ]; - formatAttr = "VMA"; - fileExtension = ".vma.zst"; -} diff --git a/formats/qcow-efi.nix b/formats/qcow-efi.nix deleted file mode 100644 index a64b744a..00000000 --- a/formats/qcow-efi.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - # for virtio kernel drivers - imports = [ - "${toString modulesPath}/profiles/qemu-guest.nix" - ]; - - options = { - boot = { - consoles = lib.mkOption { - default = - ["ttyS0"] - ++ (lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") - ++ (lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200"); - description = "Kernel console boot flags to pass to boot.kernelParams"; - example = ["ttyS2,115200"]; - }; - }; - }; - - config = { - fileSystems."/" = { - device = "/dev/disk/by-label/nixos"; - autoResize = true; - fsType = "ext4"; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-label/ESP"; - fsType = "vfat"; - }; - - boot.growPartition = true; - boot.kernelParams = map (c: "console=${c}") config.boot.consoles; - boot.loader.grub.device = "nodev"; - - boot.loader.grub.efiSupport = true; - boot.loader.grub.efiInstallAsRemovable = true; - boot.loader.timeout = 0; - - system.build.qcow-efi = import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - inherit (config.virtualisation) diskSize; - format = "qcow2"; - partitionTableType = "efi"; - }; - - formatAttr = "qcow-efi"; - fileExtension = ".qcow2"; - }; -} diff --git a/formats/qcow.nix b/formats/qcow.nix deleted file mode 100644 index 411bee2e..00000000 --- a/formats/qcow.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - # for virtio kernel drivers - imports = [ - "${toString modulesPath}/profiles/qemu-guest.nix" - ]; - - fileSystems."/" = { - device = "/dev/disk/by-label/nixos"; - autoResize = true; - fsType = "ext4"; - }; - - boot.growPartition = true; - boot.kernelParams = ["console=ttyS0"]; - boot.loader.grub.device = - if (pkgs.stdenv.system == "x86_64-linux") - then (lib.mkDefault "/dev/vda") - else (lib.mkDefault "nodev"); - - boot.loader.grub.efiSupport = lib.mkIf (pkgs.stdenv.system != "x86_64-linux") (lib.mkDefault true); - boot.loader.grub.efiInstallAsRemovable = lib.mkIf (pkgs.stdenv.system != "x86_64-linux") (lib.mkDefault true); - boot.loader.timeout = 0; - - system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - inherit (config.virtualisation) diskSize; - format = "qcow2"; - partitionTableType = "hybrid"; - }; - - formatAttr = "qcow"; - fileExtension = ".qcow2"; -} diff --git a/formats/raw-efi.nix b/formats/raw-efi.nix deleted file mode 100644 index 0f933361..00000000 --- a/formats/raw-efi.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - config, - lib, - options, - pkgs, - modulesPath, - ... -}: let - inherit (import ../lib.nix {inherit lib options;}) maybe; -in { - imports = [./raw.nix]; - - boot.loader.grub = { - device = "nodev"; - efiSupport = true; - efiInstallAsRemovable = true; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-label/ESP"; - fsType = "vfat"; - }; - - system.build.raw = maybe.mkOverride 99 (import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - partitionTableType = "efi"; - inherit (config.virtualisation) diskSize; - format = "raw"; - }); -} diff --git a/formats/raw.nix b/formats/raw.nix deleted file mode 100644 index bdfa5490..00000000 --- a/formats/raw.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - fileSystems."/" = { - device = "/dev/disk/by-label/nixos"; - autoResize = true; - fsType = "ext4"; - }; - - boot = { - growPartition = true; - kernelParams = ["console=ttyS0"]; - loader.grub.device = lib.mkDefault "/dev/vda"; - loader.timeout = lib.mkDefault 0; - initrd.availableKernelModules = ["uas"]; - }; - - system.build.raw = import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - inherit (config.virtualisation) diskSize; - format = "raw"; - }; - - formatAttr = "raw"; - fileExtension = ".img"; -} diff --git a/formats/sd-aarch64-installer.nix b/formats/sd-aarch64-installer.nix deleted file mode 100644 index ab3a53e2..00000000 --- a/formats/sd-aarch64-installer.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ - config, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/installer/sd-card/sd-image-aarch64-installer.nix" - ]; - - formatAttr = "sdImage"; - fileExtension = ".img.*"; -} diff --git a/formats/sd-aarch64.nix b/formats/sd-aarch64.nix deleted file mode 100644 index 5dcf7c1a..00000000 --- a/formats/sd-aarch64.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/installer/sd-card/sd-image-aarch64.nix" - ]; - - formatAttr = "sdImage"; - fileExtension = ".img.*"; -} diff --git a/formats/sd-x86_64.nix b/formats/sd-x86_64.nix deleted file mode 100644 index 3608feaf..00000000 --- a/formats/sd-x86_64.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/installer/sd-card/sd-image-x86_64.nix" - ]; - - formatAttr = "sdImage"; - fileExtension = ".img.*"; -} diff --git a/formats/vagrant-virtualbox.nix b/formats/vagrant-virtualbox.nix deleted file mode 100644 index 53311c08..00000000 --- a/formats/vagrant-virtualbox.nix +++ /dev/null @@ -1,7 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/vagrant-virtualbox-image.nix" - ]; - - formatAttr = "vagrantVirtualbox"; -} diff --git a/formats/virtualbox.nix b/formats/virtualbox.nix deleted file mode 100644 index f318422a..00000000 --- a/formats/virtualbox.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/virtualbox-image.nix" - ]; - - formatAttr = "virtualBoxOVA"; - fileExtension = ".ova"; -} diff --git a/formats/vm-bootloader.nix b/formats/vm-bootloader.nix deleted file mode 100644 index a8d6388a..00000000 --- a/formats/vm-bootloader.nix +++ /dev/null @@ -1,7 +0,0 @@ -{modulesPath, ...}: { - imports = [ - ./vm.nix - ]; - - virtualisation.useBootLoader = true; -} diff --git a/formats/vm-nogui.nix b/formats/vm-nogui.nix deleted file mode 100644 index fda8bc9b..00000000 --- a/formats/vm-nogui.nix +++ /dev/null @@ -1,21 +0,0 @@ -{pkgs, ...}: let - resize = pkgs.writeScriptBin "resize" '' - if [ -e /dev/tty ]; then - old=$(stty -g) - stty raw -echo min 0 time 5 - printf '\033[18t' > /dev/tty - IFS=';t' read -r _ rows cols _ < /dev/tty - stty "$old" - stty cols "$cols" rows "$rows" - fi - ''; # https://unix.stackexchange.com/questions/16578/resizable-serial-console-window -in { - imports = [ - ./vm.nix - ]; - virtualisation.graphics = false; - virtualisation.qemu.options = ["-serial mon:stdio"]; - - environment.systemPackages = [resize]; - environment.loginShellInit = "${resize}/bin/resize"; -} diff --git a/formats/vm.nix b/formats/vm.nix deleted file mode 100644 index ab3e5dc6..00000000 --- a/formats/vm.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - lib, - modulesPath, - ... -}: { - imports = [ - "${toString modulesPath}/virtualisation/qemu-vm.nix" - ]; - virtualisation.diskSize = lib.mkDefault (2 * 1024); - formatAttr = "vm"; -} diff --git a/formats/vmware.nix b/formats/vmware.nix deleted file mode 100644 index df8b584d..00000000 --- a/formats/vmware.nix +++ /dev/null @@ -1,8 +0,0 @@ -{modulesPath, ...}: { - imports = [ - "${toString modulesPath}/virtualisation/vmware-image.nix" - ]; - - formatAttr = "vmwareImage"; - fileExtension = ".vmdk"; -} diff --git a/garnix.yaml b/garnix.yaml deleted file mode 100644 index 23990ffb..00000000 --- a/garnix.yaml +++ /dev/null @@ -1,5 +0,0 @@ -builds: - include: - - '*.x86_64-linux.*' - - 'packages.aarch64-darwin.*' - - nixosConfigurations.* diff --git a/lib.nix b/lib.nix deleted file mode 100644 index 83e365e0..00000000 --- a/lib.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ - lib, - options, -}: let - # See https://github.com/NixOS/nixpkgs/commit/ccb85a53b6a496984073227fd8c4d4c58889f421 - # This commit changed the type of `system.build` from a lazy attribute set to - # a submodule. Prior to this commit, it doesn't make sense to qualify, e.g. - # the `system.build.kexec_tarball` definition with `lib.mkForce`, as this - # would result in setting the (final/resolved) value of - # `system.build.kexec_tarball` to something like: - # { - # _type = "override"; - # content = <...>; - # priority = 50; - # } - # However, since this commit, `system.build.kexec_tarball` *must* be defined - # using `lib.mkForce`; otherwise, Nix bails out with a complaint about - # `system.build.kexec_tarball` being defined in multiple locations. - systemBuildIsSubmodule = options.system.build.type.name == "submodule"; - - optionsLookSane = lib.hasAttrByPath ["system" "build" "type" "name"] options; -in - assert (lib.assertMsg optionsLookSane "`options' must be the NixOS module `options' argument"); { - maybe = - { - mkForce = lib.id; - mkOverride = _: lib.id; - } - // (lib.optionalAttrs systemBuildIsSubmodule { - inherit (lib) mkForce mkOverride; - }); - } diff --git a/nixos-generate b/nixos-generate deleted file mode 100755 index 05072a5f..00000000 --- a/nixos-generate +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -## Configuration - -readonly libexec_dir="${0%/*}" -readonly format_dir=$libexec_dir/formats - -configuration=${NIXOS_CONFIG:-$libexec_dir/configuration.nix} -flake_uri= -flake_attr= -format_path= -target_system= -cores= -run= -nix_args=( - "$libexec_dir/nixos-generate.nix" -) -has_outlink=false -nix_build_args=() - -## Functions - -showUsage() { - cat <&2 - exit 1 -} - -# TODO: Is there a better name for this? -fixDiskSizeFormat() { - # If the arg is an int, pass it back unchanged: - if [[ "$1" =~ ^[0-9][0-9]*$ ]]; then - echo "$1" - return - fi - - # If the arg is _not_ an int, we'll assume it's a string. - # Therefore, we'll make sure it's wrapped in quotes, so its eval'd as a string by Nix: - echo "\"$1\"" -} - -## Main ## - -while [[ $# -gt 0 ]]; do - case "$1" in - -c | --configuration) - configuration=$2 - shift - ;; - --flake) - # Note: The reason I'm using awk over cut is because cutting with an - # out-of-bounds field will return the last in-bound field instead of empty - # string. - flake="$(echo "$2" | awk -F'#' '{ print $1; }')" - - flake_uri="$(nix flake metadata --json -- "$flake" | jq -r .url)" - flake_attr="$(echo "$2" | awk -F'#' '{ print $2; }')" - shift - ;; - --cores) - cores=$2 - shift - ;; - --disk-size) - # Note: make sure integers are not incorrectly interpreted as strings by Nix: - nix_build_args+=("--arg" "diskSize" "$(fixDiskSizeFormat "$2")") - shift - ;; - --special-arg) - nix_build_args+=("--argstr" "$2" "$3") - shift 2 - ;; - --option) - nix_args+=("$1" "$2" "$3") - shift 2 - ;; - -f | --format) - format_path=$format_dir/$2.nix - shift - ;; - --format-path) - format_path=$2 - shift - ;; - --help) - showUsage - exit - ;; - --list) - listFormats - exit - ;; - --run) - run=1 - # default to the VM format - if [[ -z $format_path ]]; then - format_path=$format_dir/vm.nix - fi - ;; - --show-trace) - nix_args+=(--show-trace) - ;; - --system) - target_system=$2 - shift - ;; - -I) - nix_args+=(-I "$2") - shift - ;; - -o | --out-link) - nix_build_args+=(--out-link "$2") - has_outlink=true - shift - ;; - *) - abort "unknown option $1" - ;; - esac - shift -done - -if ! $has_outlink; then - nix_build_args+=(--no-link) -fi - -if [[ -z $format_path ]]; then - abort "missing format. use --help for more details" -fi - -if [[ ! -f $format_path ]]; then - abort "format file not found: $format_path" -fi - -nix_args+=(--argstr formatConfig "$(realpath "$format_path")") - -if [[ -z "$flake_uri" ]]; then - nix_args+=( - -I "nixos-config=$configuration" - ) -else - nix_args+=( - --argstr flakeUri "$flake_uri" - --argstr flakeAttr "${flake_attr:-"$(hostname)"}" - ) -fi - -if [[ -n $target_system ]]; then - nix_args+=(--argstr system "$target_system") -fi - -if [[ -n $cores ]]; then - nix_args+=(--cores "$cores") -fi - -formatAttr=$(nix-instantiate "${nix_args[@]}" --eval --json -A config.formatAttr | jq -r .) -fileExtension=$(nix-instantiate "${nix_args[@]}" --eval --json -A config.fileExtension | jq -r .) - -out=$(nix build --extra-experimental-features nix-command -L --print-out-paths --file "${nix_args[@]}" "${nix_build_args[@]}" "config.system.build.$formatAttr") - -if [[ -z $run ]]; then - # show the first file, ignoring nix-support - find "$out" -name "*$fileExtension" -xtype f -print -quit -else - runner=$(find "$out"/bin -type l -print -quit) - exec "$runner" -fi diff --git a/nixos-generate.nix b/nixos-generate.nix deleted file mode 100644 index 9e18ffae..00000000 --- a/nixos-generate.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - nixpkgs ? , - configuration ? , - system ? builtins.currentSystem, - diskSize ? "auto", - formatConfig, - flakeUri ? null, - flakeAttr ? null, -}: let - module = import ./format-module.nix; - - # Will only get evaluated when used, so no worries - flake = builtins.getFlake flakeUri; - flakeSystem = flake.outputs.packages."${system}".nixosConfigurations."${flakeAttr}" or flake.outputs.nixosConfigurations."${flakeAttr}"; -in - if flakeUri != null - then - flakeSystem.extendModules { - modules = [module formatConfig]; - } - else - import "${toString nixpkgs}/nixos/lib/eval-config.nix" { - inherit system; - modules = [ - {virtualisation.diskSize = diskSize;} - module - formatConfig - configuration - ]; - } diff --git a/package.nix b/package.nix deleted file mode 100644 index 23c54c49..00000000 --- a/package.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - stdenv, - makeWrapper, - jq, - coreutils, - findutils, - lib, - gawk, -}: -stdenv.mkDerivation { - name = "nixos-generate"; - src = ./.; - meta.description = "Collection of image builders"; - nativeBuildInputs = [makeWrapper]; - installFlags = ["PREFIX=$(out)"]; - postFixup = '' - wrapProgram $out/bin/nixos-generate \ - --prefix PATH : ${lib.makeBinPath [jq coreutils findutils gawk]} - ''; -} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index bfaa8870..00000000 --- a/shell.nix +++ /dev/null @@ -1,5 +0,0 @@ -(import (builtins.fetchTarball https://github.com/edolstra/flake-compat/archive/master.tar.gz) { - src = ./.; -}) -.shellNix -.default