forked from mirrors/nixpkgs
Merge pull request #111591 from Mic92/zfs-kube
This commit is contained in:
commit
57cfa03b03
|
@ -241,7 +241,17 @@ in
|
||||||
description = "Kubernetes Kubelet Service";
|
description = "Kubernetes Kubelet Service";
|
||||||
wantedBy = [ "kubernetes.target" ];
|
wantedBy = [ "kubernetes.target" ];
|
||||||
after = [ "network.target" "docker.service" "kube-apiserver.service" ];
|
after = [ "network.target" "docker.service" "kube-apiserver.service" ];
|
||||||
path = with pkgs; [ gitMinimal openssh docker util-linux iproute ethtool thin-provisioning-tools iptables socat ] ++ top.path;
|
path = with pkgs; [
|
||||||
|
gitMinimal
|
||||||
|
openssh
|
||||||
|
docker
|
||||||
|
util-linux
|
||||||
|
iproute
|
||||||
|
ethtool
|
||||||
|
thin-provisioning-tools
|
||||||
|
iptables
|
||||||
|
socat
|
||||||
|
] ++ lib.optional config.boot.zfs.enabled config.boot.zfs.package ++ top.path;
|
||||||
preStart = ''
|
preStart = ''
|
||||||
${concatMapStrings (img: ''
|
${concatMapStrings (img: ''
|
||||||
echo "Seeding docker image: ${img}"
|
echo "Seeding docker image: ${img}"
|
||||||
|
|
|
@ -17,20 +17,8 @@ let
|
||||||
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
||||||
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
||||||
|
|
||||||
enableZfs = inInitrd || inSystem;
|
|
||||||
|
|
||||||
kernel = config.boot.kernelPackages;
|
|
||||||
|
|
||||||
packages = if config.boot.zfs.enableUnstable then {
|
|
||||||
zfs = kernel.zfsUnstable;
|
|
||||||
zfsUser = pkgs.zfsUnstable;
|
|
||||||
} else {
|
|
||||||
zfs = kernel.zfs;
|
|
||||||
zfsUser = pkgs.zfs;
|
|
||||||
};
|
|
||||||
|
|
||||||
autosnapPkg = pkgs.zfstools.override {
|
autosnapPkg = pkgs.zfstools.override {
|
||||||
zfs = packages.zfsUser;
|
zfs = cfgZfs.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
zfsAutoSnap = "${autosnapPkg}/bin/zfs-auto-snapshot";
|
zfsAutoSnap = "${autosnapPkg}/bin/zfs-auto-snapshot";
|
||||||
|
@ -111,6 +99,20 @@ in
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
boot.zfs = {
|
boot.zfs = {
|
||||||
|
package = mkOption {
|
||||||
|
readOnly = true;
|
||||||
|
type = types.package;
|
||||||
|
default = if config.boot.zfs.enableUnstable then pkgs.zfsUnstable else pkgs.zfs;
|
||||||
|
description = "Configured ZFS userland tools package.";
|
||||||
|
};
|
||||||
|
|
||||||
|
enabled = mkOption {
|
||||||
|
readOnly = true;
|
||||||
|
type = types.bool;
|
||||||
|
default = inInitrd || inSystem;
|
||||||
|
description = "True if ZFS filesystem support is enabled";
|
||||||
|
};
|
||||||
|
|
||||||
enableUnstable = mkOption {
|
enableUnstable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
|
@ -354,7 +356,7 @@ in
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkMerge [
|
config = mkMerge [
|
||||||
(mkIf enableZfs {
|
(mkIf cfgZfs.enabled {
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
assertion = config.networking.hostId != null;
|
assertion = config.networking.hostId != null;
|
||||||
|
@ -366,20 +368,24 @@ in
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
virtualisation.lxd.zfsSupport = true;
|
|
||||||
|
|
||||||
boot = {
|
boot = {
|
||||||
kernelModules = [ "zfs" ];
|
kernelModules = [ "zfs" ];
|
||||||
extraModulePackages = with packages; [ zfs ];
|
|
||||||
|
extraModulePackages = [
|
||||||
|
(if config.boot.zfs.enableUnstable then
|
||||||
|
config.boot.kernelPackages.zfsUnstable
|
||||||
|
else
|
||||||
|
config.boot.kernelPackages.zfs)
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.initrd = mkIf inInitrd {
|
boot.initrd = mkIf inInitrd {
|
||||||
kernelModules = [ "zfs" ] ++ optional (!cfgZfs.enableUnstable) "spl";
|
kernelModules = [ "zfs" ] ++ optional (!cfgZfs.enableUnstable) "spl";
|
||||||
extraUtilsCommands =
|
extraUtilsCommands =
|
||||||
''
|
''
|
||||||
copy_bin_and_libs ${packages.zfsUser}/sbin/zfs
|
copy_bin_and_libs ${cfgZfs.package}/sbin/zfs
|
||||||
copy_bin_and_libs ${packages.zfsUser}/sbin/zdb
|
copy_bin_and_libs ${cfgZfs.package}/sbin/zdb
|
||||||
copy_bin_and_libs ${packages.zfsUser}/sbin/zpool
|
copy_bin_and_libs ${cfgZfs.package}/sbin/zpool
|
||||||
'';
|
'';
|
||||||
extraUtilsCommandsTest = mkIf inInitrd
|
extraUtilsCommandsTest = mkIf inInitrd
|
||||||
''
|
''
|
||||||
|
@ -433,7 +439,7 @@ in
|
||||||
services.zfs.zed.settings = {
|
services.zfs.zed.settings = {
|
||||||
ZED_EMAIL_PROG = mkDefault "${pkgs.mailutils}/bin/mail";
|
ZED_EMAIL_PROG = mkDefault "${pkgs.mailutils}/bin/mail";
|
||||||
PATH = lib.makeBinPath [
|
PATH = lib.makeBinPath [
|
||||||
packages.zfsUser
|
cfgZfs.package
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
pkgs.curl
|
pkgs.curl
|
||||||
pkgs.gawk
|
pkgs.gawk
|
||||||
|
@ -461,18 +467,18 @@ in
|
||||||
"vdev_clear-led.sh"
|
"vdev_clear-led.sh"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(file: { source = "${packages.zfsUser}/etc/${file}"; })
|
(file: { source = "${cfgZfs.package}/etc/${file}"; })
|
||||||
// {
|
// {
|
||||||
"zfs/zed.d/zed.rc".text = zedConf;
|
"zfs/zed.d/zed.rc".text = zedConf;
|
||||||
"zfs/zpool.d".source = "${packages.zfsUser}/etc/zfs/zpool.d/";
|
"zfs/zpool.d".source = "${cfgZfs.package}/etc/zfs/zpool.d/";
|
||||||
};
|
};
|
||||||
|
|
||||||
system.fsPackages = [ packages.zfsUser ]; # XXX: needed? zfs doesn't have (need) a fsck
|
system.fsPackages = [ cfgZfs.package ]; # XXX: needed? zfs doesn't have (need) a fsck
|
||||||
environment.systemPackages = [ packages.zfsUser ]
|
environment.systemPackages = [ cfgZfs.package ]
|
||||||
++ optional cfgSnapshots.enable autosnapPkg; # so the user can run the command to see flags
|
++ optional cfgSnapshots.enable autosnapPkg; # so the user can run the command to see flags
|
||||||
|
|
||||||
services.udev.packages = [ packages.zfsUser ]; # to hook zvol naming, etc.
|
services.udev.packages = [ cfgZfs.package ]; # to hook zvol naming, etc.
|
||||||
systemd.packages = [ packages.zfsUser ];
|
systemd.packages = [ cfgZfs.package ];
|
||||||
|
|
||||||
systemd.services = let
|
systemd.services = let
|
||||||
getPoolFilesystems = pool:
|
getPoolFilesystems = pool:
|
||||||
|
@ -506,8 +512,8 @@ in
|
||||||
environment.ZFS_FORCE = optionalString cfgZfs.forceImportAll "-f";
|
environment.ZFS_FORCE = optionalString cfgZfs.forceImportAll "-f";
|
||||||
script = (importLib {
|
script = (importLib {
|
||||||
# See comments at importLib definition.
|
# See comments at importLib definition.
|
||||||
zpoolCmd="${packages.zfsUser}/sbin/zpool";
|
zpoolCmd = "${cfgZfs.package}/sbin/zpool";
|
||||||
awkCmd="${pkgs.gawk}/bin/awk";
|
zfsCmd = "${cfgZfs.package}/sbin/zfs";
|
||||||
inherit cfgZfs;
|
inherit cfgZfs;
|
||||||
}) + ''
|
}) + ''
|
||||||
poolImported "${pool}" && exit
|
poolImported "${pool}" && exit
|
||||||
|
@ -561,7 +567,7 @@ in
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
};
|
};
|
||||||
script = ''
|
script = ''
|
||||||
${packages.zfsUser}/sbin/zfs set nixos:shutdown-time="$(date)" "${pool}"
|
${cfgZfs.package}/sbin/zfs set nixos:shutdown-time="$(date)" "${pool}"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
createZfsService = serv:
|
createZfsService = serv:
|
||||||
|
@ -587,7 +593,7 @@ in
|
||||||
systemd.targets.zfs.wantedBy = [ "multi-user.target" ];
|
systemd.targets.zfs.wantedBy = [ "multi-user.target" ];
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (enableZfs && cfgSnapshots.enable) {
|
(mkIf (cfgZfs.enabled && cfgSnapshots.enable) {
|
||||||
systemd.services = let
|
systemd.services = let
|
||||||
descr = name: if name == "frequent" then "15 mins"
|
descr = name: if name == "frequent" then "15 mins"
|
||||||
else if name == "hourly" then "hour"
|
else if name == "hourly" then "hour"
|
||||||
|
@ -625,7 +631,7 @@ in
|
||||||
}) snapshotNames);
|
}) snapshotNames);
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (enableZfs && cfgScrub.enable) {
|
(mkIf (cfgZfs.enabled && cfgScrub.enable) {
|
||||||
systemd.services.zfs-scrub = {
|
systemd.services.zfs-scrub = {
|
||||||
description = "ZFS pools scrubbing";
|
description = "ZFS pools scrubbing";
|
||||||
after = [ "zfs-import.target" ];
|
after = [ "zfs-import.target" ];
|
||||||
|
@ -633,11 +639,11 @@ in
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
};
|
};
|
||||||
script = ''
|
script = ''
|
||||||
${packages.zfsUser}/bin/zpool scrub ${
|
${cfgZfs.package}/bin/zpool scrub ${
|
||||||
if cfgScrub.pools != [] then
|
if cfgScrub.pools != [] then
|
||||||
(concatStringsSep " " cfgScrub.pools)
|
(concatStringsSep " " cfgScrub.pools)
|
||||||
else
|
else
|
||||||
"$(${packages.zfsUser}/bin/zpool list -H -o name)"
|
"$(${cfgZfs.package}/bin/zpool list -H -o name)"
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -652,11 +658,11 @@ in
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (enableZfs && cfgTrim.enable) {
|
(mkIf (cfgZfs.enabled && cfgTrim.enable) {
|
||||||
systemd.services.zpool-trim = {
|
systemd.services.zpool-trim = {
|
||||||
description = "ZFS pools trim";
|
description = "ZFS pools trim";
|
||||||
after = [ "zfs-import.target" ];
|
after = [ "zfs-import.target" ];
|
||||||
path = [ packages.zfsUser ];
|
path = [ cfgZfs.package ];
|
||||||
startAt = cfgTrim.interval;
|
startAt = cfgTrim.interval;
|
||||||
# By default we ignore errors returned by the trim command, in case:
|
# By default we ignore errors returned by the trim command, in case:
|
||||||
# - HDDs are mixed with SSDs
|
# - HDDs are mixed with SSDs
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.virtualisation.lxd;
|
cfg = config.virtualisation.lxd;
|
||||||
zfsCfg = config.boot.zfs;
|
in {
|
||||||
|
imports = [
|
||||||
|
(mkRemovedOptionModule [ "virtualisation" "lxd" "zfsPackage" ] "Override zfs in an overlay instead to override it globally")
|
||||||
|
];
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
{
|
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
@ -51,18 +50,10 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
zfsPackage = mkOption {
|
|
||||||
type = types.package;
|
|
||||||
default = with pkgs; if zfsCfg.enableUnstable then zfsUnstable else zfs;
|
|
||||||
defaultText = "pkgs.zfs";
|
|
||||||
description = ''
|
|
||||||
The ZFS package to use with LXD.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
zfsSupport = mkOption {
|
zfsSupport = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = config.boot.zfs.enabled;
|
||||||
|
defaultText = "config.boot.zfs.enabled";
|
||||||
description = ''
|
description = ''
|
||||||
Enables lxd to use zfs as a storage for containers.
|
Enables lxd to use zfs as a storage for containers.
|
||||||
|
|
||||||
|
@ -87,7 +78,6 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
|
@ -110,7 +100,7 @@ in
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "systemd-udev-settle.service" ];
|
after = [ "systemd-udev-settle.service" ];
|
||||||
|
|
||||||
path = lib.optional cfg.zfsSupport cfg.zfsPackage;
|
path = lib.optional config.boot.zfs.enabled config.boot.zfs.package;
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
mkdir -m 0755 -p /var/lib/lxc/rootfs
|
mkdir -m 0755 -p /var/lib/lxc/rootfs
|
||||||
|
|
Loading…
Reference in a new issue