mirror of
https://github.com/nix-community/nixos-generators.git
synced 2024-11-22 01:52:05 +03:00
Merge pull request #375 from phaer/virtualisation-diskSize
Use virtualisation.diskSize instead of specialArg
This commit is contained in:
commit
9f101f45c5
13
README.md
13
README.md
@ -122,7 +122,7 @@ Example (20GB disk):
|
||||
nixos-generate -c <your_config.nix> -f <format> --disk-size 20480
|
||||
```
|
||||
|
||||
To set the disk size in `flake.nix`, set `diskSize` in the `specialArgs` argument of the `nixosGenerate` function.
|
||||
To set the disk size in `flake.nix`, set the `virtualisation.diskSize` module option.
|
||||
|
||||
```nix
|
||||
{
|
||||
@ -158,12 +158,15 @@ To set the disk size in `flake.nix`, set `diskSize` in the `specialArgs` argumen
|
||||
system = system;
|
||||
specialArgs = {
|
||||
pkgs = pkgs;
|
||||
diskSize = 20 * 1024;
|
||||
};
|
||||
modules = [
|
||||
# Pin nixpkgs to the flake input, so that the packages installed
|
||||
# come from the flake inputs.nixpkgs.url.
|
||||
({ ... }: { nix.registry.nixpkgs.flake = nixpkgs; })
|
||||
{
|
||||
# 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
|
||||
];
|
||||
|
@ -30,25 +30,27 @@
|
||||
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;
|
||||
});
|
||||
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")"
|
||||
''
|
||||
)
|
||||
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;
|
||||
|
@ -1,7 +1,4 @@
|
||||
{
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
{lib, ...}: {
|
||||
services.sshd.enable = true;
|
||||
services.nginx.enable = true;
|
||||
|
||||
|
10
flake.lock
10
flake.lock
@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixlib": {
|
||||
"locked": {
|
||||
"lastModified": 1729386149,
|
||||
"lastModified": 1729990941,
|
||||
"narHash": "sha256-hUP9oxmnOmNnKcDOf5Y55HQ+NnoT0+bLWHLQWLLw9Ks=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "cce4521b6df014e79a7b7afc58c703ed683c916e",
|
||||
"rev": "7d68864343650322045894951602d6e82b5296d7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -17,11 +17,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1729265718,
|
||||
"narHash": "sha256-4HQI+6LsO3kpWTYuVGIzhJs1cetFcwT7quWCk/6rqeo=",
|
||||
"lastModified": 1730170245,
|
||||
"narHash": "sha256-PRq4vJjDa+m1mNwkV9H7zVzMhuMqsHJrTGx0iJZ0e0w=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ccc0c2126893dd20963580b6478d1a10a4512185",
|
||||
"rev": "30c9efeef01e2ad4880bff6a01a61dd99536b3c9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1,4 +1,8 @@
|
||||
{lib, ...}: rec {
|
||||
{
|
||||
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
|
||||
@ -6,6 +10,8 @@
|
||||
# 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;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
system.build.cloudstackImage = import "${toString modulesPath}/../lib/make-disk-image.nix" {
|
||||
inherit lib config pkgs;
|
||||
diskSize = 8192;
|
||||
inherit (config.virtualisation) diskSize;
|
||||
format = "qcow2";
|
||||
configFile =
|
||||
pkgs.writeText "configuration.nix"
|
||||
|
@ -1,19 +1,8 @@
|
||||
{
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
diskSize = specialArgs.diskSize or "auto";
|
||||
in {
|
||||
{modulesPath, ...}: {
|
||||
imports = [
|
||||
"${toString modulesPath}/virtualisation/hyperv-image.nix"
|
||||
];
|
||||
|
||||
hyperv.baseImageSize =
|
||||
if diskSize == "auto" then "auto"
|
||||
else lib.strings.toIntBase10 diskSize;
|
||||
|
||||
formatAttr = "hypervImage";
|
||||
fileExtension = ".vhdx";
|
||||
}
|
||||
|
@ -13,20 +13,20 @@ in {
|
||||
];
|
||||
|
||||
system.build = rec {
|
||||
image = pkgs.runCommand "image" { buildInputs = [ pkgs.nukeReferences ]; } ''
|
||||
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.kexectools}/bin:${pkgs.cpio}/bin:$PATH
|
||||
export PATH=${pkgs.kexec-tools}/bin:${pkgs.cpio}/bin:$PATH
|
||||
set -x
|
||||
set -e
|
||||
cd $(mktemp -d)
|
||||
@ -44,7 +44,7 @@ in {
|
||||
sync
|
||||
echo "executing kernel, filesystems will be improperly umounted"
|
||||
kexec -e
|
||||
'';
|
||||
'';
|
||||
};
|
||||
|
||||
kexec_tarball = maybe.mkForce (pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {
|
||||
|
@ -1,4 +1,8 @@
|
||||
{lib, modulesPath, ...}: {
|
||||
{
|
||||
lib,
|
||||
modulesPath,
|
||||
...
|
||||
}: {
|
||||
imports = [
|
||||
"${toString modulesPath}/virtualisation/proxmox-lxc.nix"
|
||||
];
|
||||
|
@ -1,14 +1,7 @@
|
||||
{
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
...
|
||||
}: {
|
||||
{modulesPath, ...}: {
|
||||
imports = [
|
||||
"${toString modulesPath}/virtualisation/proxmox-image.nix"
|
||||
];
|
||||
|
||||
proxmox.qemuConf.diskSize = specialArgs.diskSize or "auto";
|
||||
|
||||
formatAttr = "VMA";
|
||||
fileExtension = ".vma.zst";
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
{ config, lib, pkgs, modulesPath, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
...
|
||||
}: {
|
||||
# for virtio kernel drivers
|
||||
imports = [
|
||||
"${toString modulesPath}/profiles/qemu-guest.nix"
|
||||
@ -8,17 +13,12 @@
|
||||
options = {
|
||||
boot = {
|
||||
consoles = lib.mkOption {
|
||||
default = [ "ttyS0" ] ++
|
||||
(lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++
|
||||
(lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200");
|
||||
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" ];
|
||||
};
|
||||
|
||||
diskSize = lib.mkOption {
|
||||
default = "auto";
|
||||
description = "The disk size in megabytes of the system disk image.";
|
||||
type = with lib.types; oneOf [ ints.positive (enum [ "auto" ])];
|
||||
example = ["ttyS2,115200"];
|
||||
};
|
||||
};
|
||||
};
|
||||
@ -45,7 +45,7 @@
|
||||
|
||||
system.build.qcow-efi = import "${toString modulesPath}/../lib/make-disk-image.nix" {
|
||||
inherit lib config pkgs;
|
||||
diskSize = config.boot.diskSize;
|
||||
inherit (config.virtualisation) diskSize;
|
||||
format = "qcow2";
|
||||
partitionTableType = "efi";
|
||||
};
|
||||
@ -54,4 +54,3 @@
|
||||
fileExtension = ".qcow2";
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
lib,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
...
|
||||
}: {
|
||||
# for virtio kernel drivers
|
||||
@ -30,7 +29,7 @@
|
||||
|
||||
system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" {
|
||||
inherit lib config pkgs;
|
||||
diskSize = specialArgs.diskSize or "auto";
|
||||
inherit (config.virtualisation) diskSize;
|
||||
format = "qcow2";
|
||||
partitionTableType = "hybrid";
|
||||
};
|
||||
|
@ -4,7 +4,6 @@
|
||||
options,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
...
|
||||
}: let
|
||||
inherit (import ../lib.nix {inherit lib options;}) maybe;
|
||||
@ -25,7 +24,7 @@ in {
|
||||
system.build.raw = maybe.mkOverride 99 (import "${toString modulesPath}/../lib/make-disk-image.nix" {
|
||||
inherit lib config pkgs;
|
||||
partitionTableType = "efi";
|
||||
diskSize = specialArgs.diskSize or "auto";
|
||||
inherit (config.virtualisation) diskSize;
|
||||
format = "raw";
|
||||
});
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
lib,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
...
|
||||
}: {
|
||||
fileSystems."/" = {
|
||||
@ -22,7 +21,7 @@
|
||||
|
||||
system.build.raw = import "${toString modulesPath}/../lib/make-disk-image.nix" {
|
||||
inherit lib config pkgs;
|
||||
diskSize = specialArgs.diskSize or "auto";
|
||||
inherit (config.virtualisation) diskSize;
|
||||
format = "raw";
|
||||
};
|
||||
|
||||
|
@ -1,16 +1,11 @@
|
||||
{
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
lib,
|
||||
modulesPath,
|
||||
...
|
||||
}: let
|
||||
diskSize = specialArgs.diskSize or "auto";
|
||||
in {
|
||||
}: {
|
||||
imports = [
|
||||
"${toString modulesPath}/virtualisation/qemu-vm.nix"
|
||||
];
|
||||
|
||||
virtualisation.diskSize = lib.mkIf (diskSize != "auto") (lib.strings.toIntBase10 diskSize);
|
||||
|
||||
virtualisation.diskSize = lib.mkDefault (2 * 1024);
|
||||
formatAttr = "vm";
|
||||
}
|
||||
|
@ -1,19 +1,8 @@
|
||||
{
|
||||
modulesPath,
|
||||
specialArgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
diskSize = specialArgs.diskSize or "auto";
|
||||
in {
|
||||
{modulesPath, ...}: {
|
||||
imports = [
|
||||
"${toString modulesPath}/virtualisation/vmware-image.nix"
|
||||
];
|
||||
|
||||
vmware.baseImageSize =
|
||||
if diskSize == "auto" then "auto"
|
||||
else lib.strings.toIntBase10 diskSize;
|
||||
|
||||
formatAttr = "vmwareImage";
|
||||
fileExtension = ".vmdk";
|
||||
}
|
||||
|
@ -21,10 +21,8 @@ in
|
||||
else
|
||||
import "${toString nixpkgs}/nixos/lib/eval-config.nix" {
|
||||
inherit system;
|
||||
specialArgs = {
|
||||
diskSize = diskSize;
|
||||
};
|
||||
modules = [
|
||||
{virtualisation.diskSize = diskSize;}
|
||||
module
|
||||
formatConfig
|
||||
configuration
|
||||
|
Loading…
Reference in New Issue
Block a user