mirror of
https://codeberg.org/icewind/palantir.git
synced 2026-06-03 10:14:09 +02:00
flake reorg
This commit is contained in:
parent
898737eea8
commit
bc6b1b1c8f
4 changed files with 177 additions and 125 deletions
140
flake.nix
140
flake.nix
|
|
@ -21,7 +21,10 @@
|
||||||
cross-naersk,
|
cross-naersk,
|
||||||
}:
|
}:
|
||||||
utils.lib.eachDefaultSystem (system: let
|
utils.lib.eachDefaultSystem (system: let
|
||||||
overlays = [ (import rust-overlay) ];
|
overlays = [
|
||||||
|
(import rust-overlay)
|
||||||
|
(import ./overlay.nix)
|
||||||
|
];
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system overlays;
|
inherit system overlays;
|
||||||
};
|
};
|
||||||
|
|
@ -44,30 +47,27 @@
|
||||||
|
|
||||||
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
|
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
|
||||||
|
|
||||||
addUdev = ''
|
|
||||||
mkdir -p $out/lib/udev/rules.d/
|
|
||||||
echo 'SUBSYSTEM=="powercap", ACTION=="add", RUN+="${pkgs.coreutils-full}/bin/chgrp -R powermonitoring /sys%p", RUN+="${pkgs.coreutils-full}/bin/chmod -R g=u /sys%p"' >> $out/lib/udev/rules.d/51-palantir.rules
|
|
||||||
echo 'SUBSYSTEM=="powercap", ACTION=="change", ENV{TRIGGER}!="none", RUN+="${pkgs.coreutils-full}/bin/chgrp -R powermonitoring /sys%p", RUN+="${pkgs.coreutils-full}/bin/chmod -R g=u /sys%p"' >> $out/lib/udev/rules.d/51-palantir.rules
|
|
||||||
'';
|
|
||||||
|
|
||||||
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src|benches)(/.*)?"];
|
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src|benches)(/.*)?"];
|
||||||
|
|
||||||
nearskOpt = {
|
nearskOpt = {
|
||||||
pname = "palantir";
|
pname = "palantir";
|
||||||
root = src;
|
root = src;
|
||||||
|
|
||||||
postInstall = addUdev;
|
postInstall = pkgs.palantir.postInstall;
|
||||||
};
|
};
|
||||||
buildTarget = target: (cross-naersk'.buildPackage target) nearskOpt;
|
buildTarget = target: (cross-naersk'.buildPackage target) nearskOpt;
|
||||||
hostNaersk = cross-naersk'.hostNaersk;
|
hostNaersk = cross-naersk'.hostNaersk;
|
||||||
in rec {
|
in rec {
|
||||||
# `nix build`
|
packages =
|
||||||
packages = nixpkgs.lib.attrsets.genAttrs targets buildTarget // rec {
|
nixpkgs.lib.attrsets.genAttrs targets buildTarget
|
||||||
palantir = packages.${hostTarget};
|
// rec {
|
||||||
check = hostNaersk.buildPackage (nearskOpt // {
|
palantir = pkgs.palantir;
|
||||||
|
check = hostNaersk.buildPackage (nearskOpt
|
||||||
|
// {
|
||||||
mode = "check";
|
mode = "check";
|
||||||
});
|
});
|
||||||
clippy = hostNaersk.buildPackage (nearskOpt // {
|
clippy = hostNaersk.buildPackage (nearskOpt
|
||||||
|
// {
|
||||||
mode = "clippy";
|
mode = "clippy";
|
||||||
});
|
});
|
||||||
default = palantir;
|
default = palantir;
|
||||||
|
|
@ -80,11 +80,13 @@
|
||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
# `nix develop`
|
# `nix develop`
|
||||||
|
|
@ -95,109 +97,17 @@
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
// {
|
// {
|
||||||
nixosModule = {
|
overlays = import ./overlay.nix;
|
||||||
|
modules.default = {
|
||||||
|
pkgs,
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}: {
|
||||||
with lib; let
|
imports = [./module.nix];
|
||||||
cfg = config.palantir.services.palantir;
|
config = lib.mkIf config.services.palantir.enable {
|
||||||
in {
|
nixpkgs.overlays = [self.overlays.default];
|
||||||
options.palantir.services.palantir = {
|
services.palantir.package = lib.mkDefault pkgs.palantir;
|
||||||
enable = mkEnableOption "Enables the palantir service";
|
|
||||||
|
|
||||||
port = mkOption rec {
|
|
||||||
type = types.int;
|
|
||||||
default = 5665;
|
|
||||||
example = default;
|
|
||||||
description = "The port to listen on";
|
|
||||||
};
|
|
||||||
|
|
||||||
zfs = mkOption rec {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
example = true;
|
|
||||||
description = "enable zfs integration";
|
|
||||||
};
|
|
||||||
|
|
||||||
docker = mkOption rec {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
example = true;
|
|
||||||
description = "enable docker integration";
|
|
||||||
};
|
|
||||||
|
|
||||||
mdns = mkOption rec {
|
|
||||||
type = types.bool;
|
|
||||||
default = true;
|
|
||||||
example = true;
|
|
||||||
description = "enable mdns discovery";
|
|
||||||
};
|
|
||||||
|
|
||||||
openPort = mkOption rec {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
example = true;
|
|
||||||
description = "open port";
|
|
||||||
};
|
|
||||||
|
|
||||||
openMDNSPort = mkOption rec {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
example = true;
|
|
||||||
description = "open mdns port";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
networking.firewall.allowedTCPPorts = lib.optional cfg.openPort cfg.port;
|
|
||||||
networking.firewall.allowedUDPPorts = lib.optional cfg.openMDNSPort 5353;
|
|
||||||
|
|
||||||
users.groups.powermonitoring = {};
|
|
||||||
|
|
||||||
services.udev.packages = [self.packages.${pkgs.system}.default];
|
|
||||||
|
|
||||||
systemd.services."palantir" = {
|
|
||||||
wantedBy = ["multi-user.target"];
|
|
||||||
path = lib.optional cfg.zfs pkgs.zfs;
|
|
||||||
environment = {
|
|
||||||
PORT = "${toString cfg.port}";
|
|
||||||
LD_LIBRARY_PATH = "/run/opengl-driver/lib/"; # needed for nvidia
|
|
||||||
} // (if (cfg.mdns == false) then {
|
|
||||||
DISABLE_MDNS = "true";
|
|
||||||
} else {});
|
|
||||||
|
|
||||||
serviceConfig = let
|
|
||||||
pkg = self.packages.${pkgs.system}.default;
|
|
||||||
in {
|
|
||||||
Restart = "on-failure";
|
|
||||||
ExecStart = "${pkg}/bin/palantir";
|
|
||||||
DynamicUser = true;
|
|
||||||
PrivateTmp = true;
|
|
||||||
PrivateUsers = true;
|
|
||||||
ProtectSystem = "strict";
|
|
||||||
ProtectHome = true;
|
|
||||||
NoNewPrivileges = true;
|
|
||||||
ProtectClock = !cfg.zfs; # Enabling this breaks libzfs
|
|
||||||
CapabilityBoundingSet = true;
|
|
||||||
ProtectKernelLogs = true;
|
|
||||||
ProtectControlGroups = true;
|
|
||||||
SystemCallArchitectures = "native";
|
|
||||||
ProtectKernelModules = true;
|
|
||||||
RestrictNamespaces = true;
|
|
||||||
MemoryDenyWriteExecute = true;
|
|
||||||
ProtectHostname = true;
|
|
||||||
LockPersonality = true;
|
|
||||||
ProtectKernelTunables = true;
|
|
||||||
RestrictAddressFamilies = ["AF_INET" "AF_INET6" "AF_NETLINK"] ++ lib.optional cfg.docker "AF_UNIX"; # netlink is required to make `getifaddrs` not err
|
|
||||||
RestrictRealtime = true;
|
|
||||||
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
|
||||||
IPAddressAllow = ["localhost"] ++ lib.optional cfg.mdns "multicast";
|
|
||||||
UMask = "0077";
|
|
||||||
SupplementaryGroups = ["powermonitoring"] ++ lib.optional cfg.docker "docker";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
114
module.nix
Normal file
114
module.nix
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
|
cfg = config.palantir.services.palantir;
|
||||||
|
in {
|
||||||
|
options.palantir.services.palantir = {
|
||||||
|
enable = mkEnableOption "Enables the palantir service";
|
||||||
|
|
||||||
|
port = mkOption rec {
|
||||||
|
type = types.int;
|
||||||
|
default = 5665;
|
||||||
|
example = default;
|
||||||
|
description = "The port to listen on";
|
||||||
|
};
|
||||||
|
|
||||||
|
zfs = mkOption rec {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
example = true;
|
||||||
|
description = "enable zfs integration";
|
||||||
|
};
|
||||||
|
|
||||||
|
docker = mkOption rec {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
example = true;
|
||||||
|
description = "enable docker integration";
|
||||||
|
};
|
||||||
|
|
||||||
|
mdns = mkOption rec {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
example = true;
|
||||||
|
description = "enable mdns discovery";
|
||||||
|
};
|
||||||
|
|
||||||
|
openPort = mkOption rec {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
example = true;
|
||||||
|
description = "open port";
|
||||||
|
};
|
||||||
|
|
||||||
|
openMDNSPort = mkOption rec {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
example = true;
|
||||||
|
description = "open mdns port";
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
description = "package to use";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
networking.firewall.allowedTCPPorts = lib.optional cfg.openPort cfg.port;
|
||||||
|
networking.firewall.allowedUDPPorts = lib.optional cfg.openMDNSPort 5353;
|
||||||
|
|
||||||
|
users.groups.powermonitoring = {};
|
||||||
|
|
||||||
|
services.udev.packages = [cfg.package];
|
||||||
|
|
||||||
|
systemd.services."palantir" = {
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
path = lib.optional cfg.zfs pkgs.zfs;
|
||||||
|
environment =
|
||||||
|
{
|
||||||
|
PORT = "${toString cfg.port}";
|
||||||
|
LD_LIBRARY_PATH = "/run/opengl-driver/lib/"; # needed for nvidia
|
||||||
|
}
|
||||||
|
// (
|
||||||
|
if (cfg.mdns == false)
|
||||||
|
then {
|
||||||
|
DISABLE_MDNS = "true";
|
||||||
|
}
|
||||||
|
else {}
|
||||||
|
);
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Restart = "on-failure";
|
||||||
|
ExecStart = "${cfg.package}/bin/palantir";
|
||||||
|
DynamicUser = true;
|
||||||
|
PrivateTmp = true;
|
||||||
|
PrivateUsers = true;
|
||||||
|
ProtectSystem = "strict";
|
||||||
|
ProtectHome = true;
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
ProtectClock = !cfg.zfs; # Enabling this breaks libzfs
|
||||||
|
CapabilityBoundingSet = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
SystemCallArchitectures = "native";
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
MemoryDenyWriteExecute = true;
|
||||||
|
ProtectHostname = true;
|
||||||
|
LockPersonality = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
RestrictAddressFamilies = ["AF_INET" "AF_INET6" "AF_NETLINK"] ++ lib.optional cfg.docker "AF_UNIX"; # netlink is required to make `getifaddrs` not err
|
||||||
|
RestrictRealtime = true;
|
||||||
|
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
||||||
|
IPAddressAllow = ["localhost"] ++ lib.optional cfg.mdns "multicast";
|
||||||
|
UMask = "0077";
|
||||||
|
SupplementaryGroups = ["powermonitoring"] ++ lib.optional cfg.docker "docker";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
3
overlay.nix
Normal file
3
overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
final: prev: {
|
||||||
|
palantir = final.callPackage ./package.nix {};
|
||||||
|
}
|
||||||
25
package.nix
Normal file
25
package.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
stdenv,
|
||||||
|
rustPlatform,
|
||||||
|
coreutils,
|
||||||
|
lib,
|
||||||
|
}: let
|
||||||
|
inherit (lib.sources) sourceByRegex;
|
||||||
|
src = sourceByRegex ./. ["Cargo.*" "(src|benches)(/.*)?"];
|
||||||
|
in
|
||||||
|
rustPlatform.buildRustPackage rec {
|
||||||
|
name = "palantir";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
inherit src;
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
mkdir -p $out/lib/udev/rules.d/
|
||||||
|
echo 'SUBSYSTEM=="powercap", ACTION=="add", RUN+="${coreutils}/bin/chgrp -R powermonitoring /sys%p", RUN+="${coreutils}/bin/chmod -R g=u /sys%p"' >> $out/lib/udev/rules.d/51-palantir.rules
|
||||||
|
echo 'SUBSYSTEM=="powercap", ACTION=="change", ENV{TRIGGER}!="none", RUN+="${coreutils}/bin/chgrp -R powermonitoring /sys%p", RUN+="${coreutils}/bin/chmod -R g=u /sys%p"' >> $out/lib/udev/rules.d/51-palantir.rules
|
||||||
|
'';
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue