mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 08:00:05 +01:00
Merge #136
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:
commit
d3bbbfe4f4
6 changed files with 70 additions and 1565 deletions
5
cli.nix
5
cli.nix
|
|
@ -1,4 +1,5 @@
|
||||||
{ pkgs ? import <nixpkgs> {}
|
{ pkgs ? import <nixpkgs> {}
|
||||||
|
, lib ? pkgs.lib
|
||||||
, mode ? "mount"
|
, mode ? "mount"
|
||||||
, flake ? null
|
, flake ? null
|
||||||
, flakeAttr ? null
|
, flakeAttr ? null
|
||||||
|
|
@ -9,13 +10,13 @@
|
||||||
let
|
let
|
||||||
disko = import ./. {
|
disko = import ./. {
|
||||||
inherit rootMountPoint;
|
inherit rootMountPoint;
|
||||||
lib = pkgs.lib;
|
inherit lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
diskFormat = if flake != null then
|
diskFormat = if flake != null then
|
||||||
(pkgs.lib.attrByPath [ "diskoConfigurations" flakeAttr ] (builtins.abort "${flakeAttr} does not exist") (builtins.getFlake flake)) args
|
(pkgs.lib.attrByPath [ "diskoConfigurations" flakeAttr ] (builtins.abort "${flakeAttr} does not exist") (builtins.getFlake flake)) args
|
||||||
else
|
else
|
||||||
import diskoFile args;
|
import diskoFile ({ inherit lib; } // args);
|
||||||
|
|
||||||
diskoEval = if noDeps then
|
diskoEval = if noDeps then
|
||||||
if (mode == "create") then
|
if (mode == "create") then
|
||||||
|
|
|
||||||
46
example/hybrid.nix
Normal file
46
example/hybrid.nix
Normal 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 = "/";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
22
package.nix
22
package.nix
|
|
@ -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 {
|
stdenvNoCC.mkDerivation rec {
|
||||||
name = "disko";
|
name = "disko";
|
||||||
src = inclFiles { inherit name; src = ./.; } [
|
src = ./.;
|
||||||
"disko"
|
nativeBuildInputs = [
|
||||||
"cli.nix"
|
makeWrapper
|
||||||
"default.nix"
|
|
||||||
"types.nix"
|
|
||||||
"options.nix"
|
|
||||||
];
|
];
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin $out/share/disko
|
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 \
|
sed \
|
||||||
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
|
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
|
||||||
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
|
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
|
||||||
$src/disko > $out/bin/disko
|
disko > $out/bin/disko
|
||||||
chmod 755 $out/bin/disko
|
chmod 755 $out/bin/disko
|
||||||
|
wrapProgram $out/bin/disko --prefix NIX_PATH : "nixpkgs=${path}"
|
||||||
'';
|
'';
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "Format disks with nix-config";
|
description = "Format disks with nix-config";
|
||||||
|
|
|
||||||
9
tests/hybrid.nix
Normal file
9
tests/hybrid.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{ pkgs ? (import <nixpkgs> { })
|
||||||
|
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
|
||||||
|
}:
|
||||||
|
makeDiskoTest {
|
||||||
|
disko-config = ../example/hybrid.nix;
|
||||||
|
extraTestScript = ''
|
||||||
|
machine.succeed("mountpoint /");
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
@ -55,12 +55,14 @@ rec {
|
||||||
deviceNumbering = dev: index:
|
deviceNumbering = dev: index:
|
||||||
if match "/dev/[vs]d.+" dev != null then
|
if match "/dev/[vs]d.+" dev != null then
|
||||||
dev + toString index # /dev/{s,v}da style
|
dev + toString index # /dev/{s,v}da style
|
||||||
else if match "/dev/disk/.+" dev != null then
|
else if match "/dev/(disk|zvol)/.+" dev != null then
|
||||||
"${dev}-part${toString index}" # /dev/disk/by-id/xxx style
|
"${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
|
else if match "/dev/(nvme|md/|mmcblk).+" dev != null then
|
||||||
"${dev}p${toString index}" # /dev/nvme0n1p1 style
|
"${dev}p${toString index}" # /dev/nvme0n1p1 style
|
||||||
else
|
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 */
|
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
||||||
jsonType =
|
jsonType =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue