NixOS Containers: Improved

Add personal containers module
Move gitlab into new containers
Move matrix onto Isaiah
This commit is contained in:
Greg Hellings
2024-03-04 15:01:33 -06:00
parent 49e60b180b
commit 57cc340d02
6 changed files with 90 additions and 82 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ let
makeService = name: job: {
serviceConfig = {
User = job.user;
ExecStarPre = lib.optionalString (job.pre != "") job.pre;
ExecStartPre = lib.optionalString (job.pre != "") job.pre;
ExecStart = "${pkgs.rsync}/bin/rsync -avz --delete -e '${pkgs.openssh}/bin/ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null' ${job.src}/ backup@chronicles.shire-zebra.ts.net:/volume1/NetBackup/${job.dest}";
ExecStartPost = lib.optionalString (job.post != "") job.post;
};
+76
View File
@@ -0,0 +1,76 @@
{ config, lib, inputs, ... }:
let
cfg = config.greg.containers;
# Create a container with all our default settings
makeContainer = name: container: let
agekey = "/etc/ssh/agenix_key";
in {
autoStart = true;
hostAddress = "192.168.${container.subnet}.1";
localAddress = "192.168.${container.subnet}.2";
privateNetwork = true;
bindMounts = {
"${agekey}".hostPath = "/etc/ssh/ssh_host_ed25519_key"; # This is needed for agenix to
};
enableTun = container.tailscale;
config = { config, pkgs, ... }: {
imports = [
inputs.agenix.nixosModules.default
inputs.self.modules.nixosModule
container.builder
];
nixpkgs.overlays = inputs.self.overlays.all;
networking = {
firewall.enable = true;
useHostResolvConf = lib.mkForce false;
};
age.identityPaths = [ agekey ];
greg.tailscale.enable = container.tailscale;
};
};
in {
options.greg.containers = lib.mkOption {
default = {};
type = with lib.types; attrsOf ( submodule (
{
options = {
tailscale = lib.mkOption {
type = bool;
default = false;
description = "Enable tailscale in the container";
};
subnet = lib.mkOption {
type = str;
default = "200";
};
builder = lib.mkOption {
default = { ... }: {};
description = ''
This needs to be a function, like the one for
a container's config. It will setup the core system above the
defaults set in this module.
'';
example = ''
{ pkgs, config, lib, ... } :
{
services.openssh.enable = true;
}
'';
};
};
}
));
};
config = {
containers = builtins.mapAttrs makeContainer cfg;
};
}
+1
View File
@@ -4,6 +4,7 @@
imports = [
../baseline.nix
./backup.nix
./container.nix
./db.nix
./gnome.nix
./home.nix