New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/containers: add extraFlags option #35541
Conversation
@@ -714,7 +724,10 @@ in | |||
${optionalString cfg.autoStart '' | |||
AUTO_START=1 | |||
''} | |||
EXTRA_NSPAWN_FLAGS="${mkBindFlags cfg.bindMounts}" | |||
EXTRA_NSPAWN_FLAGS="${(mkBindFlags cfg.bindMounts) + | |||
(if cfg.extraFlags != null && cfg.extraFlags != [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg.extraFlags
can't be null, because it's type doesn't allow it
nix-repl> (lib.evalModules { modules = [
{
options.test = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
};
}
{
test = null;
}
]; }).config
{ _module = { ... }; test = «error: The option value `test' in `<unknown-file>' is not of type `list of strings'.»; }
EXTRA_NSPAWN_FLAGS="${mkBindFlags cfg.bindMounts}" | ||
EXTRA_NSPAWN_FLAGS="${(mkBindFlags cfg.bindMounts) + | ||
(if cfg.extraFlags != null && cfg.extraFlags != [] | ||
then '' ${" " + concatStringsSep " " cfg.extraFlags}'' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, little nitpicks:
- you can use lib.optionalString instead of if-then-else
- you add one space before antiquotation, and one inside. One of them seems to be redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danbst thank you for your suggestions to clean up the code
else "")}" | ||
EXTRA_NSPAWN_FLAGS="${mkBindFlags cfg.bindMounts + | ||
optionalString (cfg.extraFlags != []) | ||
''${" " + concatStringsSep " " cfg.extraFlags}''}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look like ''${...}''
can now be replaced by ( ... )
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
A bit of topic: User namespaces will not work at the moment |
@Mic92 it would be great to have user namespaces fixed so we can start experimenting with them in NixOS. |
to pass extra flags to systemd-nspawn
9c0adde
to
a82aae3
Compare
rebased and squashed |
Motivation for this change
This new option allows the user to pass arbitrary extra flags to systemd-nspawn when starting a container (similar to extraFlags / extraConfig options in many other modules).
My main use cases for this are dropping capabilities and private user namespaces.
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)