refactor: further progress
This commit is contained in:
+73
-32
@@ -1,48 +1,80 @@
|
||||
{ lib, config, ... }:
|
||||
let
|
||||
nixosModules = config.flake.modules.nixos;
|
||||
hmModules = config.flake.modules.homeManager;
|
||||
|
||||
resolvePackagePath =
|
||||
{
|
||||
pkgs,
|
||||
path,
|
||||
}:
|
||||
lib.attrByPath path null pkgs;
|
||||
|
||||
mkCaddyReverseProxy =
|
||||
{
|
||||
domain,
|
||||
port,
|
||||
extraHeaders ? [ ],
|
||||
extraConfigText ? "",
|
||||
}:
|
||||
let
|
||||
headerLines = map (header: " header_up ${header.name} ${header.value}") extraHeaders;
|
||||
extraConfigLines = map (line: " ${line}") (
|
||||
lib.filter (line: line != "") (lib.splitString "\n" extraConfigText)
|
||||
);
|
||||
bodyLines = headerLines ++ extraConfigLines;
|
||||
body = lib.concatStringsSep "\n" bodyLines;
|
||||
in
|
||||
{
|
||||
services.caddy.virtualHosts.${domain}.extraConfig =
|
||||
if body == "" then
|
||||
"reverse_proxy :${toString port}"
|
||||
else
|
||||
''
|
||||
reverse_proxy :${toString port} {
|
||||
${body}
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
mkHost =
|
||||
machine:
|
||||
{ config, pkgs, ... }:
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [
|
||||
nixosModules.host-base
|
||||
nixosModules.meta
|
||||
machine.module
|
||||
];
|
||||
|
||||
meta.machine = machine;
|
||||
|
||||
networking.hostName = machine.name;
|
||||
system.stateVersion = machine.stateVersion;
|
||||
|
||||
# TODO: Move this
|
||||
programs.zsh.enable = true;
|
||||
|
||||
users.users = lib.mapAttrs (
|
||||
_: account: {
|
||||
inherit (account) name extraGroups;
|
||||
isNormalUser = true;
|
||||
home = account.homeDirectory;
|
||||
# TODO: Move this
|
||||
shell = pkgs.zsh;
|
||||
}
|
||||
);
|
||||
users.users = lib.mapAttrs (_: user: {
|
||||
isNormalUser = true;
|
||||
home = user.account.homeDirectory;
|
||||
extraGroups = [
|
||||
"wheel"
|
||||
"networkmanager"
|
||||
];
|
||||
shell = pkgs.zsh;
|
||||
}) machine.users;
|
||||
|
||||
home-manager.users = lib.mapAttrs (
|
||||
_: account: {
|
||||
imports = [
|
||||
hmModules.meta
|
||||
account.baseModule
|
||||
];
|
||||
meta = {
|
||||
inherit machine account;
|
||||
};
|
||||
home.homeDirectory = account.homeDirectory;
|
||||
home.stateVersion = machine.hmStateVersion;
|
||||
}
|
||||
);
|
||||
home-manager.users = lib.mapAttrs (name: user: {
|
||||
imports = [ user.account.baseModule ];
|
||||
|
||||
meta = {
|
||||
inherit machine user;
|
||||
};
|
||||
|
||||
home = {
|
||||
username = name;
|
||||
homeDirectory = user.account.homeDirectory;
|
||||
stateVersion = machine.hmStateVersion;
|
||||
};
|
||||
}) machine.users;
|
||||
};
|
||||
|
||||
mkWorkstationHost =
|
||||
@@ -54,11 +86,13 @@ let
|
||||
nixosModules.workstation-base
|
||||
];
|
||||
|
||||
home-manager.users = lib.mapAttrs (
|
||||
_: account: {
|
||||
imports = [ account.workstationModule ];
|
||||
}
|
||||
);
|
||||
users.users = lib.mapAttrs (_: _: {
|
||||
extraGroups = [ "networkmanager" ];
|
||||
}) machine.users;
|
||||
|
||||
home-manager.users = lib.mapAttrs (_: user: {
|
||||
imports = [ user.account.workstationModule ];
|
||||
}) machine.users;
|
||||
};
|
||||
in
|
||||
{
|
||||
@@ -68,5 +102,12 @@ in
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
config.repo.helpers = { inherit mkHost mkWorkstationHost; };
|
||||
config.repo.helpers = {
|
||||
inherit
|
||||
mkCaddyReverseProxy
|
||||
mkHost
|
||||
mkWorkstationHost
|
||||
resolvePackagePath
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user