Skip to content

llama-swap: init at v129 & llama-swap: init module #417516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

podium868909
Copy link

adds llama-swap package at v125 & added module
https://github.com/mostlygeek/llama-swap

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

@NixOSInfra NixOSInfra added the 12.first-time contribution This PR is the author's first one; please be gentle! label Jun 17, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` labels Jun 17, 2025
@peterhoeg
Copy link
Member

Thank you for doing this. Feel free to incorporate the changes from here for supporting building the new react UI with version 126.

{
  lib,
  buildGoModule,
  buildNpmPackage,
  fetchFromGitHub,
  versionCheckHook,
}:

let
  version = "126";

  src = fetchFromGitHub {
    owner = "mostlygeek";
    repo = "llama-swap";
    rev = "v${version}";
    hash = "sha256-ZYGH7eAkasZ79V4DD3fuRcUUjHrvd4DPnAxcWVtkJY8=";
  };

  ui = buildNpmPackage (finalAttrs: {
    pname = "llama-swap-ui";
    inherit version src;

    postPatch = ''
      substituteInPlace vite.config.ts \
        --replace '../proxy/ui_dist' '${placeholder "out"}/ui_dist'
    '';

    sourceRoot = "source/ui";

    npmDepsHash = "sha256-smdqD1X9tVr0XMhQYpLBZ57/3iP8tYVoVJ2wR/gAC3w=";

    postInstall = ''
      rm -rf $out/lib
    '';

    meta = {
      description = "llama-swap - UI";
      license = lib.licenses.mit;
      platform = lib.platforms.linux;
    };
  });

in
buildGoModule rec {
  pname = "llama-swap";
  inherit version src;

  vendorHash = "sha256-5mmciFAGe8ZEIQvXejhYN+ocJL3wOVwevIieDuokhGU=";

  preBuild = ''
    cp -r ${ui}/ui_dist proxy/
  '';

  subPackages =
    [
      "."
      "proxy"
    ]
    ++ lib.optionals doCheck [
      "misc/process-cmd-test"
      "misc/simple-responder"
    ];

  nativeBuildInputs = [ versionCheckHook ];

  ldflags = [
    "-X main.version=${version}"
    "-X main.date=unknown"
    "-X main.commit=v${version}"
  ];

  postInstall = ''
    install -Dm444 -t $out/share/doc/${pname} *.md *.yaml
    cp -r examples $out/share/doc/${pname}/
  '';

  # need to adjust proxy/helpers_test.go for it to find the binaries
  doCheck = false;
  # if we run the tests in installCheckPhase instead, adjust this
  postCheck = ''
    rm -f $out/bin/{process-cmd-test,simple-responder}
  '';

  doInstallCheck = true;
  versionCheckProgramArg = "-version";

  meta = {
    description = "Model swapping for llama.cpp (or any local OpenAPI compatible server)";
    license = lib.licenses.mit;
    platform = lib.platforms.linux;
    mainProgram = "llama-swap";
  };
}

@peterhoeg
Copy link
Member

As for the module, I would expect it to run as a user service either here or via home-manager. Having multiple users hitting the same llama-swap instance is bound to bring pain.

@podium868909 podium868909 force-pushed the init-llama-swap branch 3 times, most recently from b8f1abf to b257bb5 Compare June 20, 2025 13:28
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. and removed 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. labels Jun 20, 2025
@podium868909
Copy link
Author

Hi, thanks for the addition of the UI to the package, I was not aware of it when i created this PR 😅.
Regarding the module sorry, i am not very sure what you meant by "run as a user service here", should i just modify the service to use systemd.user.services.llama-swap to replace systemd.services.llama-swap
or do something like something like:

