Override the package used by a service

Hello,

I would like to use a package+service from nixpkgs-unstable. I am able to get the package from nixpkgs-unstable to install using an overlay, however the corresponding service is still using the old version of the package.

The relevant service file get the package path it uses from ${pkgs.bazarr} and I don’t know why that isn’t using the overridden package.

This configuration done with flakes, I don’t know if that matters.

        modules = [
          ({ config, pkgs, ... }:
            let
              overlay-unstable = final: prev: {
                unstable = import nixpkgs-unstable {
                  system = "x86_64-linux";
                  config.allowUnfree = true;
                };
              };
            in
            {
              nixpkgs.overlays = [ overlay-unstable ];
              environment.systemPackages = with pkgs; [
                unstable.bazarr
              ];
            }
          )
      ]

If something is accessed via pkgs, this will always be the package in the nixpkgs attribute set, not whatever you have in environment.systemPackages. You need to fundamentally change the contents of nixpkgs to have the package version you want using an overlay (however not the way you do), or you need to change the package the module uses.

Some modules will allow you to change whatever packages they’re using with a path.module.package option. In those cases it’s pretty easy, and I’d recommend checking if any module permits this before using overlays (assuming you’re using a flake here, given the modules):

modules = [
  ({ config, pkgs, ... }: {
    path.module.package = nixpkgs-unstable.legacyPackages."x86_64-linux".bazarr;
  })
]

Of course, not all modules have this level of flexibility baked in. Sometimes you do need to faff with overlays. Overlays literally change the contents of your pkgs variable. Your overlay currently adds an unstable attribute, which then contains all the contents of the unstable nixpkgs.

If the module in question accessed bazarr via pkgs.unstable.bazarr, your overlay would work. However, it uses pkgs.bazarr, which currently still points to the stable version.

So all we need to do is fix your overlay to change that attribute instead (also using the legacyPackages here, because the allowUnfree should be unnecessary - feel free to change this back if you do need unfree unstable packages elsewhere):

modules = [
  ({ config, pkgs, ... }:
    let
      overlay-bazarr-unstable = final: prev: {
        bazarr = nixpkgs-unstable.legacyPackages."x86_64-linux".bazarr
      };
    in {
      nixpkgs.overlays = [ overlay-bazarr-unstable ];
    }
  )
]
2 Likes

This worked! And explained what I was doing wrong!

Thank you so much!

I’m making a PR to add a package option to the service :slight_smile:

1 Like