Override a service definition in Nix?

750 views Asked by At

I'm writing a deployment definition in NixOps. As part of that definition, I need to modify an existing service definition that's provided by <nixpkgs>.

I can't configure the service to do what I want. Because the service definition itself defines some derivations that I need to modify, I can't just add on my own derivation. The only solution I can see is to override the service definition itself, vendoring in a patched copy.

But if I just try

options.services.<myservice> = ... # new service definition

Nix complains that I'm re-defining all the service options.

If I do

options.services.<myservice>.override = ...

Then the changes to the service definition aren't reflected in my use of services.<myservice> later on (specifically, I define new options, but they can't be used).

How can I actually tell Nix that I want to override the service definition, so I can vendor in my own version of the service?

Motivation

The Grafana service provided by nixpkgs is incomplete. You can't provision notifiers, and because the service definition controls provisioning, you can't manually modify the filesystem - you have to control the provisioning derivation.

There's a PR to fix this, but it'll take a while before it's merged. In the meantime, I want to use the version from the PR locally.

1

There are 1 answers

0
Robert Hensing On BEST ANSWER

You can use disabledModules to achieve this.

It will look like

{
  disabledModules = [ "services/monitoring/grafana.nix" ];

  imports = [
    ./my-modules/grafana.nix
  ];
}