Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions example/bcachefs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@
relies_on_external_subvolume = {
type = "bcachefs_filesystem";
mountpoint = "/home/Documents";
extraFormatArgs = [
"--compression=lz4"
"--background_compression=lz4"
];
mountOptions = [
"verbose"
];
uuid = "64e50034-ebe2-eaf8-1f93-cf56266a8d86";
};
};
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,21 @@ let
loc: defs:
let
evaled = lib.evalModules {
modules =
[
{
freeformType = lib.types.lazyAttrsOf lib.types.raw;
options.type = lib.mkOption {
type = lib.types.str;
};
}
]
++ map (
{ value, file }:
{
_file = file;
config = value;
}
) defs;
modules = [
{
freeformType = lib.types.lazyAttrsOf lib.types.raw;
options.type = lib.mkOption {
type = lib.types.str;
};
}
]
++ map (
{ value, file }:
{
_file = file;
config = value;
}
) defs;
};
inherit (evaled.config) type;
in
Expand Down Expand Up @@ -1195,6 +1194,7 @@ let
};

binfmt = import ./binfmt.nix;
} // outputs;
}
// outputs;
in
diskoLib
23 changes: 11 additions & 12 deletions lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ let

vmTools = pkgs.vmTools.override (
{
rootModules =
[
"9p"
"9pnet_virtio" # we can drop those in future if we stop supporting 24.11
rootModules = [
"9p"
"9pnet_virtio" # we can drop those in future if we stop supporting 24.11

"virtiofs"
"virtio_pci"
"virtio_blk"
"virtio_balloon"
"virtio_rng"
]
++ (lib.optional configSupportsZfs "zfs")
++ cfg.extraRootModules;
"virtiofs"
"virtio_pci"
"virtio_blk"
"virtio_balloon"
"virtio_rng"
]
++ (lib.optional configSupportsZfs "zfs")
++ cfg.extraRootModules;
kernel = pkgs.aggregateModules (
[
cfg.kernelPackages.kernel
Expand Down
29 changes: 14 additions & 15 deletions lib/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,20 @@ let
(
{ config, ... }:
{
boot.supportedFilesystems =
[
"btrfs"
"cifs"
"f2fs"
"jfs"
"ntfs"
"reiserfs"
"vfat"
"xfs"
]
++ lib.optional (
config.networking.hostId != null
&& lib.meta.availableOn pkgs.stdenv.hostPlatform config.boot.zfs.package
) "zfs";
boot.supportedFilesystems = [
"btrfs"
"cifs"
"f2fs"
"jfs"
"ntfs"
"reiserfs"
"vfat"
"xfs"
]
++ lib.optional (
config.networking.hostId != null
&& lib.meta.availableOn pkgs.stdenv.hostPlatform config.boot.zfs.package
) "zfs";
}
)

Expand Down
15 changes: 9 additions & 6 deletions lib/types/bcachefs_filesystem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@
${lib.optionalString (
config.passwordFile != null
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
bcachefs mount \
mount \
-t bcachefs \
-o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \
UUID="${config.uuid}" \
"/dev/disk/by-uuid/${config.uuid}" \
"$MNTPOINT";
trap 'umount "$MNTPOINT"; rm -rf "$MNTPOINT"; rm -rf "$TEMPDIR";' EXIT;
SUBVOL_ABS_PATH="$MNTPOINT/${subvolume.name}";
Expand Down Expand Up @@ -230,7 +231,8 @@
${lib.optionalString (
config.passwordFile != null
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
bcachefs mount \
mount \
-t bcachefs \
-o "${
lib.concatStringsSep "," (
lib.unique (
Expand All @@ -242,7 +244,7 @@
)
)
}" \
UUID="${config.uuid}" \
"/dev/disk/by-uuid/${config.uuid}" \
"${rootMountPoint}${subvolume.mountpoint}";
fi;
'';
Expand All @@ -261,9 +263,10 @@
${lib.optionalString (
config.passwordFile != null
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
bcachefs mount \
mount \
-t bcachefs \
-o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \
UUID="${config.uuid}" \
"/dev/disk/by-uuid/${config.uuid}" \
"${rootMountPoint}${config.mountpoint}";
fi;
'';
Expand Down
3 changes: 2 additions & 1 deletion lib/types/luks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ in
{
boot.initrd.luks.devices.${config.name} = {
inherit (config) device;
} // config.settings;
}
// config.settings;
}
])
++ (lib.optional (config.content != null) config.content._config);
Expand Down
53 changes: 26 additions & 27 deletions lib/types/lvm_vg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
}:
let
# Load kernel modules to ensure device mapper types are available
kernelModules =
[
# Prevent unbootable systems if LVM snapshots are present at boot time.
"dm-snapshot"
]
++ lib.filter (x: x != "") (
map (lv: lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "dm-${lv.lvm_type}") (
lib.attrValues config.lvs
)
);
kernelModules = [
# Prevent unbootable systems if LVM snapshots are present at boot time.
"dm-snapshot"
]
++ lib.filter (x: x != "") (
map (lv: lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "dm-${lv.lvm_type}") (
lib.attrValues config.lvs
)
);
in
{
options = {
Expand Down Expand Up @@ -182,24 +181,24 @@ in
_config = lib.mkOption {
internal = true;
readOnly = true;
default =
[ { boot.initrd.kernelModules = kernelModules; } ]
++ map (lv: [
(lib.optional (lv.content != null) lv.content._config)
(lib.optional (lv.lvm_type != null) {
boot.initrd.kernelModules =
[
(if lv.lvm_type == "mirror" then "dm-mirror" else "dm-raid")
]
++ lib.optional (lv.lvm_type == "raid0") "raid0"
++ lib.optional (lv.lvm_type == "raid1") "raid1"
# ++ lib.optional (lv.lvm_type == "raid10") "raid10"
++ lib.optional (
lv.lvm_type == "raid4" || lv.lvm_type == "raid5" || lv.lvm_type == "raid6"
) "raid456";
default = [
{ boot.initrd.kernelModules = kernelModules; }
]
++ map (lv: [
(lib.optional (lv.content != null) lv.content._config)
(lib.optional (lv.lvm_type != null) {
boot.initrd.kernelModules = [
(if lv.lvm_type == "mirror" then "dm-mirror" else "dm-raid")
]
++ lib.optional (lv.lvm_type == "raid0") "raid0"
++ lib.optional (lv.lvm_type == "raid1") "raid1"
# ++ lib.optional (lv.lvm_type == "raid10") "raid10"
++ lib.optional (
lv.lvm_type == "raid4" || lv.lvm_type == "raid5" || lv.lvm_type == "raid6"
) "raid456";

})
]) (lib.attrValues config.lvs);
})
]) (lib.attrValues config.lvs);
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
Expand Down
3 changes: 2 additions & 1 deletion lib/types/mdadm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
boot.initrd.services.swraid.enable = true;
}
)
] ++ lib.optional (config.content != null) config.content._config;
]
++ lib.optional (config.content != null) config.content._config;
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
Expand Down
49 changes: 25 additions & 24 deletions lib/types/zfs_fs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,20 @@
fi
'';
})
// lib.optionalAttrs
(config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off")
{
fs.${config.mountpoint} = ''
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
-o X-mount.mkdir \
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
-t zfs
fi
'';
};
//
lib.optionalAttrs
(config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off")
{
fs.${config.mountpoint} = ''
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
-o X-mount.mkdir \
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
-t zfs
fi
'';
};
};

_unmount = diskoLib.mkUnmountOption {
Expand All @@ -149,15 +150,16 @@
fi
'';
})
// lib.optionalAttrs
(config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off")
{
fs.${config.mountpoint} = ''
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
//
lib.optionalAttrs
(config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off")
{
fs.${config.mountpoint} = ''
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
};

_config = lib.mkOption {
Expand All @@ -170,8 +172,7 @@
device = "${config._name}";
fsType = "zfs";
options =
config.mountOptions
++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
};
};
description = "NixOS configuration";
Expand Down
Loading