refactor(guest): assemble guest modules
This commit is contained in:
@@ -14,27 +14,23 @@ let
|
||||
root = self + "/modules";
|
||||
};
|
||||
|
||||
guestModules = guests.mkGuests {
|
||||
root = self + "/guests";
|
||||
};
|
||||
|
||||
#----------------------------------------------------------
|
||||
guestFiles = util.collectNixFiles (self + "/guests");
|
||||
|
||||
collectedRegistry = registryAssembly.collect { hosts = self.nixosConfigurations; };
|
||||
|
||||
specialArgs = {
|
||||
inherit
|
||||
flake
|
||||
inputs
|
||||
self
|
||||
util
|
||||
;
|
||||
registry = collectedRegistry;
|
||||
};
|
||||
|
||||
flake = {
|
||||
inherit (hosts) mkHosts;
|
||||
inherit (guests) mkGuest;
|
||||
|
||||
inherit util;
|
||||
};
|
||||
|
||||
guests = import ./guest.nix {
|
||||
inherit
|
||||
inputs
|
||||
@@ -51,10 +47,12 @@ let
|
||||
inputs
|
||||
lib
|
||||
specialArgs
|
||||
guestFiles
|
||||
guestModules
|
||||
registryAssembly
|
||||
;
|
||||
repositoryModules = modules;
|
||||
};
|
||||
in
|
||||
flake
|
||||
{
|
||||
inherit (hosts) mkHosts;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,9 @@
|
||||
registryAssembly,
|
||||
util,
|
||||
}:
|
||||
{
|
||||
let
|
||||
mkGuest =
|
||||
{
|
||||
name,
|
||||
interior ? { },
|
||||
}:
|
||||
name:
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
cfg = config.guests.${name};
|
||||
@@ -131,6 +128,11 @@
|
||||
Mounts are read-write unless `readOnly` is set.
|
||||
'';
|
||||
};
|
||||
interior = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
default = { };
|
||||
description = "NixOS module imported into the guest interior.";
|
||||
};
|
||||
limits = {
|
||||
memory = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
@@ -246,7 +248,7 @@
|
||||
|
||||
repositoryModules
|
||||
registryAssembly.module
|
||||
interior
|
||||
cfg.interior
|
||||
|
||||
{
|
||||
modules.guest.enable = true;
|
||||
@@ -265,4 +267,16 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
mkGuests =
|
||||
{ root }:
|
||||
let
|
||||
files = util.collectNixFiles root;
|
||||
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (builtins.readDir root);
|
||||
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
|
||||
in
|
||||
{
|
||||
imports = files ++ map mkGuest names;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
specialArgs,
|
||||
repositoryModules,
|
||||
|
||||
# TODO refactor guests
|
||||
guestFiles,
|
||||
guestModules,
|
||||
# TODO refactor registry
|
||||
registryAssembly,
|
||||
}:
|
||||
@@ -17,24 +16,23 @@ let
|
||||
}:
|
||||
lib.nixosSystem {
|
||||
inherit specialArgs;
|
||||
modules =
|
||||
guestFiles
|
||||
++ [
|
||||
inputs.chaotic.nixosModules.default
|
||||
inputs.disko.nixosModules.disko
|
||||
inputs.sops-nix.nixosModules.sops
|
||||
inputs.stylix.nixosModules.stylix
|
||||
modules = [
|
||||
inputs.chaotic.nixosModules.default
|
||||
inputs.disko.nixosModules.disko
|
||||
inputs.sops-nix.nixosModules.sops
|
||||
inputs.stylix.nixosModules.stylix
|
||||
|
||||
repositoryModules
|
||||
repositoryModules
|
||||
guestModules
|
||||
|
||||
# TODO: refactor
|
||||
registryAssembly.module (root + "/${name}")
|
||||
# TODO: refactor
|
||||
registryAssembly.module (root + "/${name}")
|
||||
|
||||
{
|
||||
networking.hostName = name;
|
||||
modules.host.enable = true;
|
||||
}
|
||||
];
|
||||
{
|
||||
networking.hostName = name;
|
||||
modules.host.enable = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
flake,
|
||||
...
|
||||
}:
|
||||
let
|
||||
@@ -9,18 +8,6 @@ let
|
||||
dataDir = "/data";
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(flake.mkGuest {
|
||||
name = "actualbudget";
|
||||
interior = {
|
||||
modules.services.actualbudget = {
|
||||
enable = true;
|
||||
inherit dataDir;
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
options.guests.actualbudget = {
|
||||
dataPath = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
@@ -39,6 +26,12 @@ in
|
||||
];
|
||||
|
||||
guests.actualbudget = {
|
||||
interior = {
|
||||
modules.services.actualbudget = {
|
||||
enable = true;
|
||||
inherit dataDir;
|
||||
};
|
||||
};
|
||||
mounts.${dataDir}.directory = cfg.dataPath;
|
||||
limits = {
|
||||
memory = lib.mkDefault "2G";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
flake,
|
||||
...
|
||||
}:
|
||||
let
|
||||
@@ -34,26 +33,6 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(flake.mkGuest {
|
||||
name = "copyparty";
|
||||
interior = {
|
||||
modules.services.copyparty = {
|
||||
enable = true;
|
||||
inherit (cfg) accountName stateDir;
|
||||
passwordFile = "/run/secrets/${cfg.passwordSecret}";
|
||||
reverseProxy = {
|
||||
enable = cfg.reverseProxy.enable;
|
||||
inherit (cfg.reverseProxy) trustedSources;
|
||||
};
|
||||
volumes = lib.mapAttrs (_urlPath: volume: {
|
||||
inherit (volume) path access flags;
|
||||
}) cfg.volumes;
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
options.guests.copyparty = {
|
||||
accountName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
@@ -106,6 +85,19 @@ in
|
||||
];
|
||||
|
||||
guests.copyparty = {
|
||||
interior.modules.services.copyparty = {
|
||||
enable = true;
|
||||
inherit (cfg) accountName stateDir;
|
||||
passwordFile = "/run/secrets/${cfg.passwordSecret}";
|
||||
reverseProxy = {
|
||||
enable = cfg.reverseProxy.enable;
|
||||
inherit (cfg.reverseProxy) trustedSources;
|
||||
};
|
||||
volumes = lib.mapAttrs (_urlPath: volume: {
|
||||
inherit (volume) path access flags;
|
||||
}) cfg.volumes;
|
||||
};
|
||||
|
||||
mounts =
|
||||
{
|
||||
${cfg.stateDir} = {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
flake,
|
||||
...
|
||||
}:
|
||||
let
|
||||
giteaSshBackend = "10.23.20.45:2022";
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(flake.mkGuest {
|
||||
name = "reverse-proxy";
|
||||
config = lib.mkIf config.guests.reverse-proxy.enable {
|
||||
guests.reverse-proxy = {
|
||||
interior = {
|
||||
modules.services.reverse-proxy.enable = true;
|
||||
|
||||
@@ -66,11 +64,7 @@ in
|
||||
}
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
config = lib.mkIf config.guests.reverse-proxy.enable {
|
||||
guests.reverse-proxy = {
|
||||
limits = {
|
||||
memory = lib.mkDefault "1G";
|
||||
cpu = lib.mkDefault "100%";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
flake,
|
||||
pkgs,
|
||||
inputs,
|
||||
...
|
||||
@@ -64,7 +63,7 @@ in
|
||||
useGlobalPkgs = true;
|
||||
useUserPackages = true;
|
||||
extraSpecialArgs = {
|
||||
inherit flake inputs;
|
||||
inherit inputs;
|
||||
};
|
||||
users.${user.name} = {
|
||||
home.username = user.name;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
flake,
|
||||
util,
|
||||
...
|
||||
}:
|
||||
# The host networking foundation: per-VLAN bridges over a tagged trunk.
|
||||
let
|
||||
cfg = config.modules.network.vlans;
|
||||
|
||||
inherit (flake.util) bridgeName;
|
||||
inherit (util) bridgeName;
|
||||
|
||||
vlanName = id: "${cfg.trunk}.${toString id}";
|
||||
in
|
||||
|
||||
Reference in New Issue
Block a user