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