mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 21:25:30 +03:00
treewide: format all inactive Nix files
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRev0128fbb0a5
result/bin/apply-formatting $NIXPKGS_PATH
This commit is contained in:
parent
0128fbb0a5
commit
d9d87c5196
21586 changed files with 712147 additions and 434007 deletions
|
@ -24,77 +24,81 @@
|
|||
# presumably because zed doesn’t get an event saying it’s partition grew,
|
||||
# whereas it can and does get an event saying the whole disk it is on is
|
||||
# now larger.
|
||||
{ lib
|
||||
, pkgs
|
||||
, # The NixOS configuration to be installed onto the disk image.
|
||||
config
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
# The NixOS configuration to be installed onto the disk image.
|
||||
config,
|
||||
|
||||
, # size of the FAT boot disk, in megabytes.
|
||||
bootSize ? 1024
|
||||
# size of the FAT boot disk, in megabytes.
|
||||
bootSize ? 1024,
|
||||
|
||||
, # The size of the root disk, in megabytes.
|
||||
rootSize ? 2048
|
||||
# The size of the root disk, in megabytes.
|
||||
rootSize ? 2048,
|
||||
|
||||
, # The name of the ZFS pool
|
||||
rootPoolName ? "tank"
|
||||
# The name of the ZFS pool
|
||||
rootPoolName ? "tank",
|
||||
|
||||
, # zpool properties
|
||||
# zpool properties
|
||||
rootPoolProperties ? {
|
||||
autoexpand = "on";
|
||||
}
|
||||
, # pool-wide filesystem properties
|
||||
},
|
||||
# pool-wide filesystem properties
|
||||
rootPoolFilesystemProperties ? {
|
||||
acltype = "posixacl";
|
||||
atime = "off";
|
||||
compression = "on";
|
||||
mountpoint = "legacy";
|
||||
xattr = "sa";
|
||||
}
|
||||
},
|
||||
|
||||
, # datasets, with per-attribute options:
|
||||
# datasets, with per-attribute options:
|
||||
# mount: (optional) mount point in the VM
|
||||
# properties: (optional) ZFS properties on the dataset, like filesystemProperties
|
||||
# Notes:
|
||||
# 1. datasets will be created from shorter to longer names as a simple topo-sort
|
||||
# 2. you should define a root's dataset's mount for `/`
|
||||
datasets ? { }
|
||||
datasets ? { },
|
||||
|
||||
, # The files and directories to be placed in the target file system.
|
||||
# The files and directories to be placed in the target file system.
|
||||
# This is a list of attribute sets {source, target} where `source'
|
||||
# is the file system object (regular file or directory) to be
|
||||
# grafted in the file system at path `target'.
|
||||
contents ? []
|
||||
contents ? [ ],
|
||||
|
||||
, # The initial NixOS configuration file to be copied to
|
||||
# The initial NixOS configuration file to be copied to
|
||||
# /etc/nixos/configuration.nix. This configuration will be embedded
|
||||
# inside a configuration which includes the described ZFS fileSystems.
|
||||
configFile ? null
|
||||
configFile ? null,
|
||||
|
||||
, # Shell code executed after the VM has finished.
|
||||
postVM ? ""
|
||||
# Shell code executed after the VM has finished.
|
||||
postVM ? "",
|
||||
|
||||
, # Guest memory size
|
||||
memSize ? 1024
|
||||
# Guest memory size
|
||||
memSize ? 1024,
|
||||
|
||||
, name ? "nixos-disk-image"
|
||||
name ? "nixos-disk-image",
|
||||
|
||||
, # Disk image format, one of qcow2, qcow2-compressed, vdi, vpc, raw.
|
||||
format ? "raw"
|
||||
# Disk image format, one of qcow2, qcow2-compressed, vdi, vpc, raw.
|
||||
format ? "raw",
|
||||
|
||||
, # Include a copy of Nixpkgs in the disk image
|
||||
includeChannel ? true
|
||||
# Include a copy of Nixpkgs in the disk image
|
||||
includeChannel ? true,
|
||||
}:
|
||||
let
|
||||
formatOpt = if format == "qcow2-compressed" then "qcow2" else format;
|
||||
|
||||
compress = lib.optionalString (format == "qcow2-compressed") "-c";
|
||||
|
||||
filenameSuffix = "." + {
|
||||
qcow2 = "qcow2";
|
||||
vdi = "vdi";
|
||||
vpc = "vhd";
|
||||
raw = "img";
|
||||
}.${formatOpt} or formatOpt;
|
||||
filenameSuffix =
|
||||
"."
|
||||
+ {
|
||||
qcow2 = "qcow2";
|
||||
vdi = "vdi";
|
||||
vpc = "vhd";
|
||||
raw = "img";
|
||||
}
|
||||
.${formatOpt} or formatOpt;
|
||||
bootFilename = "nixos.boot${filenameSuffix}";
|
||||
rootFilename = "nixos.root${filenameSuffix}";
|
||||
|
||||
|
@ -103,27 +107,32 @@ let
|
|||
let
|
||||
nixpkgs = lib.cleanSource pkgs.path;
|
||||
in
|
||||
pkgs.runCommand "nixos-${config.system.nixos.version}" {} ''
|
||||
mkdir -p $out
|
||||
cp -prd ${nixpkgs.outPath} $out/nixos
|
||||
chmod -R u+w $out/nixos
|
||||
if [ ! -e $out/nixos/nixpkgs ]; then
|
||||
ln -s . $out/nixos/nixpkgs
|
||||
fi
|
||||
rm -rf $out/nixos/.git
|
||||
echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix
|
||||
'';
|
||||
pkgs.runCommand "nixos-${config.system.nixos.version}" { } ''
|
||||
mkdir -p $out
|
||||
cp -prd ${nixpkgs.outPath} $out/nixos
|
||||
chmod -R u+w $out/nixos
|
||||
if [ ! -e $out/nixos/nixpkgs ]; then
|
||||
ln -s . $out/nixos/nixpkgs
|
||||
fi
|
||||
rm -rf $out/nixos/.git
|
||||
echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix
|
||||
'';
|
||||
|
||||
closureInfo = pkgs.closureInfo {
|
||||
rootPaths = [ config.system.build.toplevel ]
|
||||
++ (lib.optional includeChannel channelSources);
|
||||
rootPaths = [ config.system.build.toplevel ] ++ (lib.optional includeChannel channelSources);
|
||||
};
|
||||
|
||||
modulesTree = pkgs.aggregateModules
|
||||
(with config.boot.kernelPackages; [ kernel zfs ]);
|
||||
modulesTree = pkgs.aggregateModules (
|
||||
with config.boot.kernelPackages;
|
||||
[
|
||||
kernel
|
||||
zfs
|
||||
]
|
||||
);
|
||||
|
||||
tools = lib.makeBinPath (
|
||||
with pkgs; [
|
||||
with pkgs;
|
||||
[
|
||||
nixos-enter
|
||||
config.system.build.nixos-install
|
||||
dosfstools
|
||||
|
@ -136,92 +145,101 @@ let
|
|||
]
|
||||
);
|
||||
|
||||
hasDefinedMount = disk: ((disk.mount or null) != null);
|
||||
hasDefinedMount = disk: ((disk.mount or null) != null);
|
||||
|
||||
stringifyProperties = prefix: properties: lib.concatStringsSep " \\\n" (
|
||||
lib.mapAttrsToList
|
||||
(
|
||||
stringifyProperties =
|
||||
prefix: properties:
|
||||
lib.concatStringsSep " \\\n" (
|
||||
lib.mapAttrsToList (
|
||||
property: value: "${prefix} ${lib.escapeShellArg property}=${lib.escapeShellArg value}"
|
||||
)
|
||||
properties
|
||||
);
|
||||
) properties
|
||||
);
|
||||
|
||||
createDatasets =
|
||||
let
|
||||
datasetlist = lib.mapAttrsToList lib.nameValuePair datasets;
|
||||
sorted = lib.sort (left: right: (lib.stringLength left.name) < (lib.stringLength right.name)) datasetlist;
|
||||
cmd = { name, value }:
|
||||
sorted = lib.sort (
|
||||
left: right: (lib.stringLength left.name) < (lib.stringLength right.name)
|
||||
) datasetlist;
|
||||
cmd =
|
||||
{ name, value }:
|
||||
let
|
||||
properties = stringifyProperties "-o" (value.properties or {});
|
||||
properties = stringifyProperties "-o" (value.properties or { });
|
||||
in
|
||||
"zfs create -p ${properties} ${name}";
|
||||
"zfs create -p ${properties} ${name}";
|
||||
in
|
||||
lib.concatMapStringsSep "\n" cmd sorted;
|
||||
lib.concatMapStringsSep "\n" cmd sorted;
|
||||
|
||||
mountDatasets =
|
||||
let
|
||||
datasetlist = lib.mapAttrsToList lib.nameValuePair datasets;
|
||||
mounts = lib.filter ({ value, ... }: hasDefinedMount value) datasetlist;
|
||||
sorted = lib.sort (left: right: (lib.stringLength left.value.mount) < (lib.stringLength right.value.mount)) mounts;
|
||||
cmd = { name, value }:
|
||||
sorted = lib.sort (
|
||||
left: right: (lib.stringLength left.value.mount) < (lib.stringLength right.value.mount)
|
||||
) mounts;
|
||||
cmd =
|
||||
{ name, value }:
|
||||
''
|
||||
mkdir -p /mnt${lib.escapeShellArg value.mount}
|
||||
mount -t zfs ${name} /mnt${lib.escapeShellArg value.mount}
|
||||
'';
|
||||
in
|
||||
lib.concatMapStringsSep "\n" cmd sorted;
|
||||
lib.concatMapStringsSep "\n" cmd sorted;
|
||||
|
||||
unmountDatasets =
|
||||
let
|
||||
datasetlist = lib.mapAttrsToList lib.nameValuePair datasets;
|
||||
mounts = lib.filter ({ value, ... }: hasDefinedMount value) datasetlist;
|
||||
sorted = lib.sort (left: right: (lib.stringLength left.value.mount) > (lib.stringLength right.value.mount)) mounts;
|
||||
cmd = { name, value }:
|
||||
sorted = lib.sort (
|
||||
left: right: (lib.stringLength left.value.mount) > (lib.stringLength right.value.mount)
|
||||
) mounts;
|
||||
cmd =
|
||||
{ name, value }:
|
||||
''
|
||||
umount /mnt${lib.escapeShellArg value.mount}
|
||||
'';
|
||||
in
|
||||
lib.concatMapStringsSep "\n" cmd sorted;
|
||||
|
||||
lib.concatMapStringsSep "\n" cmd sorted;
|
||||
|
||||
fileSystemsCfgFile =
|
||||
let
|
||||
mountable = lib.filterAttrs (_: value: hasDefinedMount value) datasets;
|
||||
in
|
||||
pkgs.runCommand "filesystem-config.nix" {
|
||||
buildInputs = with pkgs; [ jq nixpkgs-fmt ];
|
||||
pkgs.runCommand "filesystem-config.nix"
|
||||
{
|
||||
buildInputs = with pkgs; [
|
||||
jq
|
||||
nixpkgs-fmt
|
||||
];
|
||||
filesystems = builtins.toJSON {
|
||||
fileSystems = lib.mapAttrs'
|
||||
(
|
||||
dataset: attrs:
|
||||
{
|
||||
name = attrs.mount;
|
||||
value = {
|
||||
fsType = "zfs";
|
||||
device = "${dataset}";
|
||||
};
|
||||
}
|
||||
)
|
||||
mountable;
|
||||
fileSystems = lib.mapAttrs' (dataset: attrs: {
|
||||
name = attrs.mount;
|
||||
value = {
|
||||
fsType = "zfs";
|
||||
device = "${dataset}";
|
||||
};
|
||||
}) mountable;
|
||||
};
|
||||
passAsFile = [ "filesystems" ];
|
||||
} ''
|
||||
(
|
||||
echo "builtins.fromJSON '''"
|
||||
jq . < "$filesystemsPath"
|
||||
echo "'''"
|
||||
) > $out
|
||||
}
|
||||
''
|
||||
(
|
||||
echo "builtins.fromJSON '''"
|
||||
jq . < "$filesystemsPath"
|
||||
echo "'''"
|
||||
) > $out
|
||||
|
||||
nixpkgs-fmt $out
|
||||
'';
|
||||
nixpkgs-fmt $out
|
||||
'';
|
||||
|
||||
mergedConfig =
|
||||
if configFile == null
|
||||
then fileSystemsCfgFile
|
||||
if configFile == null then
|
||||
fileSystemsCfgFile
|
||||
else
|
||||
pkgs.runCommand "configuration.nix" {
|
||||
buildInputs = with pkgs; [ nixpkgs-fmt ];
|
||||
}
|
||||
pkgs.runCommand "configuration.nix"
|
||||
{
|
||||
buildInputs = with pkgs; [ nixpkgs-fmt ];
|
||||
}
|
||||
''
|
||||
(
|
||||
echo '{ imports = ['
|
||||
|
@ -233,98 +251,109 @@ let
|
|||
nixpkgs-fmt $out
|
||||
'';
|
||||
|
||||
image = (
|
||||
pkgs.vmTools.override {
|
||||
rootModules =
|
||||
[ "zfs" "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ] ++
|
||||
(pkgs.lib.optional pkgs.stdenv.hostPlatform.isx86 "rtc_cmos");
|
||||
image =
|
||||
(pkgs.vmTools.override {
|
||||
rootModules = [
|
||||
"zfs"
|
||||
"9p"
|
||||
"9pnet_virtio"
|
||||
"virtio_pci"
|
||||
"virtio_blk"
|
||||
] ++ (pkgs.lib.optional pkgs.stdenv.hostPlatform.isx86 "rtc_cmos");
|
||||
kernel = modulesTree;
|
||||
}
|
||||
).runInLinuxVM (
|
||||
pkgs.runCommand name
|
||||
{
|
||||
QEMU_OPTS = "-drive file=$bootDiskImage,if=virtio,cache=unsafe,werror=report"
|
||||
+ " -drive file=$rootDiskImage,if=virtio,cache=unsafe,werror=report";
|
||||
inherit memSize;
|
||||
preVM = ''
|
||||
PATH=$PATH:${pkgs.qemu_kvm}/bin
|
||||
mkdir $out
|
||||
bootDiskImage=boot.raw
|
||||
qemu-img create -f raw $bootDiskImage ${toString bootSize}M
|
||||
}).runInLinuxVM
|
||||
(
|
||||
pkgs.runCommand name
|
||||
{
|
||||
QEMU_OPTS =
|
||||
"-drive file=$bootDiskImage,if=virtio,cache=unsafe,werror=report"
|
||||
+ " -drive file=$rootDiskImage,if=virtio,cache=unsafe,werror=report";
|
||||
inherit memSize;
|
||||
preVM = ''
|
||||
PATH=$PATH:${pkgs.qemu_kvm}/bin
|
||||
mkdir $out
|
||||
bootDiskImage=boot.raw
|
||||
qemu-img create -f raw $bootDiskImage ${toString bootSize}M
|
||||
|
||||
rootDiskImage=root.raw
|
||||
qemu-img create -f raw $rootDiskImage ${toString rootSize}M
|
||||
'';
|
||||
rootDiskImage=root.raw
|
||||
qemu-img create -f raw $rootDiskImage ${toString rootSize}M
|
||||
'';
|
||||
|
||||
postVM = ''
|
||||
${if formatOpt == "raw" then ''
|
||||
mv $bootDiskImage $out/${bootFilename}
|
||||
mv $rootDiskImage $out/${rootFilename}
|
||||
'' else ''
|
||||
${pkgs.qemu_kvm}/bin/qemu-img convert -f raw -O ${formatOpt} ${compress} $bootDiskImage $out/${bootFilename}
|
||||
${pkgs.qemu_kvm}/bin/qemu-img convert -f raw -O ${formatOpt} ${compress} $rootDiskImage $out/${rootFilename}
|
||||
''}
|
||||
bootDiskImage=$out/${bootFilename}
|
||||
rootDiskImage=$out/${rootFilename}
|
||||
set -x
|
||||
${postVM}
|
||||
'';
|
||||
} ''
|
||||
export PATH=${tools}:$PATH
|
||||
set -x
|
||||
postVM = ''
|
||||
${
|
||||
if formatOpt == "raw" then
|
||||
''
|
||||
mv $bootDiskImage $out/${bootFilename}
|
||||
mv $rootDiskImage $out/${rootFilename}
|
||||
''
|
||||
else
|
||||
''
|
||||
${pkgs.qemu_kvm}/bin/qemu-img convert -f raw -O ${formatOpt} ${compress} $bootDiskImage $out/${bootFilename}
|
||||
${pkgs.qemu_kvm}/bin/qemu-img convert -f raw -O ${formatOpt} ${compress} $rootDiskImage $out/${rootFilename}
|
||||
''
|
||||
}
|
||||
bootDiskImage=$out/${bootFilename}
|
||||
rootDiskImage=$out/${rootFilename}
|
||||
set -x
|
||||
${postVM}
|
||||
'';
|
||||
}
|
||||
''
|
||||
export PATH=${tools}:$PATH
|
||||
set -x
|
||||
|
||||
cp -sv /dev/vda /dev/sda
|
||||
cp -sv /dev/vda /dev/xvda
|
||||
cp -sv /dev/vda /dev/sda
|
||||
cp -sv /dev/vda /dev/xvda
|
||||
|
||||
parted --script /dev/vda -- \
|
||||
mklabel gpt \
|
||||
mkpart no-fs 1MiB 2MiB \
|
||||
set 1 bios_grub on \
|
||||
align-check optimal 1 \
|
||||
mkpart ESP fat32 2MiB -1MiB \
|
||||
align-check optimal 2 \
|
||||
print
|
||||
parted --script /dev/vda -- \
|
||||
mklabel gpt \
|
||||
mkpart no-fs 1MiB 2MiB \
|
||||
set 1 bios_grub on \
|
||||
align-check optimal 1 \
|
||||
mkpart ESP fat32 2MiB -1MiB \
|
||||
align-check optimal 2 \
|
||||
print
|
||||
|
||||
sfdisk --dump /dev/vda
|
||||
sfdisk --dump /dev/vda
|
||||
|
||||
|
||||
zpool create \
|
||||
${stringifyProperties " -o" rootPoolProperties} \
|
||||
${stringifyProperties " -O" rootPoolFilesystemProperties} \
|
||||
${rootPoolName} /dev/vdb
|
||||
parted --script /dev/vdb -- print
|
||||
zpool create \
|
||||
${stringifyProperties " -o" rootPoolProperties} \
|
||||
${stringifyProperties " -O" rootPoolFilesystemProperties} \
|
||||
${rootPoolName} /dev/vdb
|
||||
parted --script /dev/vdb -- print
|
||||
|
||||
${createDatasets}
|
||||
${mountDatasets}
|
||||
${createDatasets}
|
||||
${mountDatasets}
|
||||
|
||||
mkdir -p /mnt/boot
|
||||
mkfs.vfat -n ESP /dev/vda2
|
||||
mount /dev/vda2 /mnt/boot
|
||||
mkdir -p /mnt/boot
|
||||
mkfs.vfat -n ESP /dev/vda2
|
||||
mount /dev/vda2 /mnt/boot
|
||||
|
||||
mount
|
||||
mount
|
||||
|
||||
# Install a configuration.nix
|
||||
mkdir -p /mnt/etc/nixos
|
||||
# `cat` so it is mutable on the fs
|
||||
cat ${mergedConfig} > /mnt/etc/nixos/configuration.nix
|
||||
# Install a configuration.nix
|
||||
mkdir -p /mnt/etc/nixos
|
||||
# `cat` so it is mutable on the fs
|
||||
cat ${mergedConfig} > /mnt/etc/nixos/configuration.nix
|
||||
|
||||
export NIX_STATE_DIR=$TMPDIR/state
|
||||
nix-store --load-db < ${closureInfo}/registration
|
||||
export NIX_STATE_DIR=$TMPDIR/state
|
||||
nix-store --load-db < ${closureInfo}/registration
|
||||
|
||||
nixos-install \
|
||||
--root /mnt \
|
||||
--no-root-passwd \
|
||||
--system ${config.system.build.toplevel} \
|
||||
--substituters "" \
|
||||
${lib.optionalString includeChannel ''--channel ${channelSources}''}
|
||||
nixos-install \
|
||||
--root /mnt \
|
||||
--no-root-passwd \
|
||||
--system ${config.system.build.toplevel} \
|
||||
--substituters "" \
|
||||
${lib.optionalString includeChannel ''--channel ${channelSources}''}
|
||||
|
||||
df -h
|
||||
df -h
|
||||
|
||||
umount /mnt/boot
|
||||
${unmountDatasets}
|
||||
umount /mnt/boot
|
||||
${unmountDatasets}
|
||||
|
||||
zpool export ${rootPoolName}
|
||||
''
|
||||
);
|
||||
zpool export ${rootPoolName}
|
||||
''
|
||||
);
|
||||
in
|
||||
image
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue