lxc: start an impl on server7
This commit is contained in:
parent
2158436497
commit
d94e9775c6
|
@ -35,4 +35,11 @@ let
|
|||
in {
|
||||
boot.enableContainers = true;
|
||||
inherit containers;
|
||||
|
||||
imports = [ ../../../lib/lxc ];
|
||||
lxc.containers = {
|
||||
trivial = {
|
||||
nixos-config = "/tmp/trivial.nix";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
with lib;
|
||||
|
||||
let
|
||||
profilesDir = "/nix/var/nix/profiles/lxc";
|
||||
gcRoots = "/nix/var/nix/gcroots/lxc";
|
||||
containers = config.lxc.containers;
|
||||
in {
|
||||
options = with types; {
|
||||
lxc.containers = mkOption {
|
||||
type = attrs;
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (containers != {}) {
|
||||
virtualisation.lxc = {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
systemd.services =
|
||||
builtins.foldl' (services: name:
|
||||
let
|
||||
config = builtins.getAttr name containers;
|
||||
builder = {
|
||||
description = "Build NixOS for lxc container ${name}";
|
||||
wants = [ "nix-daemon.socket" ];
|
||||
after = [ "nix-daemon.service" ];
|
||||
|
||||
path = with pkgs; [ coreutils nix ];
|
||||
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.RemainAfterExit = true;
|
||||
|
||||
script = ''
|
||||
mkdir -p ${profilesDir}/${name}
|
||||
mkdir -p ${gcRoots}/${name}
|
||||
|
||||
nix-env -p ${profilesDir}/${name}/system \
|
||||
-I nixos-config=${config.nixos-config} \
|
||||
-f '<nixpkgs/nixos>' \
|
||||
--set -A system
|
||||
'';
|
||||
};
|
||||
starter = {
|
||||
description = "LXC container ${name}";
|
||||
requires = [ "lxc-container-${name}-builder" ];
|
||||
after = [ "lxc-container-${name}-builder" ];
|
||||
|
||||
path = with pkgs; [ lxc ];
|
||||
|
||||
script = ''
|
||||
lxc-start -F -n ${name}
|
||||
'';
|
||||
};
|
||||
in services // {
|
||||
"lxc-container-${name}-builder" = builder;
|
||||
"lxc-container-${name}" = starter;
|
||||
}
|
||||
) {} (builtins.attrNames containers);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue