mkModule
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{ lib, ... }:
|
||||
{ lib, namespace, ... }:
|
||||
let
|
||||
inherit (lib.mjallen.file)
|
||||
inherit (lib.${namespace}.file)
|
||||
readFile
|
||||
pathExists
|
||||
safeImport
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
namespace,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib.mjallen.module) mkModule mkOpt;
|
||||
inherit (lib.${namespace}.module) mkModule mkOpt;
|
||||
in
|
||||
mkModule {
|
||||
name = "sops";
|
||||
@@ -23,13 +24,13 @@ mkModule {
|
||||
];
|
||||
|
||||
sops = {
|
||||
inherit (config.mjallen.sops) defaultSopsFile;
|
||||
inherit (config.${namespace}.sops) defaultSopsFile;
|
||||
defaultSopsFormat = "yaml";
|
||||
|
||||
age = {
|
||||
generateKey = true;
|
||||
keyFile = "${config.home.homeDirectory}/.config/sops/age/keys.txt";
|
||||
sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ] ++ config.mjallen.sops.sshKeyPaths;
|
||||
sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ] ++ config.${namespace}.sops.sshKeyPaths;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Example usage of the reverse proxy utilities
|
||||
{ lib, ... }:
|
||||
{ lib, namespace, ... }:
|
||||
let
|
||||
inherit (lib.mjallen-lib.reverseproxy)
|
||||
inherit (lib.${namespace}-lib.reverseproxy)
|
||||
mkReverseProxy
|
||||
mkReverseProxies
|
||||
templates
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{ config, lib, ... }:
|
||||
{ config, lib, namespace, ... }:
|
||||
let
|
||||
inherit (lib.mjallen.module) mkModule mkOpt mkBoolOpt;
|
||||
inherit (lib.${namespace}.module) mkModule mkOpt mkBoolOpt;
|
||||
in
|
||||
mkModule {
|
||||
name = "sops";
|
||||
@@ -22,18 +22,18 @@ mkModule {
|
||||
};
|
||||
config = {
|
||||
sops = {
|
||||
inherit (config.mjallen.sops) defaultSopsFile validateSopsFiles;
|
||||
inherit (config.${namespace}.sops) defaultSopsFile validateSopsFiles;
|
||||
|
||||
age = {
|
||||
inherit (config.mjallen.sops) generateAgeKey;
|
||||
inherit (config.${namespace}.sops) generateAgeKey;
|
||||
|
||||
keyFile =
|
||||
if config.mjallen.sops.ageKeyPath != null then
|
||||
config.mjallen.sops.ageKeyPath
|
||||
if config.${namespace}.sops.ageKeyPath != null then
|
||||
config.${namespace}.sops.ageKeyPath
|
||||
else
|
||||
"${config.users.users.${config.mjallen.user.name}.home}/.config/sops/age/keys.txt";
|
||||
"${config.users.users.${config.${namespace}.user.name}.home}/.config/sops/age/keys.txt";
|
||||
|
||||
sshKeyPaths = config.mjallen.sops.sshKeyPaths;
|
||||
sshKeyPaths = config.${namespace}.sops.sshKeyPaths;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{ inputs, ... }:
|
||||
{ inputs, namespace, ... }:
|
||||
let
|
||||
inherit (inputs.self.mjallen-lib.system.common)
|
||||
inherit (inputs.self.${namespace}-lib.system.common)
|
||||
mkExtendedLib
|
||||
mkNixpkgsConfig
|
||||
mkHomeConfigs
|
||||
@@ -13,10 +13,10 @@ in
|
||||
nixosConfigurations =
|
||||
let
|
||||
# Get all systems
|
||||
allSystems = inputs.self.mjallen-lib.file.scanSystems ../systems;
|
||||
allSystems = inputs.self.${namespace}-lib.file.scanSystems ../systems;
|
||||
|
||||
# Filter for NixOS systems
|
||||
nixosSystems = inputs.self.mjallen-lib.file.filterNixOSSystems allSystems;
|
||||
nixosSystems = inputs.self.${namespace}-lib.file.filterNixOSSystems allSystems;
|
||||
in
|
||||
inputs.nixpkgs.lib.mapAttrs' (
|
||||
_name:
|
||||
@@ -74,7 +74,7 @@ in
|
||||
# Import all nixos modules recursively
|
||||
../${system}/${hostname}
|
||||
]
|
||||
++ (extendedLib.mjallen.file.importModulesRecursive ../modules/nixos);
|
||||
++ (extendedLib.${namespace}.file.importModulesRecursive ../modules/nixos);
|
||||
};
|
||||
}
|
||||
) nixosSystems;
|
||||
@@ -83,7 +83,7 @@ in
|
||||
homeConfigurations =
|
||||
let
|
||||
# Get all homes
|
||||
allHomes = inputs.self.mjallen-lib.file.scanHomes ../homes;
|
||||
allHomes = inputs.self.${namespace}-lib.file.scanHomes ../homes;
|
||||
in
|
||||
inputs.nixpkgs.lib.mapAttrs' (
|
||||
_name:
|
||||
@@ -125,7 +125,7 @@ in
|
||||
# Import the home configuration
|
||||
path
|
||||
]
|
||||
++ (extendedLib.mjallen.file.importModulesRecursive ../modules/home);
|
||||
++ (extendedLib.${namespace}.file.importModulesRecursive ../modules/home);
|
||||
};
|
||||
}
|
||||
) allHomes;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ inputs }:
|
||||
{ inputs, lib, namespace }:
|
||||
let
|
||||
inherit (inputs.nixpkgs.lib)
|
||||
mapAttrs
|
||||
@@ -28,23 +28,69 @@ rec {
|
||||
name,
|
||||
description ? "",
|
||||
options ? { },
|
||||
config ? { },
|
||||
moduleConfig ? { },
|
||||
domain ? "services",
|
||||
config
|
||||
}:
|
||||
{ lib, ... }:
|
||||
let
|
||||
cfg = config.${namespace}.${domain}.${name};
|
||||
|
||||
# Create reverse proxy configuration using mkReverseProxy
|
||||
reverseProxyConfig = lib.${namespace}.mkReverseProxy {
|
||||
inherit name;
|
||||
subdomain = cfg.reverseProxy.subdomain;
|
||||
url = "http://${config.${namespace}.network.ipv4.address}:${toString cfg.port}"; # TODO: address
|
||||
middlewares = cfg.reverseProxy.middlewares;
|
||||
};
|
||||
|
||||
defaultConfig = {
|
||||
${namespace}.services.traefik = lib.mkIf cfg.reverseProxy.enable {
|
||||
reverseProxies = [ reverseProxyConfig ];
|
||||
};
|
||||
|
||||
users = lib.mkIf cfg.createUser {
|
||||
users.${name} = {
|
||||
isSystemUser = true;
|
||||
group = name;
|
||||
home = cfg.configDir;
|
||||
};
|
||||
groups.${name} = { };
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d ${cfg.configDir} 0700 ${name} ${name} - -"
|
||||
"d ${cfg.configDir}/server-files 0700 ${name} ${name} - -"
|
||||
"d ${cfg.configDir}/user-files 0700 ${name} ${name} - -"
|
||||
];
|
||||
} // moduleConfig;
|
||||
in
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
options.mjallen.${name} = lib.mkOption {
|
||||
options.${namespace}.${domain}.${name} = lib.mkOption {
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
enable = lib.mkEnableOption description;
|
||||
|
||||
port = mkOpt types.int 80 "Port for ${name} to be hosted on";
|
||||
|
||||
configDir = mkOpt types.str "/media/nas/main/nix-app-data/${name}" "Path to the config dir";
|
||||
|
||||
dataDir = mkOpt types.str "/media/nas/main/${name}" "Path to the data dir";
|
||||
|
||||
createUser = mkBoolOpt false "create a user for this module/service";
|
||||
|
||||
reverseProxy = mkReverseProxyOpt;
|
||||
}
|
||||
// options;
|
||||
};
|
||||
default = { };
|
||||
};
|
||||
|
||||
config = lib.mkIf config.mjallen.${name}.enable config;
|
||||
config = lib.mkIf cfg.enable defaultConfig;
|
||||
};
|
||||
|
||||
|
||||
# container
|
||||
mkContainer =
|
||||
{
|
||||
name,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ inputs }:
|
||||
{ inputs, namespace }:
|
||||
let
|
||||
inherit (inputs.nixpkgs.lib) filterAttrs mapAttrs';
|
||||
in
|
||||
@@ -7,7 +7,7 @@ in
|
||||
flake: nixpkgs:
|
||||
nixpkgs.lib.extend (
|
||||
_final: _prev: {
|
||||
mjallen = flake.mjallen-lib;
|
||||
mjallen = flake.${namespace}-lib;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -30,7 +30,7 @@ in
|
||||
hostname,
|
||||
}:
|
||||
let
|
||||
inherit (flake.mjallen-lib.file) scanHomes;
|
||||
inherit (flake.${namespace}-lib.file) scanHomes;
|
||||
homesPath = ../../homes;
|
||||
allHomes = scanHomes homesPath;
|
||||
in
|
||||
@@ -59,7 +59,7 @@ in
|
||||
sharedModules = [
|
||||
{ _module.args.lib = extendedLib; }
|
||||
]
|
||||
++ (extendedLib.mjallen.file.importModulesRecursive ../../modules/home);
|
||||
++ (extendedLib.${namespace}.file.importModulesRecursive ../../modules/home);
|
||||
users = mapAttrs' (_name: homeConfig: {
|
||||
name = homeConfig.username;
|
||||
value = {
|
||||
|
||||
Reference in New Issue
Block a user