docker: more params: extraPkgs, (trusted)Substituters and extraEnv#6434
docker: more params: extraPkgs, (trusted)Substituters and extraEnv#6434jlamur wants to merge 3 commits intoNixOS:masterfrom
Conversation
|
Isn’t already exposed one way or another by |
|
I am quite new to nix & nixpkgs but I am pretty sure that it is impossible as most of these parameters are defined / used in intermediate variables (in Also, the certs override does not work in some CRI (an "old" one from a ubuntu repo on one of my servers fails to compute env variables correctly if they are duplicated). So I ended up re-creating an image from scratch for my own needs, it works pretty well for now. If that helps someone, it looks like this: nixpkgs.dockerTools.buildLayeredImageWithNixDb {
name = "nix";
tag = "latest";
contents = [
pkgs.bashInteractive
pkgs.coreutils-full
pkgs.curl
pkgs.git
pkgs.nix
pkgs.openssh
pkgs.vim
(pkgs.cacert.override {
extraCertificateFiles = [ certificates.all ];
})
(pkgs.writeTextFile {
name = "nix.conf";
text = ''
build-users-group =
sandbox = false
substituters = ${proxies.nixosCache}
trusted-substituters = ${proxies.nixosCache}
experimental-features = nix-command flakes
'';
destination = "/etc/nix/nix.conf";
})
(pkgs.writeTextFile {
name = ".nix-channels";
text = "${proxies.nixpkgs "nixos-${version}"} nixpkgs";
destination = "/.nix-channels";
})
];
extraCommands = ''
mkdir -p tmp var/tmp
chmod 1777 tmp var/tmp
'';
config = {
Cmd = [ "bash" ];
Env = [
"USER=root"
"PATH=/.nix-profile/bin:/bin"
"NIX_PATH=/.nix-defexpr/channels"
"SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
"GIT_SSL_CAINFO=/etc/ssl/certs/ca-bundle.crt"
"NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
];
};
}I am pretty sure the lack of a shadow & a passwd file may cause problems in some use-cases / for some softwares, but for my own needs (mainly |
Oh, that’s annoying :/ I’ll defer this to @garbas since he’s the author of this file. I’m not too fond of adding these kind of ad-hoc parameters but maybe he has a better solution to this issue |
garbas
left a comment
There was a problem hiding this comment.
@jlamur If you look at the initial PR when we added this file (docker.nix) it was said that this functionality should be actually moved to nixpkgs. Therefore we didn't really work on improving it.
I left one comment, but generally this PR looks like improvement and I would merge once the comment gets addressed.
But if you have time I would love if you can move it to nixpkgs.
Thank you @jlamur for working on this. 🚀
| trusted-public-keys = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="; | ||
| }; | ||
| nixConfContents = (lib.concatStringsSep "\n" (lib.mapAttrsFlatten (n: v: "${n} = ${v}") nixConf)) + "\n"; | ||
| } // (if substituters == [] then {} else { |
There was a problem hiding this comment.
I think it would be better to extend nix.conf via some more general extraNixConf variable (as simple string) instead of having specialized arguments for each option in nix.conf.
NixOS/nixpkgs#148456 demonstrates the refactoring of NixOS modules so that they can efficiently and accurately construct a "partial" configuration that is a container. (as well as be used in "complete" NixOS systems) |
This allows for users to build nix docker images tuned for their substituters, ca and custom packages.
For example, I would use it this way: