This commit is contained in:
mjallen18
2025-12-14 21:50:50 -06:00
parent 0012a019fc
commit 34539045e5
41 changed files with 164 additions and 251 deletions

View File

@@ -1,6 +1,6 @@
{ lib, ... }:
{ lib, namespace, ... }:
let
inherit (lib.mjallen.file)
inherit (lib.${namespace}.file)
readFile
pathExists
safeImport

View File

@@ -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;
};
};
};

View File

@@ -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

View File

@@ -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;
};
};
};

View File

@@ -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;

View File

@@ -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,

View File

@@ -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 = {

View File

@@ -2,10 +2,11 @@
config,
lib,
pkgs,
namespace,
...
}:
let
cfg = config.mjallen.desktop.gnome;
cfg = config.${namespace}.desktop.gnome;
in
{
imports = [ ./options.nix ];

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.desktop.gnome = {
options.${namespace}.desktop.gnome = {
enable = mkEnableOption "enable gnome settings";
};
}

View File

@@ -1,7 +1,7 @@
{ config, lib, ... }:
{ config, lib, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.btop;
cfg = config.${namespace}.programs.btop;
in
{
imports = [ ./options.nix ];

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.programs.btop = {
options.${namespace}.programs.btop = {
enable = mkEnableOption "enable btop";
};
}

View File

@@ -2,11 +2,12 @@
config,
lib,
pkgs,
namespace,
...
}:
with lib;
let
cfg = config.mjallen.programs.hyprland;
cfg = config.${namespace}.programs.hyprland;
drawer = "nwg-drawer -fm nautilus -term kitty -mb 10 -mt 10 -ml 10 -mr 10 -pbuseicontheme -i ${config.stylix.icons.dark}";
in
{
@@ -66,7 +67,7 @@ in
xsettingsd
xwayland
pkgs.mjallen.pipewire-python
pkgs.${namespace}.pipewire-python
]
++ (if cfg.notificationDaemon == "mako" then [ mako ] else [ dunst ])
++ (if cfg.launcher == "wofi" then [ wofi ] else [ rofi ])

View File

@@ -1,7 +1,7 @@
{ lib, pkgs, ... }:
{ lib, pkgs, namespace, ... }:
with lib;
{
options.mjallen.programs.hyprland = {
options.${namespace}.programs.hyprland = {
enable = mkEnableOption "enable hyprland";
primaryDisplay = mkOption {

View File

@@ -1,7 +1,7 @@
{ lib, config, ... }:
{ lib, config, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.kitty;
cfg = config.${namespace}.programs.kitty;
in
{
imports = [ ./options.nix ];

View File

@@ -4,7 +4,7 @@ let
inherit (lib.${namespace}) mkOpt;
in
{
options.mjallen.programs.kitty = {
options.${namespace}.programs.kitty = {
enable = mkEnableOption "enable kitty terminal";
};
}

View File

@@ -1,7 +1,7 @@
{ config, lib, ... }:
{ config, lib, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.mako;
cfg = config.${namespace}.programs.mako;
in
{
imports = [ ./options.nix ];

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.programs.mako = {
options.${namespace}.programs.mako = {
enable = mkEnableOption "enable mako";
fontName = mkOption {

View File

@@ -2,11 +2,12 @@
config,
lib,
pkgs,
namespace,
...
}:
with lib;
let
cfg = config.mjallen.programs.nwg-dock;
cfg = config.${namespace}.programs.nwg-dock;
palette = import cfg.theme.file;
in
{

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.programs.nwg-dock = {
options.${namespace}.programs.nwg-dock = {
enable = mkEnableOption "enable nwg-dock";
};
}

View File

@@ -2,11 +2,12 @@
config,
lib,
pkgs,
namespace,
...
}:
with lib;
let
cfg = config.mjallen.programs.nwg-drawer;
cfg = config.${namespace}.programs.nwg-drawer;
palette = import cfg.theme.file;
in
{

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.programs.nwg-drawer = {
options.${namespace}.programs.nwg-drawer = {
enable = mkEnableOption "enable nwg-drawer";
};
}

View File

@@ -1,7 +1,7 @@
{ config, lib, ... }:
{ config, lib, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.nwg-panel;
cfg = config.${namespace}.programs.nwg-panel;
in
{
imports = [ ./options.nix ];

View File

@@ -1,7 +1,7 @@
{ lib, pkgs, ... }:
{ lib, pkgs, namespace, ... }:
with lib;
{
options.mjallen.programs.nwg-panel = {
options.${namespace}.programs.nwg-panel = {
enable = mkEnableOption "enable nwg-panel";
defaultApps = mkOption {

View File

@@ -1,7 +1,7 @@
{ config, lib, ... }:
{ config, lib, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.waybar;
cfg = config.${namespace}.programs.waybar;
baseStyle =
if cfg.style.file != null then

View File

@@ -1,4 +1,4 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
let
inherit (types)
@@ -13,7 +13,7 @@ let
;
in
{
options.mjallen.programs.waybar = {
options.${namespace}.programs.waybar = {
enable = mkEnableOption "Waybar status bar";
# Legacy/compat options (kept for backwards compatibility)

View File

@@ -6,7 +6,7 @@
...
}:
let
cfg = config.mjallen.programs.waybar;
cfg = config.${namespace}.programs.waybar;
pythonEnv = pkgs.python3.withPackages (_ps: [
pkgs.${namespace}.homeassistant-api

View File

@@ -2,10 +2,11 @@
config,
lib,
pkgs,
namespace,
...
}:
let
cfg = config.mjallen.programs.waybar;
cfg = config.${namespace}.programs.waybar;
waybar-weather = pkgs.writeScriptBin "waybar-weather" ''
#!/usr/bin/env nix-shell

View File

@@ -1,7 +1,7 @@
{ config, lib, ... }:
{ config, lib, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.wlogout;
cfg = config.${namespace}.programs.wlogout;
palette = import cfg.theme.file;
in
{

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.programs.wlogout = {
options.${namespace}.programs.wlogout = {
enable = mkEnableOption "enable wlogout";
};
}

View File

@@ -1,7 +1,7 @@
{ config, lib, ... }:
{ config, lib, namespace, ... }:
with lib;
let
cfg = config.mjallen.programs.wofi;
cfg = config.${namespace}.programs.wofi;
palette = import cfg.theme.file;
in
{

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.programs.wofi = {
options.${namespace}.programs.wofi = {
enable = mkEnableOption "enable wofi";
fontName = mkOption {

View File

@@ -1,13 +1,14 @@
{
config,
lib,
namespace,
...
}:
let
cfg = config.mjallen.shell-aliases;
cfg = config.${namespace}.shell-aliases;
in
{
options.mjallen.shell-aliases = {
options.${namespace}.shell-aliases = {
enable = lib.mkEnableOption "Common shell aliases";
buildHost = lib.mkOption {

View File

@@ -15,7 +15,7 @@ let
'';
in
{
options.mjallen.desktop.hyprland = {
options.${namespace}.desktop.hyprland = {
enable = mkEnableOption "enable hyprland desktop environment";
wallpaperSource = mkOpt (types.enum [

View File

@@ -29,7 +29,7 @@ let
{ }
else
{
address = cfg.ipv4.address;
address = "${cfg.ipv4.address}\\24";
gateway = cfg.ipv4.gateway;
dns = cfg.ipv4.dns;
}

View File

@@ -7,59 +7,42 @@
}:
with lib;
let
cfg = config.${namespace}.services.actual;
name = "actual";
cfg = config.${namespace}.services.${name};
actualConfig = {
services.actual = {
enable = true;
openFirewall = true;
settings = {
trustedProxies = [ "10.0.1.3" ];
port = cfg.port;
dataDir = cfg.dataDir;
serverFiles = "${cfg.dataDir}/server-files";
userFiles = "${cfg.dataDir}/user-files";
actualConfig = lib.${namespace}.mkModule rec {
inherit name;
description = "Actual Personal Finance Planner";
options = { };
moduleConfig = {
services.actual = {
enable = true;
openFirewall = true;
settings = {
trustedProxies = [ config.${namespace}.network.ipv4.address ];
port = cfg.port;
configDir = cfg.configDir;
serverFiles = "${cfg.configDir}/server-files";
userFiles = "${cfg.configDir}/user-files";
};
};
};
systemd.services = {
actual = {
environment.ACTUAL_CONFIG_PATH = lib.mkForce "${cfg.dataDir}/config.json";
serviceConfig = {
ExecStart = lib.mkForce "${lib.getExe pkgs.actual-server} --config ${cfg.dataDir}/config.json";
WorkingDirectory = lib.mkForce cfg.dataDir;
StateDirectoryMode = lib.mkForce 700;
DynamicUser = lib.mkForce false;
ProtectSystem = lib.mkForce "full";
systemd.services = lib.mkIf cfg.createUser {
actual = {
environment.ACTUAL_CONFIG_PATH = lib.mkForce "${cfg.configDir}/config.json";
serviceConfig = {
ExecStart = lib.mkForce "${lib.getExe pkgs.actual-server} --config ${cfg.configDir}/config.json";
WorkingDirectory = lib.mkForce cfg.configDir;
StateDirectoryMode = lib.mkForce 700;
DynamicUser = lib.mkForce false;
ProtectSystem = lib.mkForce "full";
};
};
};
};
users.users.actual = {
isSystemUser = true;
group = "actual";
home = cfg.dataDir;
};
users.groups.actual = { };
inherit config;
};
# Create reverse proxy configuration using mkReverseProxy
reverseProxyConfig = lib.${namespace}.mkReverseProxy {
name = "actual";
subdomain = cfg.reverseProxy.subdomain;
url = "http://${cfg.localAddress}:${toString cfg.port}";
middlewares = cfg.reverseProxy.middlewares;
};
fullConfig = {
"${namespace}".services.traefik = lib.mkIf cfg.reverseProxy.enable {
reverseProxies = [ reverseProxyConfig ];
};
}
// actualConfig;
in
{
imports = [ ./options.nix ];
config = mkIf cfg.enable fullConfig;
imports = [ actualConfig ];
}

View File

@@ -1,104 +0,0 @@
{
config,
pkgs,
lib,
namespace,
...
}:
with lib;
let
cfg = config.${namespace}.services.actual;
dataDir = "/data";
hostAddress = "10.0.1.3";
actualUserId = config.users.users.nix-apps.uid;
actualGroupId = config.users.groups.jallen-nas.gid;
actualConfig = {
services.actual = {
enable = true;
openFirewall = true;
settings = {
trustedProxies = [ hostAddress ];
port = cfg.port;
dataDir = dataDir;
serverFiles = "${dataDir}/server-files";
userFiles = "${dataDir}/user-files";
};
};
users.users.actual = {
isSystemUser = true;
uid = lib.mkForce actualUserId;
group = "actual";
};
users.groups = {
actual = {
gid = lib.mkForce actualGroupId;
};
};
# System packages
environment.systemPackages = with pkgs; [
sqlite
];
# Create and set permissions for required directories
system.activationScripts.actual-dirs = ''
mkdir -p ${dataDir}
chown -R actual:actual ${dataDir}
chmod -R 0700 ${dataDir}
'';
systemd.services = {
actual = {
environment.ACTUAL_CONFIG_PATH = lib.mkForce "${dataDir}/config.json";
serviceConfig = {
ExecStart = lib.mkForce "${lib.getExe pkgs.actual-server} --config ${dataDir}/config.json";
WorkingDirectory = lib.mkForce dataDir;
StateDirectory = lib.mkForce dataDir;
StateDirectoryMode = lib.mkForce 700;
DynamicUser = lib.mkForce false;
ProtectSystem = lib.mkForce null;
};
};
};
};
bindMounts = {
"${dataDir}" = {
hostPath = cfg.dataDir;
isReadOnly = false;
};
};
# Create reverse proxy configuration using mkReverseProxy
reverseProxyConfig = lib.${namespace}.mkReverseProxy {
name = "actual";
subdomain = cfg.reverseProxy.subdomain;
url = "http://${cfg.localAddress}:${toString cfg.port}";
middlewares = cfg.reverseProxy.middlewares;
};
actualContainer =
(lib.${namespace}.mkContainer {
name = "actual";
localAddress = cfg.localAddress;
ports = [ cfg.port ];
bindMounts = bindMounts;
config = actualConfig;
})
{ inherit lib; };
fullConfig = {
"${namespace}".services.traefik = lib.mkIf cfg.reverseProxy.enable {
reverseProxies = [ reverseProxyConfig ];
};
}
// actualContainer;
in
{
imports = [ ./options.nix ];
config = mkIf cfg.enable fullConfig;
}

View File

@@ -1,18 +0,0 @@
{ lib, namespace, ... }:
let
inherit (lib.${namespace}) mkOpt mkReverseProxyOpt;
in
with lib;
{
options.${namespace}.services.actual = {
enable = mkEnableOption "actual service";
port = mkOpt types.int 80 "Port for Actual to be hosted on";
localAddress = mkOpt types.str "127.0.0.1" "local address of the service";
dataDir = mkOpt types.str "" "Path to the data dir";
reverseProxy = mkReverseProxyOpt;
};
}

View File

@@ -7,7 +7,7 @@
with lib;
let
cfg = config.${namespace}.services.gitea;
rootUrl = "https://gitea.mjallen.dev/";
rootUrl = "https://gitea.${namespace}.dev/";
mailerPasswordFile = config.sops.secrets."jallen-nas/gitea/mail-key".path;
metricsTokenFile = config.sops.secrets."jallen-nas/gitea/metrics-key".path;

View File

@@ -1,7 +1,7 @@
{ lib, ... }:
{ lib, namespace, ... }:
with lib;
{
options.mjallen.sops = {
options.${namespace}.sops = {
enable = mkEnableOption "enable sops";
defaultSopsFile = mkOption {

View File

@@ -27,8 +27,7 @@
actual = {
enable = true;
port = 3333;
localAddress = "10.0.1.3";
dataDir = "/media/nas/main/nix-app-data/actual";
createUser = true;
reverseProxy = {
enable = true;
subdomain = "actual";

View File

@@ -110,7 +110,7 @@ in
network = {
hostName = "jallen-nas";
ipv4 = {
address = "10.0.1.3/24";
address = "10.0.1.3";
method = "manual";
gateway = "10.0.1.1";
interface = "enp197s0";