-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
dockerTools: populate the nix database of the container nix store #28561
Conversation
This should be optional or outside of dockerTools. We don't use Nix inside of containers and do not want to increase our image sizes with a Nix DB. |
I use nix inside the container because my container is a hydra slave. It could also be useful to be able to use nix inside the container for debugging purpose. |
27ddc4b
to
55669ed
Compare
@puffnfresh I added the option |
@nlewo can you write this as a function which creates a new layer instead of modifying mkPureLayer? |
I'd definitely prefer making this opt-in |
@puffnfresh I think it's not trivial to add a layer, and I'm not sure it's a good idea to have a layer with a nix database without the store associated to that database. Note also, we currently publish on the docker hub a docker image ( |
55669ed
to
638de38
Compare
ping |
@nlewo isn't this enough? with import <nixpkgs> { };
let
nixRegistration = contents: runCommand "nix-registration" {
buildInputs = [ nixUnstable perl ];
# For obtaining the closure of `contents'.
exportReferencesGraph =
let contentsList = if builtins.isList contents then contents else [ contents ];
in map (x: [("closure-" + baseNameOf x) x]) contentsList;
}
''
printRegistration=1 perl ${pkgs.pathsFromGraph} closure-* > $out
'';
populateNixStore = args@{ contents, ... }:
dockerTools.buildImage (args // {
runAsRoot = dockerTools.shellScript "nix-db.sh" ''
echo "Generating the nix database..."
echo "Warning: only the database of the deepest Nix layer is loaded."
echo " If you want to use nix commands in the container, it would"
echo " be better to only have one layer that contains a nix store."
# This requires Nix 1.12 or higher
export NIX_REMOTE=local?root=$PWD
${nixUnstable}/bin/nix-store --load-db < ${nixRegistration contents}
'';
});
in
populateNixStore {
name = "populated-example";
contents = [ nix hello bash coreutils sqlite ];
} Can we rewrite this PR to just add the above function to dockerTools? |
638de38
to
1e8c43b
Compare
@puffnfresh yeah, really nice improvement. Thanks. |
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.
Even better. Looks good!
@globin could you have a look? |
f325331
to
10f3102
Compare
Maybe @grahamc you could have look? |
LGTM! |
10f3102
to
b552114
Compare
… store Currently, the contents closure is copied to the layer but there is no nix database initialization. If pkgs.nix is added in the contents, nix-store doesn't work because there is no nix database. From the contents of the layer, this commit generates and loads the database in the nix store of the container. This only works if there is no parent layer that already have a nix store (to support several nix layers, we would have to merge nix databases of parent layers). We also add an example to play with the nix store inside the container. Note it seems `more` is a missing dependency of the nix package!
The database dump doesn't contain sha and size. This leads to invalid path in the container. We have to fix the database by using nix-store. Note a better way to do this is available in Nix 1.12 (since the database dump contains all required information). We also add content output paths in the gcroots since they ca be used by the container.
b552114
to
cb6fc52
Compare
Could we move forward on this PR ? :) |
Thanks |
Currently, the contents closure is copied to the layer but there is no
nix database initialization. If pkgs.nix is added in the contents,
nix-store doesn't work because there is no nix database.
From the contents of the layer, this commit generates and loads the
database in the nix store of the container. This only works if there
is no parent layer that already have a nix store (to support several
nix layers, we would have to merge nix databases of parent layers).
We also add an example to play with the nix store inside the
container. Note it seems
more
is a missing dependency of the nixpackage!
Motivation for this change
Be able to use nix in a container
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)