[Nix-dev] How to override/replace part of a service definition?

Nicolas Pierron nicolas.b.pierron at gmail.com
Tue Feb 24 20:39:26 CET 2015


Hi Michael,

On Sun, Feb 22, 2015 at 2:45 PM, Michael Alan Dorman <mdorman at jaunder.io> wrote:
> All the documentation I can find about overriding things seems focuses
> on packages, but what I'm interested in overriding is the systemd
> pre-start-script.  I tried what seemed obvious:
>
> { config, ... }:
>
> let
>   cfg = config.services.couchdb;
>
> in {
>   systemd.services.couchdb.preStart =
>       ''
>       […]
>       '';
> }
>
> But that appears to have had an *additive* effect---that is, a copy of
> the modified text appears *after* the existing, non-working, definition.

First, you can double check the content of this option without
building a system, with

  $ nixos-option systemd.services.couchdb.preStart

The *additive* effect is a feature, which is used in many cases, such
as defining "fileSystems", "systemd.services", and many more.  This
gives the ability to have a module system where multiple modules can
register them-self concurrently in other modules.

You can override other modules definitions, almost as you expected, by
using "mkOverride <int> <value>", which has a convenient short-cut
named "mkForce <value>", with the "force" int-priority.

This way, you mention that one definition override all the others, as
thus ignore all the definitions with a default priority.  These
properties are briefly described in the Manual [1], and in the Wiki
[2].

[1] https://nixos.org/nixos/manual/sec-writing-modules.html#sec-option-definitions
[2] https://nixos.org/wiki/NixOS:Modules

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron - http://nbp.name/


More information about the nix-dev mailing list