mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
unbound: run in chroot
This commit is contained in:
parent
686fa594ab
commit
aedbfdff84
1 changed files with 16 additions and 16 deletions
|
@ -6,8 +6,6 @@ let
|
||||||
|
|
||||||
cfg = config.services.unbound;
|
cfg = config.services.unbound;
|
||||||
|
|
||||||
username = "unbound";
|
|
||||||
|
|
||||||
stateDir = "/var/lib/unbound";
|
stateDir = "/var/lib/unbound";
|
||||||
|
|
||||||
access = concatMapStrings (x: " access-control: ${x} allow\n") cfg.allowedAccess;
|
access = concatMapStrings (x: " access-control: ${x} allow\n") cfg.allowedAccess;
|
||||||
|
@ -21,21 +19,13 @@ let
|
||||||
confFile = pkgs.writeText "unbound.conf" ''
|
confFile = pkgs.writeText "unbound.conf" ''
|
||||||
server:
|
server:
|
||||||
directory: "${stateDir}"
|
directory: "${stateDir}"
|
||||||
username: ${username}
|
username: unbound
|
||||||
# make sure unbound can access entropy from inside the chroot.
|
|
||||||
# e.g. on linux the use these commands (on BSD, devfs(8) is used):
|
|
||||||
# mount --bind -n /dev/random /etc/unbound/dev/random
|
|
||||||
# and mount --bind -n /dev/log /etc/unbound/dev/log
|
|
||||||
chroot: "${stateDir}"
|
chroot: "${stateDir}"
|
||||||
# logfile: "${stateDir}/unbound.log" #uncomment to use logfile.
|
pidfile: ""
|
||||||
pidfile: "${stateDir}/unbound.pid"
|
|
||||||
verbosity: 1 # uncomment and increase to get more logging.
|
|
||||||
${interfaces}
|
${interfaces}
|
||||||
${access}
|
${access}
|
||||||
|
|
||||||
${forward}
|
|
||||||
|
|
||||||
${cfg.extraConfig}
|
${cfg.extraConfig}
|
||||||
|
${forward}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
|
@ -82,7 +72,7 @@ in
|
||||||
environment.systemPackages = [ pkgs.unbound ];
|
environment.systemPackages = [ pkgs.unbound ];
|
||||||
|
|
||||||
users.extraUsers = singleton {
|
users.extraUsers = singleton {
|
||||||
name = username;
|
name = "unbound";
|
||||||
uid = config.ids.uids.unbound;
|
uid = config.ids.uids.unbound;
|
||||||
description = "unbound daemon user";
|
description = "unbound daemon user";
|
||||||
home = stateDir;
|
home = stateDir;
|
||||||
|
@ -96,8 +86,18 @@ in
|
||||||
wants = [" nss-lookup.target" ];
|
wants = [" nss-lookup.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
path = [ pkgs.unbound ];
|
preStart = ''
|
||||||
serviceConfig.ExecStart = "${pkgs.unbound}/sbin/unbound -d -c ${confFile}";
|
mkdir -m 0755 -p ${stateDir}/dev/
|
||||||
|
cp ${confFile} ${stateDir}/unbound.conf
|
||||||
|
chown unbound ${stateDir}
|
||||||
|
touch ${stateDir}/dev/random
|
||||||
|
${pkgs.utillinux}/bin/mount --bind -n /dev/random ${stateDir}/dev/random
|
||||||
|
'';
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.unbound}/sbin/unbound -d -c ${stateDir}/unbound.conf";
|
||||||
|
ExecStopPost="${pkgs.utillinux}/bin/umount ${stateDir}/dev/random";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue