refactor
This commit is contained in:
1 parent
81e576a877
commit
cde67e4d75
46 files changed
+619
-518
No files matched your search
+209
-32
@@ -1,14 +1,193 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
factsOption = lib.mkOption {
|
||||
type = lib.types.submodule {
|
||||
freeformType = lib.types.attrsOf lib.types.anything;
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
emailType = types.submodule {
|
||||
options = {
|
||||
address = mkOption { type = types.nonEmptyStr; };
|
||||
type = mkOption {
|
||||
type = types.enum [
|
||||
"mxrouting"
|
||||
"office365"
|
||||
];
|
||||
};
|
||||
};
|
||||
default = { };
|
||||
};
|
||||
|
||||
accountType = types.submodule {
|
||||
options = {
|
||||
name = mkOption { type = types.nonEmptyStr; };
|
||||
realName = mkOption { type = types.nonEmptyStr; };
|
||||
homeDirectory = mkOption { type = types.nonEmptyStr; };
|
||||
nixosConfigurationPath = mkOption { type = types.nonEmptyStr; };
|
||||
emails = mkOption { type = types.attrsOf emailType; };
|
||||
primaryEmail = mkOption { type = types.nonEmptyStr; };
|
||||
};
|
||||
};
|
||||
|
||||
accountOption = mkOption {
|
||||
type = accountType;
|
||||
apply =
|
||||
account:
|
||||
assert lib.assertMsg (builtins.hasAttr account.primaryEmail account.emails)
|
||||
"facts.account.primaryEmail must name an entry in facts.account.emails";
|
||||
account;
|
||||
};
|
||||
|
||||
sshKeyType = types.submodule {
|
||||
options = {
|
||||
publicKey = mkOption { type = types.nonEmptyStr; };
|
||||
privateKeyPath = mkOption {
|
||||
type = types.nullOr types.nonEmptyStr;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
displayType = types.submodule {
|
||||
options = {
|
||||
x = mkOption {
|
||||
type = types.int;
|
||||
default = 0;
|
||||
};
|
||||
y = mkOption {
|
||||
type = types.int;
|
||||
default = 0;
|
||||
};
|
||||
primary = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
scale = mkOption {
|
||||
type = types.nullOr types.number;
|
||||
default = null;
|
||||
};
|
||||
width = mkOption {
|
||||
type = types.nullOr types.ints.positive;
|
||||
default = null;
|
||||
};
|
||||
height = mkOption {
|
||||
type = types.nullOr types.ints.positive;
|
||||
default = null;
|
||||
};
|
||||
refresh = mkOption {
|
||||
type = types.nullOr types.number;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
displaysOption = mkOption {
|
||||
type = types.attrsOf displayType;
|
||||
default = { };
|
||||
apply =
|
||||
displays:
|
||||
assert lib.assertMsg (lib.all (
|
||||
display:
|
||||
let
|
||||
values = [
|
||||
display.width
|
||||
display.height
|
||||
display.refresh
|
||||
];
|
||||
in
|
||||
lib.all (value: value == null) values || lib.all (value: value != null) values
|
||||
) (builtins.attrValues displays)) "display width, height, and refresh must be supplied together";
|
||||
displays;
|
||||
};
|
||||
|
||||
machineType =
|
||||
{
|
||||
withName ? false,
|
||||
}:
|
||||
types.submodule (
|
||||
{ config, ... }:
|
||||
{
|
||||
options = {
|
||||
system = mkOption { type = types.nonEmptyStr; };
|
||||
stateVersion = mkOption { type = types.nonEmptyStr; };
|
||||
hmStateVersion = mkOption {
|
||||
type = types.nonEmptyStr;
|
||||
default = config.stateVersion;
|
||||
};
|
||||
syncthingId = mkOption {
|
||||
type = types.nullOr types.nonEmptyStr;
|
||||
default = null;
|
||||
};
|
||||
sshKeys = mkOption {
|
||||
type = types.attrsOf sshKeyType;
|
||||
default = { };
|
||||
};
|
||||
displays = displaysOption;
|
||||
}
|
||||
// lib.optionalAttrs withName {
|
||||
name = mkOption { type = types.nonEmptyStr; };
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
endpointType = types.submodule (
|
||||
{ config, ... }:
|
||||
{
|
||||
options = {
|
||||
scheme = mkOption {
|
||||
type = types.enum [
|
||||
"http"
|
||||
"https"
|
||||
];
|
||||
};
|
||||
domain = mkOption { type = types.nonEmptyStr; };
|
||||
origin = mkOption {
|
||||
type = types.nonEmptyStr;
|
||||
readOnly = true;
|
||||
default = "${config.scheme}://${config.domain}";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
externalDeviceType = types.submodule {
|
||||
options.syncthingId = mkOption {
|
||||
type = types.nullOr types.nonEmptyStr;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
topologyType = types.submodule {
|
||||
options.server = mkOption {
|
||||
type = types.submodule {
|
||||
options = {
|
||||
machine = mkOption { type = types.nonEmptyStr; };
|
||||
sshAlias = mkOption { type = types.nonEmptyStr; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
factsType =
|
||||
{
|
||||
withMachine ? false,
|
||||
}:
|
||||
types.submodule {
|
||||
options = {
|
||||
account = accountOption;
|
||||
machines = mkOption { type = types.attrsOf (machineType { }); };
|
||||
services = mkOption { type = types.attrsOf endpointType; };
|
||||
externalDevices = mkOption {
|
||||
type = types.attrsOf externalDeviceType;
|
||||
default = { };
|
||||
};
|
||||
topology = mkOption { type = topologyType; };
|
||||
}
|
||||
// lib.optionalAttrs withMachine {
|
||||
machine = mkOption { type = machineType { withName = true; }; };
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.facts = factsOption;
|
||||
options.facts = mkOption {
|
||||
type = factsType { };
|
||||
};
|
||||
|
||||
config = {
|
||||
facts = {
|
||||
@@ -17,11 +196,11 @@ in
|
||||
realName = "Jelle Spreeuwenberg";
|
||||
homeDirectory = "/home/${name}";
|
||||
nixosConfigurationPath = "${homeDirectory}/.config/nixos";
|
||||
primaryEmail = "personal";
|
||||
|
||||
emails = {
|
||||
personal = {
|
||||
address = "mail@jelles.net";
|
||||
primary = true;
|
||||
type = "mxrouting";
|
||||
};
|
||||
old = {
|
||||
@@ -37,61 +216,59 @@ in
|
||||
type = "office365";
|
||||
};
|
||||
};
|
||||
|
||||
primaryEmail = emails.personal;
|
||||
};
|
||||
|
||||
services = {
|
||||
actual = {
|
||||
scheme = "https";
|
||||
domain = "finance.jelles.net";
|
||||
host = "127.0.0.1";
|
||||
port = 3000;
|
||||
url = "https://finance.jelles.net";
|
||||
};
|
||||
gitea = {
|
||||
scheme = "https";
|
||||
domain = "git.jelles.net";
|
||||
host = "127.0.0.1";
|
||||
port = 3001;
|
||||
url = "https://git.jelles.net/";
|
||||
};
|
||||
radicale = {
|
||||
scheme = "https";
|
||||
domain = "radicale.jelles.net";
|
||||
host = "127.0.0.1";
|
||||
port = 5232;
|
||||
url = "https://radicale.jelles.net/";
|
||||
};
|
||||
vaultwarden = {
|
||||
scheme = "https";
|
||||
domain = "vault.jelles.net";
|
||||
host = "127.0.0.1";
|
||||
port = 8100;
|
||||
url = "https://vault.jelles.net";
|
||||
};
|
||||
};
|
||||
|
||||
theme = import ./capabilities/_theme.nix;
|
||||
externalDevices.pixel-10.syncthingId = "MTJHEHA-UMZDQZ7-BTMRRLQ-Y7BFPUJ-ZTY6LZX-PDXV3IS-XVJCU7B-EPETBQZ";
|
||||
|
||||
topology.server = {
|
||||
machine = "orion";
|
||||
sshAlias = "orion";
|
||||
};
|
||||
};
|
||||
|
||||
flake.modules.nixos.facts = { lib, ... }: {
|
||||
options.facts = factsOption;
|
||||
flake.modules.nixos.facts = {
|
||||
options.facts = mkOption {
|
||||
type = factsType { withMachine = true; };
|
||||
};
|
||||
};
|
||||
|
||||
flake.modules.homeManager.facts =
|
||||
{ osConfig, ... }:
|
||||
{
|
||||
lib,
|
||||
osConfig ? { },
|
||||
...
|
||||
}:
|
||||
{
|
||||
options.facts = factsOption;
|
||||
options.facts = mkOption {
|
||||
type = factsType { withMachine = true; };
|
||||
};
|
||||
|
||||
config.facts = lib.optionalAttrs (osConfig ? facts) {
|
||||
config.facts = {
|
||||
inherit (osConfig.facts)
|
||||
account
|
||||
externalDevices
|
||||
machine
|
||||
machines
|
||||
services
|
||||
theme
|
||||
topology
|
||||
;
|
||||
services = lib.mapAttrs (_: service: {
|
||||
inherit (service) scheme domain;
|
||||
}) osConfig.facts.services;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user