mirror of
https://codeberg.org/icewind/cube.git
synced 2026-06-03 20:14:10 +02:00
flake update
This commit is contained in:
parent
36aff48c7e
commit
5c083bbd4e
6 changed files with 199 additions and 166 deletions
102
nix/module.nix
Normal file
102
nix/module.nix
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.cube;
|
||||
format = pkgs.formats.toml {};
|
||||
configFile = format.generate "cube.toml" {
|
||||
inherit (cfg) listen;
|
||||
exports =
|
||||
mapAttrs (_: export: {
|
||||
inherit (export) path;
|
||||
read_only = export.readOnly;
|
||||
})
|
||||
cfg.exports;
|
||||
};
|
||||
pkg = self.defaultPackage.${pkgs.system};
|
||||
in {
|
||||
options.services.cube = {
|
||||
enable = mkEnableOption "cube";
|
||||
|
||||
log = mkOption {
|
||||
type = types.str;
|
||||
default = "INFO";
|
||||
description = "Log level";
|
||||
};
|
||||
|
||||
listen = mkOption {
|
||||
type = types.submodule {
|
||||
options = {
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
default = 10809;
|
||||
description = "Port to listen on";
|
||||
};
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "0.0.0.0";
|
||||
description = "Address to listen on";
|
||||
};
|
||||
};
|
||||
};
|
||||
default = {
|
||||
address = "0.0.0.0";
|
||||
port = 10809;
|
||||
};
|
||||
};
|
||||
|
||||
exports = mkOption {
|
||||
default = [];
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
description = "Source path to the image to export";
|
||||
};
|
||||
readOnly = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Whether to export the image readonly";
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
openPorts = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
description = "package to use";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
# symlink instead of passing `configFile` directly to cube to allread changing the config without changing the path
|
||||
environment.etc."cube/cube.toml".source = configFile;
|
||||
|
||||
networking.firewall.allowedTCPPorts = optional cfg.openPorts cfg.listen.port;
|
||||
|
||||
systemd.services.cube = {
|
||||
description = "NBD block server";
|
||||
|
||||
environment = {
|
||||
RUST_LOG = cfg.log;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${cfg.package}/bin/cube -c /etc/cube/cube.toml";
|
||||
ExecReload = "${pkgs.util-linux}/bin/kill -HUP $MAINPID";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 10;
|
||||
};
|
||||
wantedBy = ["multi-user.target"];
|
||||
reloadTriggers = [configFile];
|
||||
};
|
||||
};
|
||||
}
|
||||
3
nix/overlay.nix
Normal file
3
nix/overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
final: prev: {
|
||||
cube = final.callPackage ./package.nix {};
|
||||
}
|
||||
23
nix/package.nix
Normal file
23
nix/package.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
rustPlatform,
|
||||
lib,
|
||||
}: let
|
||||
src = lib.sources.sourceByRegex ../. ["Cargo.*" "(src)(/.*)?"];
|
||||
in
|
||||
rustPlatform.buildRustPackage rec {
|
||||
version = "0.1.0";
|
||||
pname = "cube";
|
||||
|
||||
inherit src;
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ../Cargo.lock;
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
description = "A basic NBD block server with a single gimmick";
|
||||
homepage = "https://github.com/icewind1991/cube";
|
||||
license = licenses.mit;
|
||||
platforms = platforms.linux;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue