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

[Discussion] Lxc image should contain configuration used for generation as /etc/nixos/configuration.nix #42

Open
asbachb opened this issue Sep 14, 2019 · 3 comments
Assignees

Comments

@asbachb
Copy link

asbachb commented Sep 14, 2019

Since I'm not quite familiar with NixOS environment I don't exactly know if this is a good idea or not:

Basically what I stumbled over was that the default configuration bundles an nginx server within the image, but the bundled configuration.nix is empty.
Maybe the configuration used to generating the image should be included into the image somehow?

@asbachb
Copy link
Author

asbachb commented Sep 26, 2019

@Lassulus any thoughts on that?

@zimbatm
Copy link
Member

zimbatm commented Sep 26, 2019

To rebuild the system you need a copy of the configuration.nix and also the version of nixpkgs that was used to build the system in the first place.

{ modulesPath, ... }:
{
  imports = [
    # add a copy of nixpkgs to the image
    "${modulesPath}/installer/cd-dvd/channel.nix"
  ];
  # copy the configuration.nix into /run/current-system/configuration.nix
  system.copySystemConfiguration = true;
}

Then if you want to rebuild the system from within the VM, run:

cp /run/current-system/configuration.nix /etc/nixos/configuration.nix
# edit the file with your changes
nixos-rebuild switch

There are a few limitations with the approach:

  1. adding nixpkgs to the image grows the image quite a bit (~600Mb ?). If you disable it then append -I nixpkgs=channel:nixos-19.09 for example to the nixos-rebuild command
  2. it doesn't work if the system configuration is split over multiple files as only the main configuration.nix will be copied into the store.
  3. I'm not sure if LXC supports changing the bootloader of the VM. To be verified.

(1) and (2) are the main reasons why it's not done by default.

@Lassulus
Copy link
Collaborator

Lassulus commented Oct 2, 2019

mildly related: NixOS/nixpkgs#67475

but thanks a lot to zimbatm for the thorough explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants