feat(downstream): add easy configuration overrides
- Introduce nomarchy.configOverrides option to map a user directory to ~/.config - Implement automatic merging of upstream defaults and user overrides - Use lib.mkDefault for all upstream mappings to allow granular HM overrides - Update installer template with usage examples
This commit is contained in:
@@ -1,26 +1,38 @@
|
||||
{ config, pkgs, ... }:
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
configDir = ../../config;
|
||||
|
||||
# Read the contents of the config directory
|
||||
# Read the contents of the upstream config directory
|
||||
configEntries = builtins.readDir configDir;
|
||||
|
||||
# Check for user overrides
|
||||
userConfigDir = config.nomarchy.configOverrides;
|
||||
userEntries = if userConfigDir != null && builtins.pathExists userConfigDir
|
||||
then builtins.readDir userConfigDir
|
||||
else {};
|
||||
|
||||
# Files to explicitly exclude (handled elsewhere or not intended for ~/.config/)
|
||||
excludedFiles = [
|
||||
"nomarchy.ttf"
|
||||
];
|
||||
|
||||
# Get all unique names from both sources
|
||||
allNames = lib.unique (builtins.attrNames configEntries ++ builtins.attrNames userEntries);
|
||||
|
||||
# Filter the entries
|
||||
validEntries = builtins.filter (name: !(builtins.elem name excludedFiles)) (builtins.attrNames configEntries);
|
||||
validEntries = builtins.filter (name: !(builtins.elem name excludedFiles)) allNames;
|
||||
|
||||
# Generate the xdg.configFile attribute set
|
||||
# If a name exists in userEntries, it takes precedence.
|
||||
# For directories, we use `recursive = true;` to allow the user to create their own files alongside the read-only defaults.
|
||||
makeMapping = name: {
|
||||
inherit name;
|
||||
value = {
|
||||
source = "${configDir}/${name}";
|
||||
recursive = configEntries.${name} == "directory";
|
||||
value = lib.mkDefault {
|
||||
source = if userEntries ? ${name}
|
||||
then "${userConfigDir}/${name}"
|
||||
else "${configDir}/${name}";
|
||||
recursive = (userEntries.${name} or configEntries.${name}) == "directory";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -73,5 +73,10 @@
|
||||
description = "System monospace font.";
|
||||
};
|
||||
};
|
||||
configOverrides = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = "Path to a directory containing configuration overrides.";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user