about summary refs log tree commit diff
path: root/nixos/modules/tasks/bcache.nix
blob: 68531a4d2fed7ff21b66b1376d782b1efc4628ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{ config, lib, pkgs, ... }: let
  cfg = config.boot.bcache;
in {
  options.boot.bcache.enable = lib.mkEnableOption (lib.mdDoc "bcache mount support") // {
    default = true;
    example = false;
  };
  options.boot.initrd.services.bcache.enable = lib.mkEnableOption (lib.mdDoc "bcache support in the initrd") // {
    description = lib.mdDoc ''
      *This will only be used when systemd is used in stage 1.*

      Whether to enable bcache support in the initrd.
    '';
  };

  config = lib.mkIf cfg.enable {

    environment.systemPackages = [ pkgs.bcache-tools ];

    services.udev.packages = [ pkgs.bcache-tools ];

    boot.initrd.extraUdevRulesCommands = lib.mkIf (!config.boot.initrd.systemd.enable) ''
      cp -v ${pkgs.bcache-tools}/lib/udev/rules.d/*.rules $out/
    '';

    boot.initrd.services.udev = lib.mkIf config.boot.initrd.services.bcache.enable {
      packages = [ pkgs.bcache-tools ];
      binPackages = [ pkgs.bcache-tools ];
    };
  };
}