mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
split off hm module
This commit is contained in:
parent
50286789f1
commit
9d0e34eeff
2 changed files with 211 additions and 181 deletions
226
flake.nix
226
flake.nix
|
|
@ -12,10 +12,17 @@
|
||||||
cross-naersk.inputs.naersk.follows = "naersk";
|
cross-naersk.inputs.naersk.follows = "naersk";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, naersk, rust-overlay, cross-naersk }:
|
outputs = {
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
naersk,
|
||||||
|
rust-overlay,
|
||||||
|
cross-naersk,
|
||||||
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system: let
|
system: let
|
||||||
overlays = [ (import rust-overlay) ];
|
overlays = [(import rust-overlay)];
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system overlays;
|
inherit system overlays;
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
|
|
@ -29,11 +36,14 @@
|
||||||
];
|
];
|
||||||
releaseTargets = lib.lists.remove hostTarget targets;
|
releaseTargets = lib.lists.remove hostTarget targets;
|
||||||
|
|
||||||
execSufficForTarget = target: if lib.strings.hasInfix "windows" target then ".exe" else "";
|
execSufficForTarget = target:
|
||||||
|
if lib.strings.hasInfix "windows" target
|
||||||
|
then ".exe"
|
||||||
|
else "";
|
||||||
artifactForTarget = target: "palantir${execSufficForTarget target}";
|
artifactForTarget = target: "palantir${execSufficForTarget target}";
|
||||||
assetNameForTarget = target: "palantir-${builtins.replaceStrings ["-unknown" "-gnu" "-musl" "abihf" "-pc"] ["" "" "" "" ""] target}${execSufficForTarget target}";
|
assetNameForTarget = target: "palantir-${builtins.replaceStrings ["-unknown" "-gnu" "-musl" "abihf" "-pc"] ["" "" "" "" ""] target}${execSufficForTarget target}";
|
||||||
|
|
||||||
toolchain = (pkgs.rust-bin.stable.latest.default.override { inherit targets; });
|
toolchain = pkgs.rust-bin.stable.latest.default.override {inherit targets;};
|
||||||
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
|
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
|
||||||
|
|
||||||
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src)(/.*)?"];
|
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src)(/.*)?"];
|
||||||
|
|
@ -44,192 +54,46 @@
|
||||||
};
|
};
|
||||||
buildTarget = target: (cross-naersk'.buildPackage target) nearskOpt;
|
buildTarget = target: (cross-naersk'.buildPackage target) nearskOpt;
|
||||||
hostNaersk = cross-naersk'.hostNaersk;
|
hostNaersk = cross-naersk'.hostNaersk;
|
||||||
in
|
in rec {
|
||||||
rec {
|
# `nix build`
|
||||||
# `nix build`
|
packages =
|
||||||
packages = lib.attrsets.genAttrs targets buildTarget // rec {
|
lib.attrsets.genAttrs targets buildTarget
|
||||||
|
// rec {
|
||||||
haze = packages.${hostTarget};
|
haze = packages.${hostTarget};
|
||||||
check = hostNaersk.buildPackage (nearskOpt // {
|
check = hostNaersk.buildPackage (nearskOpt
|
||||||
mode = "check";
|
// {
|
||||||
});
|
mode = "check";
|
||||||
test = hostNaersk.buildPackage (nearskOpt // {
|
});
|
||||||
mode = "test";
|
test = hostNaersk.buildPackage (nearskOpt
|
||||||
});
|
// {
|
||||||
clippy = hostNaersk.buildPackage (nearskOpt // {
|
mode = "test";
|
||||||
mode = "clippy";
|
});
|
||||||
});
|
clippy = hostNaersk.buildPackage (nearskOpt
|
||||||
|
// {
|
||||||
|
mode = "clippy";
|
||||||
|
});
|
||||||
default = haze;
|
default = haze;
|
||||||
};
|
};
|
||||||
|
|
||||||
inherit targets;
|
inherit targets;
|
||||||
releaseMatrix = {
|
releaseMatrix = {
|
||||||
include = builtins.map (target: {
|
include =
|
||||||
|
builtins.map (target: {
|
||||||
inherit target;
|
inherit target;
|
||||||
artifact_name = artifactForTarget target;
|
artifact_name = artifactForTarget target;
|
||||||
asset_name = assetNameForTarget target;
|
asset_name = assetNameForTarget target;
|
||||||
}) releaseTargets;
|
})
|
||||||
};
|
releaseTargets;
|
||||||
|
};
|
||||||
|
|
||||||
devShells = {
|
devShells = {
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
nativeBuildInputs = with pkgs; [ rustc cargo bacon cargo-edit cargo-outdated clippy ];
|
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated clippy];
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
) // {
|
|
||||||
homeManagerModule = {
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib; let
|
|
||||||
cfg = config.programs.haze;
|
|
||||||
format = pkgs.formats.toml {};
|
|
||||||
configFile = format.generate "haze.toml" ({
|
|
||||||
sources_root = cfg.sourcesRoot;
|
|
||||||
work_dir = cfg.workDir;
|
|
||||||
auto_setup = {
|
|
||||||
enabled = cfg.autoSetup.enable;
|
|
||||||
post_setup = cfg.autoSetup.postSetup;
|
|
||||||
};
|
|
||||||
volume = map (volume: {
|
|
||||||
inherit (volume) source target;
|
|
||||||
read_only = volume.readOnly;
|
|
||||||
}) cfg.volumes;
|
|
||||||
} // (if (cfg.blackfire == null) then {} else {
|
|
||||||
blackfire = {
|
|
||||||
client_id_path = cfg.blackfire.clientIdPath;
|
|
||||||
client_token_path = cfg.blackfire.clientTokenPath;
|
|
||||||
server_id_path = cfg.blackfire.serverIdPath;
|
|
||||||
server_token_path = cfg.blackfire.serverTokenPath;
|
|
||||||
};
|
|
||||||
}) // (if (cfg.proxy == null) then {} else {
|
|
||||||
proxy = {
|
|
||||||
inherit (cfg.proxy) listen https address;
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
pkg = self.packages.${pkgs.system}.default;
|
|
||||||
in {
|
|
||||||
options.programs.haze = {
|
|
||||||
enable = mkEnableOption "haze";
|
|
||||||
|
|
||||||
sourcesRoot = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
example = "/srv/http/cloud";
|
|
||||||
description = "Path containing the Nextcloud sources";
|
|
||||||
};
|
|
||||||
|
|
||||||
workDir = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "~/.cache/haze";
|
|
||||||
description = "Directory to store instance data";
|
|
||||||
};
|
|
||||||
|
|
||||||
autoSetup = mkOption {
|
|
||||||
type = types.submodule {
|
|
||||||
options = {
|
|
||||||
enable = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = "Enable auto setup";
|
|
||||||
};
|
|
||||||
postSetup = mkOption {
|
|
||||||
type = types.listOf types.str;
|
|
||||||
default = [];
|
|
||||||
description = "Commands to run post-setup";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
blackfire = mkOption {
|
|
||||||
default = null;
|
|
||||||
type = types.nullOr (types.submodule {
|
|
||||||
options = {
|
|
||||||
clientIdPath = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Path containing the blackfire client_id";
|
|
||||||
};
|
|
||||||
clientTokenPath = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Path containing the blackfire client_token";
|
|
||||||
};
|
|
||||||
serverIdPath = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Path containing the blackfire server_id";
|
|
||||||
};
|
|
||||||
serverTokenPath = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Path containing the blackfire server_token";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
volumes = mkOption {
|
|
||||||
default = [];
|
|
||||||
type = types.listOf (types.submodule {
|
|
||||||
options = {
|
|
||||||
source = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Source path to mount into the instance";
|
|
||||||
};
|
|
||||||
target = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Path to mount to volume at";
|
|
||||||
};
|
|
||||||
readOnly = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = "Whether to mount the volume readonly";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
proxy = mkOption {
|
|
||||||
default = null;
|
|
||||||
type = types.nullOr (types.submodule {
|
|
||||||
options = {
|
|
||||||
listen = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "Listen address or socket path to listen to";
|
|
||||||
};
|
|
||||||
address = mkOption {
|
|
||||||
default = "";
|
|
||||||
type = types.str;
|
|
||||||
description = "Base address served by a reverse proxy to the haze proxy, instaces will be servered on subdomain of this address";
|
|
||||||
};
|
|
||||||
https = mkOption {
|
|
||||||
default = false;
|
|
||||||
type = types.bool;
|
|
||||||
description = "Whether the reverse proxy accepts https connections";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
xdg.configFile."haze/haze.toml".source = configFile;
|
|
||||||
home.packages = [pkg];
|
|
||||||
|
|
||||||
systemd.user.services.haze = {
|
|
||||||
Unit = {
|
|
||||||
Description = "Haze reverse proxy";
|
|
||||||
};
|
|
||||||
|
|
||||||
Service = {
|
|
||||||
ExecStart = "${pkg}/bin/haze proxy";
|
|
||||||
Restart = "on-failure";
|
|
||||||
RestartSec = 10;
|
|
||||||
};
|
|
||||||
Install = {
|
|
||||||
WantedBy = optional (cfg.proxy != null && cfg.proxy.listen != "") "default.target";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// {
|
||||||
|
homeManagerModule = import ./hm-module.nix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
166
hm-module.nix
Normal file
166
hm-module.nix
Normal file
|
|
@ -0,0 +1,166 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
|
cfg = config.programs.haze;
|
||||||
|
format = pkgs.formats.toml {};
|
||||||
|
configFile = format.generate "haze.toml" ({
|
||||||
|
sources_root = cfg.sourcesRoot;
|
||||||
|
work_dir = cfg.workDir;
|
||||||
|
auto_setup = {
|
||||||
|
enabled = cfg.autoSetup.enable;
|
||||||
|
post_setup = cfg.autoSetup.postSetup;
|
||||||
|
};
|
||||||
|
volume =
|
||||||
|
map (volume: {
|
||||||
|
inherit (volume) source target;
|
||||||
|
read_only = volume.readOnly;
|
||||||
|
})
|
||||||
|
cfg.volumes;
|
||||||
|
}
|
||||||
|
// (
|
||||||
|
if (cfg.blackfire == null)
|
||||||
|
then {}
|
||||||
|
else {
|
||||||
|
blackfire = {
|
||||||
|
client_id_path = cfg.blackfire.clientIdPath;
|
||||||
|
client_token_path = cfg.blackfire.clientTokenPath;
|
||||||
|
server_id_path = cfg.blackfire.serverIdPath;
|
||||||
|
server_token_path = cfg.blackfire.serverTokenPath;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// (
|
||||||
|
if (cfg.proxy == null)
|
||||||
|
then {}
|
||||||
|
else {
|
||||||
|
proxy = {
|
||||||
|
inherit (cfg.proxy) listen https address;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
));
|
||||||
|
pkg = self.packages.${pkgs.system}.default;
|
||||||
|
in {
|
||||||
|
options.programs.haze = {
|
||||||
|
enable = mkEnableOption "haze";
|
||||||
|
|
||||||
|
sourcesRoot = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "/srv/http/cloud";
|
||||||
|
description = "Path containing the Nextcloud sources";
|
||||||
|
};
|
||||||
|
|
||||||
|
workDir = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "~/.cache/haze";
|
||||||
|
description = "Directory to store instance data";
|
||||||
|
};
|
||||||
|
|
||||||
|
autoSetup = mkOption {
|
||||||
|
type = types.submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Enable auto setup";
|
||||||
|
};
|
||||||
|
postSetup = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
description = "Commands to run post-setup";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
blackfire = mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr (types.submodule {
|
||||||
|
options = {
|
||||||
|
clientIdPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Path containing the blackfire client_id";
|
||||||
|
};
|
||||||
|
clientTokenPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Path containing the blackfire client_token";
|
||||||
|
};
|
||||||
|
serverIdPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Path containing the blackfire server_id";
|
||||||
|
};
|
||||||
|
serverTokenPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Path containing the blackfire server_token";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
volumes = mkOption {
|
||||||
|
default = [];
|
||||||
|
type = types.listOf (types.submodule {
|
||||||
|
options = {
|
||||||
|
source = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Source path to mount into the instance";
|
||||||
|
};
|
||||||
|
target = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Path to mount to volume at";
|
||||||
|
};
|
||||||
|
readOnly = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether to mount the volume readonly";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
proxy = mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr (types.submodule {
|
||||||
|
options = {
|
||||||
|
listen = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Listen address or socket path to listen to";
|
||||||
|
};
|
||||||
|
address = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = types.str;
|
||||||
|
description = "Base address served by a reverse proxy to the haze proxy, instaces will be servered on subdomain of this address";
|
||||||
|
};
|
||||||
|
https = mkOption {
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = "Whether the reverse proxy accepts https connections";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
xdg.configFile."haze/haze.toml".source = configFile;
|
||||||
|
home.packages = [pkg];
|
||||||
|
|
||||||
|
systemd.user.services.haze = {
|
||||||
|
Unit = {
|
||||||
|
Description = "Haze reverse proxy";
|
||||||
|
};
|
||||||
|
|
||||||
|
Service = {
|
||||||
|
ExecStart = "${pkg}/bin/haze proxy";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = 10;
|
||||||
|
};
|
||||||
|
Install = {
|
||||||
|
WantedBy = optional (cfg.proxy != null && cfg.proxy.listen != "") "default.target";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue