[Nix-dev] How to override/replace part of a service definition?
Michael Alan Dorman
mdorman at jaunder.io
Sun Feb 22 14:45:43 CET 2015
I'm very new to NixOS; perhaps this isn't the correct venue to ask this
sort of question, in which case I would appreciate guidance about where
better to ask.
In trying to use the couchdb package, I found a couple of issues with
its pre-start script[1]. My PR
(https://github.com/NixOS/nixpkgs/pull/6283) has not yet been merged,
and until such time as it is, I would like to override things locally so
it will work without manual intervention after each reboot.
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 =
''
mkdir -p `dirname ${cfg.uriFile}`;
mkdir -p `dirname ${cfg.logFile}`;
mkdir -p ${cfg.databaseDir};
mkdir -p ${cfg.viewIndexDir};
touch ${cfg.configFile}
touch -a ${cfg.logFile}
if [ "$(id -u)" = 0 ]; then
chown ${cfg.user}:${cfg.group} `dirname ${cfg.uriFile}`;
(-f ${cfg.uriFile} && chown ${cfg.user}:${cfg.group}
${cfg.uriFile}) || true
chown ${cfg.user}:${cfg.group} ${cfg.databaseDir}
chown ${cfg.user}:${cfg.group} ${cfg.viewIndexDir}
chown ${cfg.user}:${cfg.group} ${cfg.configFile}
chown ${cfg.user}:${cfg.group} ${cfg.logFile}
fi
'';
}
But that appears to have had an *additive* effect---that is, a copy of
the modified text appears *after* the existing, non-working, definition.
Any specific remedies, or pointers to specific bits of documentation
I've missed---I believe I've combed the wiki pretty thoroughly---would
be much appreciated.
Mike.
1. After rebooting, checking the service status provides you with:
Feb 22 08:42:49 aching systemd[1]: Starting CouchDB Server...
Feb 22 08:42:49 aching systemd[1]: couchdb.service: control process
exited, code=exited status=1
Feb 22 08:42:49 aching systemd[1]: Failed to start CouchDB Server.
Feb 22 08:42:49 aching systemd[1]: Unit couchdb.service entered failed
state.
Feb 22 08:42:49 aching systemd[1]: couchdb.service failed.
Feb 22 08:42:49 aching couchdb-pre-start[1464]: chown: cannot access
‘/var/run/couchdb/couchdb.uri’: No such file or directory
Simple inspection reveals commands being run under -e that are not being
careful in examining their environment.
More information about the nix-dev
mailing list