title: Override a service definition in Nix?
body: <p>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 <code>&lt;nixpkgs&gt;</code>.</p>
  <p>I <em>can't</em> 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.</p>
  <p>But if I just try</p>
  <pre class="lang-hs prettyprint-override"><code>options.services.&lt;myservice&gt; = ... # new service definition
  </code></pre>
  <p>Nix complains that I'm re-defining all the service options.</p>
  <p>If I do</p>
  <pre class="lang-hs prettyprint-override"><code>options.services.&lt;myservice&gt;.override = ...
  </code></pre>
  <p>Then the changes to the service definition aren't reflected in my use of
  <code>services.&lt;myservice&gt;</code> later on (specifically, I define new options, but they can't be used).</p>
  <p>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?</p>
  <h3>Motivation</h3>
  <p>The Grafana service provided by <code>nixpkgs</code> is incomplete. You can't <a href="https://grafana.com/docs/grafana/latest/administration/provisioning/#alert-notification-channels" rel="nofollow noreferrer">provision notifiers</a>, and because the <a href="https://github.com/NixOS/nixpkgs/blob/a058d005b3cbb370bf171ebce01839dd6ff52222/nixos/modules/services/monitoring/grafana.nix#L536" rel="nofollow noreferrer">service definition controls provisioning</a>, you can't manually modify the filesystem - you have to control <a href="https://github.com/NixOS/nixpkgs/blob/a058d005b3cbb370bf171ebce01839dd6ff52222/nixos/modules/services/monitoring/grafana.nix#L67" rel="nofollow noreferrer">the provisioning derivation</a>.</p>
  <p>There's a <a href="https://github.com/NixOS/nixpkgs/pull/110942" rel="nofollow noreferrer">PR to fix this</a>, but it'll take a while before it's merged. In the meantime, I want to use the version from the PR locally.</p>