mirror of
https://codeberg.org/icewind/cube.git
synced 2026-06-03 12:04:10 +02:00
flake reorg
This commit is contained in:
parent
33e0cb8290
commit
6351eea575
5 changed files with 149 additions and 109 deletions
32
flake.lock
generated
32
flake.lock
generated
|
|
@ -1,12 +1,15 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1676283394,
|
"lastModified": 1705309234,
|
||||||
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
|
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
|
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -17,16 +20,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1686237827,
|
"lastModified": 1707650010,
|
||||||
"narHash": "sha256-fAZB+Zkcmc+qlauiFnIH9+2qgwM0NO/ru5pWEw3tDow=",
|
"narHash": "sha256-dOhphIA4MGrH4ElNCy/OlwmN24MsnEqFjRR6+RY7jZw=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "81ed90058a851eb73be835c770e062c6938c8a9e",
|
"rev": "809cca784b9f72a5ad4b991e0e7bcf8890f9c3a6",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-23.05",
|
"ref": "nixos-23.11",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -35,6 +38,21 @@
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
|
||||||
116
flake.nix
116
flake.nix
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/nixos-23.11";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
nixpkgs.url = "nixpkgs/nixos-23.05";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
|
|
@ -11,119 +11,35 @@
|
||||||
}:
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system: let
|
system: let
|
||||||
|
overlays = [
|
||||||
|
(import ./overlay.nix)
|
||||||
|
];
|
||||||
pkgs = (import nixpkgs) {
|
pkgs = (import nixpkgs) {
|
||||||
inherit system;
|
inherit system overlays;
|
||||||
};
|
};
|
||||||
in rec {
|
in rec {
|
||||||
# `nix build`
|
|
||||||
packages = rec {
|
packages = rec {
|
||||||
cube = pkgs.callPackage (import ./package.nix) {};
|
cube = pkgs.cube;
|
||||||
default = cube;
|
default = cube;
|
||||||
};
|
};
|
||||||
|
|
||||||
# `nix develop`
|
devShell = pkgs.mkShell {
|
||||||
devShells.default = pkgs.mkShell {
|
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated clippy cargo-audit];
|
||||||
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// {
|
// {
|
||||||
nixosModule = {
|
overlays.default = import ./overlay.nix;
|
||||||
|
nixosModules.default = {
|
||||||
|
pkgs,
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}: {
|
||||||
with lib; let
|
imports = [./module.nix];
|
||||||
cube = pkgs.callPackage (import ./package.nix) {};
|
config = lib.mkIf config.services.cube.enable {
|
||||||
cfg = config.services.cube;
|
nixpkgs.overlays = [self.overlays.default];
|
||||||
format = pkgs.formats.toml {};
|
services.cube.package = lib.mkDefault pkgs.cube;
|
||||||
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;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
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 = "${cube}/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];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
103
module.nix
Normal file
103
module.nix
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
{
|
||||||
|
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
overlay.nix
Normal file
3
overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
final: prev: {
|
||||||
|
cube = final.callPackage ./package.nix {};
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
lib,
|
lib,
|
||||||
}: let
|
}: let
|
||||||
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src)(/.*)?"];
|
src = lib.sources.sourceByRegex ./. ["Cargo.*" "(src)(/.*)?"];
|
||||||
in
|
in
|
||||||
rustPlatform.buildRustPackage rec {
|
rustPlatform.buildRustPackage rec {
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue