Skip to content

Commit

Permalink
lots of tweaks, add infinity nixos module (#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetrucciani authored Dec 30, 2024
1 parent 5c995fd commit 5e6563f
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 30 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
pkgs = self.packages.${sys};
specialArgs = { flake = self; machine-name = name; };
modules = [
./hosts/modules/servers/infinity.nix
./hosts/${name}/configuration.nix
self.inputs.agenix.nixosModules.default
{ programs.ssh.setXAuthLocation = lib.mkForce true; }
Expand Down
1 change: 1 addition & 0 deletions hosts/common_darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ in
util = [
"dbeaver-community"
"docker"
"ghostty"
"insomnia"
"karabiner-elements"
"keybase"
Expand Down
3 changes: 2 additions & 1 deletion hosts/modules/darwin/infinity.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ in
models = mkOption {
type = types.listOf types.str;
default = [
"BAAI/bge-small-en-v1.5"
"nomic-ai/nomic-embed-text-v1.5"
# check out the MTEB leaderboard!
### https://huggingface.co/spaces/mteb/leaderboard
# "jinaai/jina-embeddings-v3"
# "BAAI/bge-small-en-v1.5"
# "dunzhang/stella_en_400M_v5" # requires xformers?
];
description = "the list of embeddings models to load";
Expand Down
6 changes: 3 additions & 3 deletions hosts/modules/games/palworld.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, pkgs, lib, ... }:
let
inherit (lib) mkIf mkEnableOption mkOption;
inherit (lib.types) path port str number;
inherit (lib.types) nullOr path port str number;
cfg = config.services.palworld;
join = builtins.concatStringsSep " ";
in
Expand Down Expand Up @@ -36,7 +36,7 @@ in
description = "the amount of players to support";
};
secretFile = mkOption {
type = path;
type = nullOr path;
default = "/etc/default/palworld";
description = "";
};
Expand Down Expand Up @@ -391,7 +391,7 @@ in
{
wantedBy = [ "multi-user.target" ];
serviceConfig = {
EnvironmentFile = cfg.secretFile;
${if cfg.secretFile != null then "EnvironmentFile" else null} = cfg.secretFile;
ExecStartPre = "${pkgs.bash}/bin/bash -c '${pre_command}'";
ExecStart = join [
"${pkgs.steam-run}/bin/steam-run ${dir}/Pal/Binaries/Linux/${cfg.serverBinary} Pal"
Expand Down
6 changes: 3 additions & 3 deletions hosts/modules/games/valheim.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, pkgs, lib, ... }:
let
inherit (lib) mkIf mkEnableOption mkOption;
inherit (lib.types) path port str;
inherit (lib.types) nullOr path port str;
cfg = config.services.valheim;
in
{
Expand Down Expand Up @@ -40,7 +40,7 @@ in
description = "the name of the world to use";
};
secretFile = mkOption {
type = path;
type = nullOr path;
default = "/etc/default/valheim";
description = ''
this file contains any additional secrets you might want to pass in.
Expand All @@ -64,7 +64,7 @@ in
systemd.services.valheim = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
EnvironmentFile = cfg.secretFile;
${if cfg.secretFile != null then "EnvironmentFile" else null} = cfg.secretFile;
ExecStartPre = ''
${pkgs.steamcmd}/bin/steamcmd \
+force_install_dir ${cfg.dataDir} \
Expand Down
8 changes: 8 additions & 0 deletions hosts/modules/servers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ This directory contains misc servers implemented as nix modules!

a service to run + watch a local executable

### [infinity.nix](./infinity.nix)

[infinity](https://github.com/michaelfeil/infinity) embeddings server

### [minifluxng.nix](./minifluxng.nix)

miniflux

### [obligator.nix](./obligator.nix)

[obligator](https://github.com/lastlogin-net/obligator) service

### [poglets.nix](./poglets.nix)

This NixOS module contains a service for [poglets](https://github.com/jpetrucciani/poglets)
Expand Down
110 changes: 110 additions & 0 deletions hosts/modules/servers/infinity.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{ config, pkgs, lib, ... }:
let
inherit (lib) mkIf mkEnableOption mkOption literalExpression;
inherit (lib.types) listOf nullOr package path port str;
cfg = config.services.infinity;
defaultUser = "infinity";
in
{
imports = [ ];

options.services.infinity = {
enable = mkEnableOption "infinity";
package = mkOption {
type = package;
default = pkgs.python312Packages.infinity-emb;
defaultText = literalExpression "pkgs.python312Packages.infinity-emb";
description = "The package to use for infinity";
};
address = mkOption {
type = str;
default = "0.0.0.0";
description = ''the address to bind to'';
};
port = mkOption {
type = port;
default = 7997;
description = ''the port to bind to'';
};
models = mkOption {
type = listOf str;
default = [
"nomic-ai/nomic-embed-text-v1.5"
# check out the MTEB leaderboard!
### https://huggingface.co/spaces/mteb/leaderboard
# "jinaai/jina-embeddings-v3"
# "BAAI/bge-small-en-v1.5"
# "dunzhang/stella_en_400M_v5" # requires xformers?
];
description = "the list of embeddings models to load";
};
extraFlags = mkOption {
type = str;
description = "any extra flags to pass to infinity";
default = "";
};
secretFile = mkOption {
type = nullOr path;
default = null;
# default = "/etc/default/infinity";
description = ''secret env variables for infinity'';
};
user = mkOption {
type = str;
description = ''
User under which to run the infinity service.
'';
default = defaultUser;
};
group = mkOption {
type = str;
description = ''
Group under which to run the infinity service.
'';
default = defaultUser;
};
dataDir = mkOption {
type = path;
default = "/var/lib/infinity";
description = ''the data directory for infinity'';
};
};

config = mkIf cfg.enable {
users.users.${cfg.user} = {
inherit (cfg) group;
home = cfg.dataDir;
createHome = true;
isSystemUser = true;
};
users.groups.${cfg.group} = { };

systemd.services.infinity =
let
models = lib.concatStringsSep " " (
map (model: "--model-id '${lib.replaceStrings ["'"] [""] model}'") cfg.models
);
serve = pkgs.writers.writeBash "infinity-serve" ''
${lib.getExe' cfg.package "infinity_emb"} v2 --host '${cfg.address}' --port '${toString cfg.port}' ${models} ${cfg.extraFlags}
'';
in
{
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

environment = {
HOME = cfg.dataDir;
USER = cfg.user;
};

serviceConfig = {
${if cfg.secretFile != null then "EnvironmentFile" else null} = cfg.secretFile;
ExecStart = serve;
Restart = "on-failure";
StateDirectory = "infinity";
User = cfg.user;
WorkingDirectory = cfg.dataDir;
};
};
};
}
9 changes: 5 additions & 4 deletions hosts/modules/servers/zinc.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, pkgs, lib, ... }:
let
inherit (lib) mkIf mkEnableOption mkOption literalExpression;
inherit (lib.types) bool package path port str;
inherit (lib.types) bool nullOr package path port str;
cfg = config.services.zinc;
in
{
Expand All @@ -25,8 +25,9 @@ in
description = ''the data directory for zinc'';
};
secretFile = mkOption {
type = path;
default = "/etc/default/zinc";
type = nullOr path;
default = null;
# default = "/etc/default/zinc";
description = ''secret env variables for zinc'';
};
package = mkOption {
Expand Down Expand Up @@ -99,7 +100,7 @@ in
};

serviceConfig = {
EnvironmentFile = cfg.secretFile;
${if cfg.secretFile != null then "EnvironmentFile" else null} = cfg.secretFile;
ExecStart = ''
${cfg.package}/bin/zinc
'';
Expand Down
1 change: 1 addition & 0 deletions hosts/neptune/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ in
port = 8420;
controlPort = 8421;
};
infinity.enable = true;
ombi = {
enable = true;
port = 5999;
Expand Down
18 changes: 8 additions & 10 deletions hosts/neptune/hardware-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
extraModulePackages = [ ];
};

fileSystems."/" =
{
device = "/dev/nvme0n1p2";
fsType = "btrfs";
};
fileSystems."/" = {
device = "/dev/nvme0n1p2";
fsType = "btrfs";
};

fileSystems."/boot" =
{
device = "/dev/disk/by-uuid/aadbe86d-0045-4122-915a-bbd33ef2aec3";
fsType = "ext2";
};
fileSystems."/boot" = {
device = "/dev/disk/by-uuid/aadbe86d-0045-4122-915a-bbd33ef2aec3";
fsType = "ext2";
};

swapDevices = [ ];

Expand Down
3 changes: 1 addition & 2 deletions hosts/nyx0/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ in
infinity = {
enable = true;
models = [
"BAAI/bge-small-en-v1.5"
"jinaai/jina-embeddings-v3"
"nomic-ai/nomic-embed-text-v1"
"nomic-ai/nomic-embed-text-v1.5"
];
};
llama-server.servers = {
Expand Down
3 changes: 1 addition & 2 deletions hosts/pluto/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ in
infinity = {
enable = true;
models = [
"BAAI/bge-small-en-v1.5"
"jinaai/jina-embeddings-v3"
"nomic-ai/nomic-embed-text-v1"
"nomic-ai/nomic-embed-text-v1.5"
];
};
koboldcpp.servers = {
Expand Down
4 changes: 2 additions & 2 deletions hosts/styx/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ in
infinity = {
enable = true;
models = [
"BAAI/bge-small-en-v1.5"
"jinaai/jina-embeddings-v3"
"nomic-ai/nomic-embed-text-v1"
"nomic-ai/nomic-embed-text-v1.5"
# "BAAI/bge-small-en-v1.5"
# "dunzhang/stella_en_400M_v5" # requires xformers?
];
};
Expand Down
6 changes: 6 additions & 0 deletions mods/python/ai/apps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ in

build-system = with final; [
poetry-core
pythonRelaxDepsHook
];

pythonRelaxDeps = [
"numpy"
];

dependencies = with final; [
Expand All @@ -465,6 +470,7 @@ in
einops
fastapi
hf-transfer
httptools
huggingface-hub
numpy
optimum
Expand Down
2 changes: 1 addition & 1 deletion pkgs/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This directory contains specific servers

### [obligator.nix](./obligator.nix)

[obligator](https://github.com/anderspitman/obligator) is an OIDC server designed for self-hosters
[obligator](https://github.com/lastlogin-net/obligator) is an OIDC server designed for self-hosters

### [poglets.nix](./poglets.nix)

Expand Down
4 changes: 2 additions & 2 deletions pkgs/server/obligator.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [obligator](https://github.com/anderspitman/obligator) is an OIDC server designed for self-hosters
# [obligator](https://github.com/lastlogin-net/obligator) is an OIDC server designed for self-hosters
{ lib
, buildGoModule
, fetchFromGitHub
Expand All @@ -22,7 +22,7 @@ buildGoModule {

meta = with lib; {
description = "Simple and opinionated OpenID Connect server designed for self-hosters";
homepage = "https://github.com/anderspitman/obligator";
homepage = "https://github.com/lastlogin-net/obligator";
license = licenses.mit;
maintainers = with maintainers; [ jpetrucciani ];
mainProgram = "obligator";
Expand Down

0 comments on commit 5e6563f

Please sign in to comment.