-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer-scripts.nix
57 lines (52 loc) · 1.7 KB
/
container-scripts.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ nixpkgs, version }:
let
lib = nixpkgs.lib;
makeSupportScripts = pkgs:
let
nixos = let
containersBaseConfig = {
time.timeZone = "UTC";
systemd.services."container@" = {
# the start script fails to touch these if they are broken symlinks
preStart = ''
if [ -d $root ]
then
rm $root/etc/{os-release,machine-id}
fi
'';
};
networking.nat = {
enable = true;
internalInterfaces = ["ve-+"];
externalInterface = "enp2s0";
};
};
in
nixpkgs.lib.nixosSystem {
system = pkgs.system;
modules = [ "${nixpkgs}/nixos/modules/virtualisation/docker-image.nix" containersBaseConfig ];
};
osroot = nixos.config.system.build.toplevel;
nixosContainerWrapper = pkgs.writeScriptBin "nixos-container-i18n-wrapper" ''
export LOCALE_ARCHIVE="${nixos.config.i18n.glibcLocales}/lib/locale/locale-archive"
exec "${osroot}/sw/bin/nixos-container" "$@"
'';
in
pkgs.stdenv.mkDerivation {
name = "nspawn-container-scripts-${version}";
unpackPhase = ":";
installPhase = ''
mkdir -p $out/lib/systemd/system $out/bin
ln -s ${osroot}/etc/systemd/system/{nat,container@}.service $out/lib/systemd/system/
ln -s ${nixosContainerWrapper}/bin/nixos-container-i18n-wrapper $out/bin/nixos-container
'';
} // {
tempNixos = nixos;
};
in
{
inherit makeSupportScripts;
overlay = final: prev: {
nspawnContainerScripts = makeSupportScripts final;
};
}