refactor: orion and base
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
{ lib, config, ... }:
|
||||
let
|
||||
nixosModules = config.flake.modules.nixos;
|
||||
hmModules = config.flake.modules.homeManager;
|
||||
|
||||
mkHost =
|
||||
machine:
|
||||
{ config, 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;
|
||||
}
|
||||
);
|
||||
|
||||
home-manager.users = lib.mapAttrs (
|
||||
_: account: {
|
||||
imports = [
|
||||
hmModules.meta
|
||||
account.baseModule
|
||||
];
|
||||
meta = {
|
||||
inherit machine account;
|
||||
};
|
||||
home.homeDirectory = account.homeDirectory;
|
||||
home.stateVersion = machine.hmStateVersion;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
mkWorkstationHost =
|
||||
machine:
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
(mkHost machine)
|
||||
nixosModules.workstation-base
|
||||
];
|
||||
|
||||
home-manager.users = lib.mapAttrs (
|
||||
_: account: {
|
||||
imports = [ account.workstationModule ];
|
||||
}
|
||||
);
|
||||
};
|
||||
in
|
||||
{
|
||||
options.repo.helpers = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.raw;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
config.repo.helpers = { inherit mkHost mkWorkstationHost; };
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
# Account types
|
||||
emailProviderType = lib.types.enum [
|
||||
"mxrouting"
|
||||
"office365"
|
||||
];
|
||||
|
||||
emailType = lib.types.submodule (
|
||||
{ ... }:
|
||||
{
|
||||
options = {
|
||||
address = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
primary = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
|
||||
type = lib.mkOption {
|
||||
type = emailProviderType;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
accountType = lib.types.submodule (
|
||||
{ name, config, ... }:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
realName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
homeDirectory = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/home/${config.name}";
|
||||
};
|
||||
|
||||
nixosConfigurationPath = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "${config.homeDirectory}/.config/nixos";
|
||||
};
|
||||
|
||||
emails = lib.mkOption {
|
||||
type = lib.types.attrsOf emailType;
|
||||
default = { };
|
||||
};
|
||||
|
||||
extraGroups = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
baseModule = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
|
||||
workstationModule = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
|
||||
primaryEmail = lib.mkOption {
|
||||
type = lib.types.nullOr emailType;
|
||||
readOnly = true;
|
||||
description = "Derived primary email entry for this user.";
|
||||
default =
|
||||
let
|
||||
emails = builtins.attrValues config.emails;
|
||||
in
|
||||
lib.findFirst (email: email.primary) null emails;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# Machine types
|
||||
displayType = lib.types.submodule (
|
||||
{ ... }:
|
||||
{
|
||||
options = {
|
||||
primary = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
|
||||
x = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 0;
|
||||
};
|
||||
|
||||
y = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 0;
|
||||
};
|
||||
|
||||
scale = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.float;
|
||||
default = 1.0;
|
||||
};
|
||||
|
||||
width = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
};
|
||||
|
||||
height = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
};
|
||||
|
||||
refresh = lib.mkOption {
|
||||
type = lib.types.float;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
machineType = lib.types.submodule (
|
||||
{ name, config, ... }:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
module = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
default = { };
|
||||
};
|
||||
|
||||
buildFunction = lib.mkOption {
|
||||
type = lib.types.functionTo lib.types.deferredModule;
|
||||
};
|
||||
|
||||
stateVersion = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
|
||||
hmStateVersion = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config.stateVersion;
|
||||
};
|
||||
|
||||
displays = lib.mkOption {
|
||||
type = lib.types.attrsOf displayType;
|
||||
default = { };
|
||||
};
|
||||
|
||||
accounts = lib.mkOption {
|
||||
type = lib.types.attrsOf accountType;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
options.repo = {
|
||||
accounts = lib.mkOption {
|
||||
type = lib.types.attrsOf accountType;
|
||||
default = { };
|
||||
};
|
||||
machines = lib.mkOption {
|
||||
type = lib.types.attrsOf machineType;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config.flake.modules.nixos.meta =
|
||||
{ config, ... }:
|
||||
{
|
||||
options.meta.machine = lib.mkOption {
|
||||
type = machineType;
|
||||
};
|
||||
};
|
||||
|
||||
config.flake.modules.homeManager.meta =
|
||||
{ config, ... }:
|
||||
{
|
||||
options.meta = {
|
||||
machine = lib.mkOption {
|
||||
type = machineType;
|
||||
};
|
||||
|
||||
account = lib.mkOption {
|
||||
type = accountType;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user