-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to attach Packet Storage to the nix servers ? #15
Comments
I have a NixOS module which appears to work: https://gist.github.com/bgamari/c352cf7b6bada19f53678359308526fe. Note that |
Ohh, I see @bgamari! Thanks for this 👍 |
Reopening so it is easier to find later :) |
@bgamari is there more to that module? AFAICS the packet-block-storage-attach script will not be nixos friendly (try to update conf files) |
@mmlb there is not. It's definitely somewhat of a hack but it works well enough that I have been leaving it alone. However, there is one important caveat: the |
So, after discussing this on Slack with @bgamari and @grahamc, this now is trivial to set up. This is what I do (though you may make differences if you so choose):
Note: if you have iscsid running while your doing this, kill it before running nixos-rebuild switch --upgrade. If you don't, the service will throw complaints because it can't bind itself. |
Current state of the gist is as follows: { pkgs, config, lib, ... }:
let
packet-block-storage =
pkgs.stdenv.mkDerivation {
name = "packet-block-storage";
src = pkgs.fetchFromGitHub {
owner = "packethost";
repo = "packet-block-storage";
rev = "4be27cbca7a924b4de7af059d5ac30c2aa5c9e6f";
sha256 = "0h4lpvz7v6xhl14kkwrjp202lbagj6wp2wqgrqdc6cfb4h0mf9fq";
};
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase =
let
deps = with pkgs; [
which jq curl gawk kmod openiscsi multipath-tools
];
wrapIt = prog: ''
cp ${prog} $out/bin
chmod ugo+rx $out/bin/${prog}
substituteInPlace $out/bin/${prog} --replace /lib/udev/scsi_id ${pkgs.udev}/lib/udev/scsi_id
wrapProgram $out/bin/${prog} --prefix PATH : ${lib.makeBinPath deps}
'';
in ''
mkdir -p $out/bin
${wrapIt "packet-block-storage-attach"}
${wrapIt "packet-block-storage-detach"}
'';
};
in {
environment.systemPackages = [ packet-block-storage pkgs.multipath-tools pkgs.openiscsi ];
systemd.sockets.multipathd = {
description = "multipathd control socket";
before = [ "sockets.target" ];
listenStreams = ["@/org/kernel/linux/storage/multipathd"];
};
systemd.services.multipathd = {
description = "Device-Mapper Multipath Device Controller";
before = [
"iscsi.service" "iscsid.service"
];
after = [ "multipathd.socket" "systemd-udevd.service" ];
unitConfig = {
DefaultDependencies = false;
};
wants = [ "multipathd.socket" "blk-availability.service" ];
conflicts = ["shutdown.target"];
serviceConfig = {
Type = "notify";
NotifyAccess = "main";
LimitCORE = "infinity";
ExecStartPre = "${pkgs.kmod}/bin/modprobe -a dm-multipath";
ExecStart = "${pkgs.multipath-tools}/bin/multipathd -d -s";
ExecReload = "${pkgs.multipath-tools}/bin/multipathd reconfigure";
};
};
systemd.targets.iscsi = {
description = "iSCSI mounts";
wants = [ "iscsid.service" "attach-block-storage.service" ];
wantedBy = [ "remote-fs.target" ];
};
systemd.services.iscsid = {
description = "iSCSI daemon";
path = [ pkgs.openiscsi ];
script = "iscsid -f";
};
systemd.services.attach-block-storage = {
description = "Attach Packet.net block storage";
requires = [ "network-online.target" "iscsid.service" "multipathd.service" ];
after = [ "network-online.target" "iscsid.service" "multipathd.service" ];
before = [ ];
script = ''
${packet-block-storage}/bin/packet-block-storage-attach
'';
};
} |
Hi @grahamc
I'd like to know how could I connect the storage to nixos server.
I've been following the guides here
https://help.packet.net/article/63-elastic-block-storage
https://github.com/packethost/packet-block-storage
Could you please help me out ?
The text was updated successfully, but these errors were encountered: