write mkConfWrapper function for helix

this makes helix use the user config instead, if it exists
This commit is contained in:
Elec3137 2026-02-10 09:15:59 -08:00
commit 332802c981
3 changed files with 40 additions and 12 deletions

View file

@ -2,6 +2,7 @@
pkgs,
lib,
config,
owoLib,
...
}:
@ -33,15 +34,9 @@ in
config = lib.mkIf cfg.enable {
environment.systemPackages = [
(pkgs.symlinkJoin {
inherit name;
paths = [ cfg.package ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/hx \
--add-flags "-c" \
--add-flags "${pkgs.writeText "${name}.toml" cfg.extraConfig}"
'';
(owoLib.mkConfWrapper "hx" cfg.package {
globalConfig = pkgs.writeText "${name}.toml" cfg.extraConfig;
userConfig = "$HOME/${name}/config.toml";
})
];

View file

@ -1,5 +1,6 @@
{
lib,
pkgs,
config,
...
}:
@ -18,8 +19,12 @@ in
enable = lib.mkEnableOption "common settings";
};
config = lib.mkIf cfg.enable {
nixowos.cli.enable = true;
nixowos.system.enable = true;
config = {
_module.args.owoLib = pkgs.callPackage ./lib { };
nixowos = lib.mkIf cfg.enable {
cli.enable = true;
system.enable = true;
};
};
}

28
lib/default.nix Normal file
View file

@ -0,0 +1,28 @@
{
pkgs,
...
}:
{
mkConfWrapper =
name: package:
{
globalConfig,
userConfig ? "$HOME/${name}/${name}.conf",
configArg ? "-c ",
excecutable ? "${package}/bin/${name}",
}:
pkgs.writeShellApplication {
inherit name;
runtimeInputs = [ package ];
text = ''
if test -r "${userConfig}"; then
exec -a "$0" "${excecutable}" "$@"
else
exec -a "$0" "${excecutable}" ${configArg}"${globalConfig}" "$@"
fi
'';
};
}