Allow sharing namespaces other than net
This commit is contained in:
parent
a8dcbbefa6
commit
3c0a3b807b
2 changed files with 13 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ in rec {
|
||||||
add-pkg-deps = pkgs: compose (builtins.map (pkg: add-path "${pkg}/bin") pkgs);
|
add-pkg-deps = pkgs: compose (builtins.map (pkg: add-path "${pkg}/bin") pkgs);
|
||||||
no-new-session = state: state // { new-session = false; };
|
no-new-session = state: state // { new-session = false; };
|
||||||
set-env = name: value: state: state // { env = state.env // { ${name} = escape value; }; };
|
set-env = name: value: state: state // { env = state.env // { ${name} = escape value; }; };
|
||||||
|
share-ns = namespace: state: state // { namespaces = state.namespaces // { ${namespace} = true; }; };
|
||||||
|
|
||||||
set-hostname = hostname: state: state // { inherit hostname; };
|
set-hostname = hostname: state: state // { inherit hostname; };
|
||||||
|
|
||||||
|
|
@ -62,6 +63,7 @@ in rec {
|
||||||
];
|
];
|
||||||
network = state: compose [
|
network = state: compose [
|
||||||
time-zone
|
time-zone
|
||||||
|
(share-ns "net")
|
||||||
(readonly "/etc/hosts")
|
(readonly "/etc/hosts")
|
||||||
(readonly "/etc/nsswitch.conf")
|
(readonly "/etc/nsswitch.conf")
|
||||||
(readonly "/etc/resolv.conf")
|
(readonly "/etc/resolv.conf")
|
||||||
|
|
@ -69,7 +71,7 @@ in rec {
|
||||||
(readonly "/etc/static/nsswitch.conf")
|
(readonly "/etc/static/nsswitch.conf")
|
||||||
(readonly "/etc/static/ssl")
|
(readonly "/etc/static/ssl")
|
||||||
(write-text "/etc/hostname" "${state.hostname}\n")
|
(write-text "/etc/hostname" "${state.hostname}\n")
|
||||||
(unsafe-add-raw-args "--share-net --hostname ${escape state.hostname}")
|
(unsafe-add-raw-args "--hostname ${escape state.hostname}")
|
||||||
] state;
|
] state;
|
||||||
dbus-unsafe = compose [
|
dbus-unsafe = compose [
|
||||||
(readonly (noescape "\"$XDG_RUNTIME_DIR/bus\""))
|
(readonly (noescape "\"$XDG_RUNTIME_DIR/bus\""))
|
||||||
|
|
|
||||||
11
lib.nix
11
lib.nix
|
|
@ -23,6 +23,7 @@
|
||||||
new-session = true;
|
new-session = true;
|
||||||
hostname = "jail";
|
hostname = "jail";
|
||||||
env = {};
|
env = {};
|
||||||
|
namespaces = {};
|
||||||
};
|
};
|
||||||
in lib.pipe initial-state (
|
in lib.pipe initial-state (
|
||||||
# apply pre-user combinators
|
# apply pre-user combinators
|
||||||
|
|
@ -33,7 +34,6 @@ in lib.pipe initial-state (
|
||||||
(unsafe-add-raw-args "--tmpfs ~")
|
(unsafe-add-raw-args "--tmpfs ~")
|
||||||
(unsafe-add-raw-args "--clearenv")
|
(unsafe-add-raw-args "--clearenv")
|
||||||
(unsafe-add-raw-args "--die-with-parent")
|
(unsafe-add-raw-args "--die-with-parent")
|
||||||
(unsafe-add-raw-args "--unshare-all")
|
|
||||||
(readonly "/nix/store")
|
(readonly "/nix/store")
|
||||||
(readonly "/bin/sh")
|
(readonly "/bin/sh")
|
||||||
(fwd-env "LANG")
|
(fwd-env "LANG")
|
||||||
|
|
@ -58,6 +58,15 @@ in lib.pipe initial-state (
|
||||||
|
|
||||||
# apply post-user combinators
|
# apply post-user combinators
|
||||||
++ (with combinators; [
|
++ (with combinators; [
|
||||||
|
(s:
|
||||||
|
# See `--unshare-*` from man bwrap
|
||||||
|
lib.pipe ["user" "ipc" "pid" "net" "uts" "cgroup"] [
|
||||||
|
(lib.filter (ns: !(s.namespaces.${ns} or false)))
|
||||||
|
(map (ns: "--unshare-${ns}"))
|
||||||
|
(builtins.concatStringsSep " ")
|
||||||
|
unsafe-add-raw-args
|
||||||
|
] s
|
||||||
|
)
|
||||||
(s: set-env "PATH" s.path s)
|
(s: set-env "PATH" s.path s)
|
||||||
(s: if s.new-session then unsafe-add-raw-args "--new-session" s else s)
|
(s: if s.new-session then unsafe-add-raw-args "--new-session" s else s)
|
||||||
(s: lib.foldr (envVar:
|
(s: lib.foldr (envVar:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue