Skip to content
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

Merged
merged 1 commit into from Apr 21, 2018
Merged

Conversation

xeji
Copy link
Contributor

@xeji xeji commented Feb 25, 2018

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@@ -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 != []
Copy link
Contributor

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}''
Copy link
Contributor

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

Copy link
Contributor Author

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}''}"
Copy link
Contributor

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 ( ... ) ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

@Mic92
Copy link
Member

Mic92 commented Feb 25, 2018

A bit of topic: User namespaces will not work at the moment
systemd/systemd#6244
Hopefully I can eventually make a patch for that.

@xeji
Copy link
Contributor Author

xeji commented Feb 25, 2018

@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
@xeji
Copy link
Contributor Author

xeji commented Apr 12, 2018

rebased and squashed

@Mic92 Mic92 merged commit 862f5b0 into NixOS:master Apr 21, 2018
@xeji xeji deleted the containers-extraflags branch April 21, 2018 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants