1 { lib, config, pkgs, ... }:
5 maintainers = lib.teams.lxc.members;
9 ./lxc-instance-common.nix
11 (lib.mkRemovedOptionModule [ "virtualisation" "lxc" "nestedContainer" ] "")
12 (lib.mkRemovedOptionModule [ "virtualisation" "lxc" "privilegedContainer" ] "")
18 initScript = if config.boot.initrd.systemd.enable then "prepare-root" else "init";
20 boot.isContainer = true;
21 boot.postBootCommands =
23 # After booting, register the contents of the Nix store in the Nix
25 if [ -f /nix-path-registration ]; then
26 ${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration &&
27 rm /nix-path-registration
30 # nixos-rebuild also requires a "system" profile
31 ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
34 system.build.tarball = pkgs.callPackage ../../lib/make-system-tarball.nix {
35 extraArgs = "--owner=0";
39 object = config.system.build.toplevel;
46 source = config.system.build.toplevel + "/${initScript}";
47 target = "/sbin/init";
49 # Technically this is not required for lxc, but having also make this configuration work with systemd-nspawn.
50 # Nixos will setup the same symlink after start.
52 source = config.system.build.toplevel + "/etc/os-release";
53 target = "/etc/os-release";
57 extraCommands = "mkdir -p proc sys dev";
60 system.build.squashfs = pkgs.callPackage ../../lib/make-squashfs.nix {
61 fileName = "nixos-lxc-image-${pkgs.stdenv.hostPlatform.system}";
63 hydraBuildProduct = true;
64 noStrip = true; # keep directory structure
65 comp = "zstd -Xcompression-level 6";
67 storeContents = [config.system.build.toplevel];
71 "/sbin/init s 0555 0 0 ${config.system.build.toplevel}/${initScript}"
78 system.build.installBootLoader = pkgs.writeScript "install-lxc-sbin-init.sh" ''
79 #!${pkgs.runtimeShell}
80 ${pkgs.coreutils}/bin/ln -fs "$1/${initScript}" /sbin/init
83 # networkd depends on this, but systemd module disables this for containers
84 systemd.additionalUpstreamSystemUnits = ["systemd-udev-trigger.service"];
86 systemd.packages = [ pkgs.distrobuilder.generator ];
88 system.activationScripts.installInitScript = lib.mkForce ''
89 ln -fs $systemConfig/${initScript} /sbin/init