mirror of
https://github.com/nix-community/disko.git
synced 2024-09-11 06:25:33 +03:00
add btrfs subvolumes
This commit is contained in:
parent
dadc491330
commit
81e704b638
14
default.nix
14
default.nix
@ -69,6 +69,18 @@ let
|
||||
|
||||
create-f = q: x: create.${x.type} q x;
|
||||
|
||||
create.btrfs = q: x: ''
|
||||
mkfs.btrfs ${q.device}
|
||||
${lib.optionalString (!isNull x.subvolumes or null) ''
|
||||
MNTPOINT=$(mktemp -d)
|
||||
(
|
||||
mount ${q.device} "$MNTPOINT"
|
||||
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
||||
${concatMapStringsSep "\n" (subvolume: "btrfs subvolume create \"$MNTPOINT\"/${subvolume}") x.subvolumes}
|
||||
)
|
||||
''}
|
||||
'';
|
||||
|
||||
create.filesystem = q: x: ''
|
||||
mkfs.${x.format} ${q.device}
|
||||
'';
|
||||
@ -178,6 +190,8 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
mount.btrfs = mount.filesystem;
|
||||
|
||||
mount.devices = q: x: let
|
||||
z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content);
|
||||
# attrValues returns values sorted by name. This is important, because it
|
||||
|
26
example/btrfs-subvolumes.nix
Normal file
26
example/btrfs-subvolumes.nix
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
type = "devices";
|
||||
content = {
|
||||
vdb = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
type = "partition";
|
||||
part-type = "primary";
|
||||
start = "0%";
|
||||
end = "100%";
|
||||
content = {
|
||||
type = "btrfs";
|
||||
mountpoint = "/";
|
||||
subvolumes = [
|
||||
"/home"
|
||||
"/test"
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
40
tests/btrfs-subvolumes.nix
Normal file
40
tests/btrfs-subvolumes.nix
Normal file
@ -0,0 +1,40 @@
|
||||
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
||||
, pkgs ? (import <nixpkgs> {})
|
||||
}:
|
||||
let
|
||||
makeTest' = args:
|
||||
makeTest args {
|
||||
inherit pkgs;
|
||||
inherit (pkgs) system;
|
||||
};
|
||||
disko-config = import ../example/btrfs-subvolumes.nix;
|
||||
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
|
||||
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
|
||||
in makeTest' {
|
||||
name = "disko";
|
||||
|
||||
nodes.machine =
|
||||
{ config, pkgs, modulesPath, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
(modulesPath + "/profiles/installation-device.nix")
|
||||
(modulesPath + "/profiles/base.nix")
|
||||
];
|
||||
|
||||
# speed-up eval
|
||||
documentation.enable = false;
|
||||
|
||||
virtualisation.emptyDiskImages = [ 512 ];
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.succeed("echo 'secret' > /tmp/secret.key");
|
||||
machine.succeed("${tsp-create}");
|
||||
machine.succeed("${tsp-mount}");
|
||||
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
|
||||
machine.succeed("test -e /mnt/test");
|
||||
machine.succeed("btrfs subvolume list /mnt | grep -qs 'path test$'");
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user