Refactor lib.nix
This commit is contained in:
parent
d84314ffc7
commit
8ee01f1769
1 changed files with 22 additions and 18 deletions
24
lib.nix
24
lib.nix
|
|
@ -15,7 +15,7 @@
|
||||||
inherit pkgs lib helpers;
|
inherit pkgs lib helpers;
|
||||||
};
|
};
|
||||||
|
|
||||||
initial-state = lib.pipe {
|
initial-state = {
|
||||||
cmd = "${lib.getExe pkgs.bubblewrap}";
|
cmd = "${lib.getExe pkgs.bubblewrap}";
|
||||||
path = "${pkgs.coreutils}/bin";
|
path = "${pkgs.coreutils}/bin";
|
||||||
argv = "\"$@\"";
|
argv = "\"$@\"";
|
||||||
|
|
@ -23,7 +23,10 @@
|
||||||
new-session = true;
|
new-session = true;
|
||||||
hostname = "jail";
|
hostname = "jail";
|
||||||
env = {};
|
env = {};
|
||||||
} (with combinators; [
|
};
|
||||||
|
in lib.pipe initial-state (
|
||||||
|
# apply pre-user combinators
|
||||||
|
(with combinators; [
|
||||||
(unsafe-add-raw-args "--proc /proc")
|
(unsafe-add-raw-args "--proc /proc")
|
||||||
(unsafe-add-raw-args "--dev /dev")
|
(unsafe-add-raw-args "--dev /dev")
|
||||||
(unsafe-add-raw-args "--tmpfs /tmp")
|
(unsafe-add-raw-args "--tmpfs /tmp")
|
||||||
|
|
@ -48,14 +51,13 @@
|
||||||
'')
|
'')
|
||||||
(ro-bind (noescape (helpers.dataDirSubPath "passwd")) "/etc/passwd")
|
(ro-bind (noescape (helpers.dataDirSubPath "passwd")) "/etc/passwd")
|
||||||
(ro-bind (noescape (helpers.dataDirSubPath "group")) "/etc/group")
|
(ro-bind (noescape (helpers.dataDirSubPath "group")) "/etc/group")
|
||||||
]);
|
])
|
||||||
in lib.pipe combinators [
|
|
||||||
# collect opts
|
|
||||||
getOpts
|
|
||||||
(lib.foldl (acc: el: el acc) initial-state)
|
|
||||||
|
|
||||||
# finalize state
|
# apply user combinators
|
||||||
(with combinators; compose [
|
++ getOpts combinators
|
||||||
|
|
||||||
|
# apply post-user combinators
|
||||||
|
++ (with combinators; [
|
||||||
(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:
|
||||||
|
|
@ -65,6 +67,7 @@ in lib.pipe combinators [
|
||||||
])
|
])
|
||||||
|
|
||||||
# build jailed app from state
|
# build jailed app from state
|
||||||
|
++ [
|
||||||
(state: ''
|
(state: ''
|
||||||
RUNTIME_ARGS=()
|
RUNTIME_ARGS=()
|
||||||
${state.runtime}
|
${state.runtime}
|
||||||
|
|
@ -74,4 +77,5 @@ in lib.pipe combinators [
|
||||||
|
|
||||||
# forward man pages
|
# forward man pages
|
||||||
(jailed: if exe ? man then jailed // { inherit (exe) man; } else jailed)
|
(jailed: if exe ? man then jailed // { inherit (exe) man; } else jailed)
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue