nixos/nvme: Add module
All checks were successful
CI / Check, build and cache Nix flake (push) Successful in 17m30s
All checks were successful
CI / Check, build and cache Nix flake (push) Successful in 17m30s
This commit is contained in:
@@ -17,5 +17,6 @@
|
||||
gui = ./gui.nix;
|
||||
l2mesh = ./l2mesh.nix;
|
||||
borgthin = ./borgthin.nix;
|
||||
nvme = ./nvme;
|
||||
};
|
||||
}
|
||||
|
58
nixos/modules/nvme/default.nix
Normal file
58
nixos/modules/nvme/default.nix
Normal file
@@ -0,0 +1,58 @@
|
||||
{ lib, pkgs, config, ... }:
|
||||
let
|
||||
inherit (lib) mkIf;
|
||||
inherit (lib.my) mkOpt';
|
||||
|
||||
cfg = config.my.nvme;
|
||||
nvme-cli = pkgs.nvme-cli.override {
|
||||
libnvme = pkgs.libnvme.overrideAttrs (o: {
|
||||
patches = o.patches ++ [ ./libnvme-hostconf.patch ];
|
||||
});
|
||||
};
|
||||
|
||||
hostNQN = "nqn.2014-08.org.nvmexpress:uuid:${cfg.uuid}";
|
||||
etc = prefix: {
|
||||
"${prefix}nvme/hostnqn".text = hostNQN;
|
||||
"${prefix}nvme/hostid".text = cfg.uuid;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.my.nvme = with lib.types; {
|
||||
uuid = mkOpt' (nullOr str) null "NVMe host ID";
|
||||
boot = {
|
||||
nqn = mkOpt' (nullOr str) null "NQN to connect to on boot";
|
||||
address = mkOpt' str null "Address of NVMe-oF target.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.uuid != null) {
|
||||
environment = {
|
||||
systemPackages = [
|
||||
nvme-cli
|
||||
];
|
||||
etc = etc "";
|
||||
};
|
||||
|
||||
boot.initrd.systemd = mkIf (cfg.boot.nqn != null) {
|
||||
contents = etc "/etc/";
|
||||
extraBin.nvme = "${nvme-cli}/bin/nvme";
|
||||
|
||||
services.connect-nvme = {
|
||||
description = "Connect NVMe-oF";
|
||||
before = [ "initrd-root-device.target" ];
|
||||
after = [ "systemd-networkd-wait-online.service" ];
|
||||
requires = [ "systemd-networkd-wait-online.service" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${nvme-cli}/bin/nvme connect -t rdma -a ${cfg.boot.address} -n ${cfg.boot.nqn}";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 10;
|
||||
};
|
||||
|
||||
wantedBy = [ "initrd-root-device.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
15
nixos/modules/nvme/libnvme-hostconf.patch
Normal file
15
nixos/modules/nvme/libnvme-hostconf.patch
Normal file
@@ -0,0 +1,15 @@
|
||||
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
|
||||
index 21fb292..f9090d1 100644
|
||||
--- a/src/nvme/fabrics.c
|
||||
+++ b/src/nvme/fabrics.c
|
||||
@@ -41,8 +41,8 @@
|
||||
|
||||
#define NVMF_HOSTID_SIZE 37
|
||||
|
||||
-#define NVMF_HOSTNQN_FILE SYSCONFDIR "/nvme/hostnqn"
|
||||
-#define NVMF_HOSTID_FILE SYSCONFDIR "/nvme/hostid"
|
||||
+#define NVMF_HOSTNQN_FILE "/etc/nvme/hostnqn"
|
||||
+#define NVMF_HOSTID_FILE "/etc/nvme/hostid"
|
||||
|
||||
const char *nvmf_dev = "/dev/nvme-fabrics";
|
||||
|
Reference in New Issue
Block a user