<commit_before>{ config, lib, pkgs, utils, ... }:
#
# todo:
#   - crontab for scrubs, etc
#   - zfs tunables

with utils;
with lib;

let

  cfgSpl = config.boot.spl;
  cfgZfs = config.boot.zfs;
  cfgSnapshots = config.services.zfs.autoSnapshot;

  inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
  inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;

  enableAutoSnapshots = cfgSnapshots.enable;
  enableZfs = inInitrd || inSystem || enableAutoSnapshots;

  kernel = config.boot.kernelPackages;

  splKernelPkg = if cfgZfs.useGit then kernel.spl_git else kernel.spl;
  zfsKernelPkg = if cfgZfs.useGit then kernel.zfs_git else kernel.zfs;
  zfsUserPkg = if cfgZfs.useGit then pkgs.zfs_git else pkgs.zfs;

  autosnapPkg = pkgs.zfstools.override {
    zfs = zfsUserPkg;
  };

  zfsAutoSnap = "${autosnapPkg}/bin/zfs-auto-snapshot";

  datasetToPool = x: elemAt (splitString "/" x) 0;

  fsToPool = fs: datasetToPool fs.device;

  zfsFilesystems = filter (x: x.fsType == "zfs") (attrValues config.fileSystems);

  isRoot = fs: fs.neededForBoot || elem fs.mountPoint [ "/" "/nix" "/nix/store" "/var" "/var/log" "/var/lib" "/etc" ];

  allPools = unique ((map fsToPool zfsFilesystems) ++ cfgZfs.extraPools);

  rootPools = unique (map fsToPool (filter isRoot zfsFilesystems));

  dataPools = unique (filter (pool: !(elem pool rootPools)) allPools);

in

{

  ###### interface

  options = {
    boot.zfs = {
      useGit = mkOption {
        type = types.bool;
        default = false;
        example = true;
        description = ''
          Use the git version of the SPL and ZFS packages.
          Note that these are unreleased versions, with less testing, and therefore
          may be more unstable.
        '';<commit_msg>nixos/zfs: Use the git version for kernels unsupported by 0.6.3<commit_after>{ config, lib, pkgs, utils, ... }:
#
# todo:
#   - crontab for scrubs, etc
#   - zfs tunables

with utils;
with lib;

let

  cfgSpl = config.boot.spl;
  cfgZfs = config.boot.zfs;
  cfgSnapshots = config.services.zfs.autoSnapshot;

  inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
  inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;

  enableAutoSnapshots = cfgSnapshots.enable;
  enableZfs = inInitrd || inSystem || enableAutoSnapshots;

  kernel = config.boot.kernelPackages;

  splKernelPkg = if cfgZfs.useGit then kernel.spl_git else kernel.spl;
  zfsKernelPkg = if cfgZfs.useGit then kernel.zfs_git else kernel.zfs;
  zfsUserPkg = if cfgZfs.useGit then pkgs.zfs_git else pkgs.zfs;

  autosnapPkg = pkgs.zfstools.override {
    zfs = zfsUserPkg;
  };

  zfsAutoSnap = "${autosnapPkg}/bin/zfs-auto-snapshot";

  datasetToPool = x: elemAt (splitString "/" x) 0;

  fsToPool = fs: datasetToPool fs.device;

  zfsFilesystems = filter (x: x.fsType == "zfs") (attrValues config.fileSystems);

  isRoot = fs: fs.neededForBoot || elem fs.mountPoint [ "/" "/nix" "/nix/store" "/var" "/var/log" "/var/lib" "/etc" ];

  allPools = unique ((map fsToPool zfsFilesystems) ++ cfgZfs.extraPools);

  rootPools = unique (map fsToPool (filter isRoot zfsFilesystems));

  dataPools = unique (filter (pool: !(elem pool rootPools)) allPools);

in

{

  ###### interface

  options = {
    boot.zfs = {
      useGit = mkOption {
        type = types.bool;
        # TODO(wkennington): Revert when 0.6.4 is out
        default = versionAtLeast config.boot.kernelPackages.kernel.version "3.19";
        example = true;
        description = ''
          Use the git version of the SPL and ZFS packages.
          Note that these are unreleased versions, with less testing, and therefore
          may be more unstable.
        '';
{'fraction_non_alphanumeric': 0.12358031368307193, 'fraction_numerical': 0.0029745808545159546, 'mean_word_length': 3.198637911464245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7136138', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1287, 'n_words': 331}