136: add hybrid bios/efi example + fixes & zvol table support r=Lassulus a=Lassulus



Co-authored-by: lassulus <git@lassul.us>
Co-authored-by: Jörg Thalheim <joerg@thalheim.io>
This commit is contained in:
bors[bot] 2023-02-02 13:53:06 +00:00 committed by GitHub
commit d3bbbfe4f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 1565 deletions

View file

@ -1,4 +1,5 @@
{ pkgs ? import <nixpkgs> {}
, lib ? pkgs.lib
, mode ? "mount"
, flake ? null
, flakeAttr ? null
@ -9,13 +10,13 @@
let
disko = import ./. {
inherit rootMountPoint;
lib = pkgs.lib;
inherit lib;
};
diskFormat = if flake != null then
(pkgs.lib.attrByPath [ "diskoConfigurations" flakeAttr ] (builtins.abort "${flakeAttr} does not exist") (builtins.getFlake flake)) args
else
import diskoFile args;
import diskoFile ({ inherit lib; } // args);
diskoEval = if noDeps then
if (mode == "create") then

46
example/hybrid.nix Normal file
View file

@ -0,0 +1,46 @@
{ disks ? [ "/dev/vda" ], ... }:
{
disk = {
main = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = ["bios_grub"];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
type = "partition";
name = "root";
start = "512M";
end = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
};
};
};
}

View file

@ -1,28 +1,20 @@
{ stdenvNoCC, lib }:
{ stdenvNoCC, makeWrapper, lib, path }:
let
inclFiles = {src, name}: files: lib.cleanSourceWith {
inherit src name;
filter = _path: _type: _type == "regular" && lib.any (file: builtins.baseNameOf _path == file) files;
};
in
stdenvNoCC.mkDerivation rec {
name = "disko";
src = inclFiles { inherit name; src = ./.; } [
"disko"
"cli.nix"
"default.nix"
"types.nix"
"options.nix"
src = ./.;
nativeBuildInputs = [
makeWrapper
];
installPhase = ''
mkdir -p $out/bin $out/share/disko
cp -r $src/* $out/share/disko
cp -r cli.nix default.nix disk-deactivate types $out/share/disko
sed \
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
$src/disko > $out/bin/disko
disko > $out/bin/disko
chmod 755 $out/bin/disko
wrapProgram $out/bin/disko --prefix NIX_PATH : "nixpkgs=${path}"
'';
meta = with lib; {
description = "Format disks with nix-config";

9
tests/hybrid.nix Normal file
View file

@ -0,0 +1,9 @@
{ pkgs ? (import <nixpkgs> { })
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
disko-config = ../example/hybrid.nix;
extraTestScript = ''
machine.succeed("mountpoint /");
'';
}

1545
types.nix

File diff suppressed because it is too large Load diff

View file

@ -55,12 +55,14 @@ rec {
deviceNumbering = dev: index:
if match "/dev/[vs]d.+" dev != null then
dev + toString index # /dev/{s,v}da style
else if match "/dev/disk/.+" dev != null then
"${dev}-part${toString index}" # /dev/disk/by-id/xxx style
else if match "/dev/(disk|zvol)/.+" dev != null then
"${dev}-part${toString index}" # /dev/disk/by-id/xxx style, also used by zfs's zvolumes
else if match "/dev/(nvme|md/|mmcblk).+" dev != null then
"${dev}p${toString index}" # /dev/nvme0n1p1 style
else
abort "${dev} seems not to be a supported disk format";
abort ''
${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/types/default.nix
'';
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
jsonType =