services.llama-swap = {
  package = pkgs.llama-swap;
  instances = {
    john = {
      enable = true;
      ...
    },
    doe = {
      enable = true;
      ...
    }
  }

@podium868909 podium868909 changed the title llama-swap: init at v125 & llama-swap: init module llama-swap: init at v129 & llama-swap: init module Jun 20, 2025
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Jul 4, 2025
@jwiegley
Copy link
Contributor

jwiegley commented Jul 8, 2025

I've been using llama-swap just fine on Darwin, so can we make this a unix platform instead of just linux?

@peterhoeg
Copy link
Member

Hi, thanks for the addition of the UI to the package, I was not aware of it when i created this PR 😅.

In all fairness it was only added in the next version after your initial PR so it's rather difficult to blame you for not being able to see into the future! ;-)

modify the service to use systemd.user.services.llama-swap to replace systemd.services.llama-swap

Yes, exactly this and this is why I said that it really belongs in home-manager instead, but unfortunately hm isn't a part of nixos proper so this is why this is the best alternative option.

The problem with user services in nixos is that it's a little ugly to activate for individual users and why I wouldn't personally use the nixos module but rather my home-made hm module (which I really should upstream too....)

llama-swap is a fast moving project so here are the details for v137 - feel free to adopt as you see fit.

{
  lib,
  buildGoModule,
  buildNpmPackage,
  fetchFromGitHub,
  versionCheckHook,
}:

let
  version = "137";

  src = fetchFromGitHub {
    owner = "mostlygeek";
    repo = "llama-swap";
    rev = "v${version}";
    hash = "sha256-DyAbZMTy4gvmF8HnUJ5B4ypIqhL9MDS7zBzeQfapFD8=";
  };

  ui = buildNpmPackage (finalAttrs: {
    pname = "llama-swap-ui";
    inherit version src;

    postPatch = ''
      substituteInPlace vite.config.ts \
        --replace-fail '../proxy/ui_dist' '${placeholder "out"}/ui_dist'
    '';

    sourceRoot = "source/ui";

    npmDepsHash = "sha256-smdqD1X9tVr0XMhQYpLBZ57/3iP8tYVoVJ2wR/gAC3w=";

    postInstall = ''
      rm -rf $out/lib
    '';

    meta = {
      description = "llama-swap - UI";
      license = lib.licenses.mit;
      maintainers = with lib.maintainers; [ peterhoeg ];
      platform = lib.platforms.linux;
    };
  });

in
buildGoModule rec {
  pname = "llama-swap";
  inherit version src;

  vendorHash = "sha256-nSdvqYVBBVIdoa991bLVwfHPGAO4OHzW8lEQPQ6cuMs=";

  preBuild = ''
    cp -r ${ui}/ui_dist proxy/
  '';

  subPackages =
    [
      "."
      "proxy"
    ]
    ++ lib.optionals doCheck [
      "misc/process-cmd-test"
      "misc/simple-responder"
    ];

  nativeBuildInputs = [ versionCheckHook ];

  ldflags = [
    "-X main.version=${version}"
    "-X main.date=unknown"
    "-X main.commit=v${version}"
  ];

  postInstall = ''
    install -Dm444 -t $out/share/doc/${pname} *.md *.yaml
    cp -r examples $out/share/doc/${pname}/
  '';

  # need to adjust proxy/helpers_test.go for it to find the binaries
  doCheck = false;
  # if we run the tests in installCheckPhase instead, adjust this
  postCheck = ''
    rm -f $out/bin/{process-cmd-test,simple-responder}
  '';

  doInstallCheck = true;
  versionCheckProgramArg = "-version";

  meta = {
    description = "Model swapping for llama.cpp (or any local OpenAPI compatible server)";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ peterhoeg ];
    platform = lib.platforms.linux;
    mainProgram = "llama-swap";
  };
}

An alternative approach is just to do the package first (which is rather uncontroversial) while we hammer out the details of the nixos module. That's your call of course.

I don't have any macs to test on, but if @jwiegley says it works then it does!

@peterhoeg
Copy link
Member

I also didn't take the time to thank for contributing your time to the project - I just noticed this is your first nixos PR so thank you!

@jwiegley
Copy link
Contributor

I copied the definitions from this PR into my configuration in order to update to v137 — by changing linux to unix — and all is working well here. So if you could make that change, I'd be happy to approve and merge.

@podium868909 podium868909 force-pushed the init-llama-swap branch 2 times, most recently from 9eb63af to 9575973 Compare July 16, 2025 08:19
@nixpkgs-ci nixpkgs-ci bot removed the 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. label Jul 16, 2025
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. labels Jul 16, 2025
@podium868909
Copy link
Author

Hi, i've changed linux to unix 😄

An alternative approach is just to do the package first (which is rather uncontroversial) while we hammer out the details of the nixos module.

Would it be possible for the module to be on both home-manager and on nixos at the same time? (system service on nixos here and user service via home-manager)

I think that a common use case for llama-swap are home servers where there usually isn't a need for it to be a user service.

This would allow more convenience and flexibility for users to choose which type they want 😃

@anund anund mentioned this pull request Aug 12, 2025
13 tasks
--replace-fail '../proxy/ui_dist' '${placeholder "out"}/ui_dist'
'';

sourceRoot = "source/ui";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourceRoot = "source/ui";
sourceRoot = "${src.name}/ui";

@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants