Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion wrapperModules/a/alacritty/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ in
'';
};
};
config.flags."--config-file" = tomlFmt.generate "alacritty.toml" config.settings;
config.flags."--config-file" = config.constructFiles.generatedConfig.path;
config.constructFiles.generatedConfig = {
content = builtins.toJSON config.settings;
relPath = "${config.binName}-config.toml";
builder = ''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
};
config.package = lib.mkDefault pkgs.alacritty;
config.meta.maintainers = [ wlib.maintainers.birdee ];
}
7 changes: 6 additions & 1 deletion wrapperModules/b/bottom/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ in
config = {
package = pkgs.bottom;
flags = {
"--config_location" = tomlFmt.generate "bottom-config.toml" config.settings;
"--config_location" = config.constructFiles.generatedConfig.path;
};
constructFiles.generatedConfig = {
content = builtins.toJSON config.settings;
relPath = "${config.binName}-config.toml";
builder = ''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
};
meta.maintainers = [ wlib.maintainers.rachitvrma ];
};
Expand Down
7 changes: 5 additions & 2 deletions wrapperModules/c/cava/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
}:
let
iniFmt = pkgs.formats.ini { };
configFile = iniFmt.generate "cava-config" config.settings;
in
{
imports = [ wlib.modules.default ];
Expand All @@ -24,7 +23,11 @@ in
config = {
package = lib.mkDefault pkgs.cava;
flags = {
"-p" = configFile;
"-p" = config.constructFiles.generatedConfig.path;
};
constructFiles.generatedConfig = {
content = lib.generators.toINI { } config.settings;
relPath = "${config.binName}.ini";
};
meta.maintainers = [ wlib.maintainers.rachitvrma ];
meta.platforms = lib.platforms.linux;
Expand Down
6 changes: 5 additions & 1 deletion wrapperModules/f/foot/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ in
'';
};
};
config.flags."--config" = iniFmt.generate "foot.ini" config.settings;
config.flags."--config" = config.constructFiles.generatedConfig.path;
config.constructFiles.generatedConfig = {
content = lib.generators.toINI { } config.settings;
relPath = "${config.binName}.ini";
};
config.filesToPatch = [ "share/systemd/user/*.service" ];
config.package = lib.mkDefault pkgs.foot;
config.meta.maintainers = [ wlib.maintainers.birdee ];
Expand Down
6 changes: 5 additions & 1 deletion wrapperModules/f/fuzzel/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ in
};
config.flagSeparator = "=";
config.flags = {
"--config" = iniFmt.generate "fuzzel.ini" config.settings;
"--config" = config.constructFiles.generatedConfig.path;
};
config.constructFiles.generatedConfig = {
content = lib.generators.toINI { } config.settings;
relPath = "${config.binName}.ini";
};
config.package = lib.mkDefault pkgs.fuzzel;
config.meta.maintainers = [ wlib.maintainers.birdee ];
Expand Down
117 changes: 74 additions & 43 deletions wrapperModules/h/helix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,12 @@
}:
let
tomlFmt = pkgs.formats.toml { };
conf =
let
base = tomlFmt.generate "helix-config" config.settings;
in
if config.extraSettings != "" then
pkgs.concatText "helix-config" [
base
(pkgs.writeText "extraSettings" config.extraSettings)
]
else
base;
langs = tomlFmt.generate "helix-languages-config" config.languages;
ignore = pkgs.writeText "helix-ignore" (lib.strings.concatLines config.ignores);
themes = lib.mapAttrsToList (
name: value:
let
fname = "helix-theme-${name}";
in
{
name = "themes/${name}.toml";
path = if lib.isString value then pkgs.writeText fname value else (tomlFmt.generate fname value);
}
) config.themes;
hasConfig =
config.settings != { }
|| config.extraSettings != ""
|| config.languages != { }
|| config.ignores != [ ]
|| config.themes != { };
in
{
imports = [ wlib.modules.default ];
Expand All @@ -47,7 +30,6 @@ in
default = "";
description = ''
Extra lines appended to the config file.
This can be used to maintain order for settings.
'';
};
languages = lib.mkOption {
Expand Down Expand Up @@ -79,27 +61,76 @@ in
The format is the same as in .gitignore.
'';
};
generatedConfig.output = lib.mkOption {
type = lib.types.str;
default = config.outputName;
description = ''
The derivation output for the config generated by this wrapper module
'';
};
generatedConfig.placeholder = lib.mkOption {
type = lib.types.str;
default = "${placeholder config.generatedConfig.output}/${config.binName}-config";
readOnly = true;
description = ''
The placeholder accessible in the wrapper derivation build script for the config generated by this wrapper module
'';
};
};
config.package = lib.mkDefault pkgs.helix;
config.env = {
XDG_CONFIG_HOME = pkgs.linkFarm "helix-merged-config" (
map
(a: {
inherit (a) path;
name = "helix/" + a.name;
})
(
let
entry = name: path: { inherit name path; };
in
[
(entry "config.toml" conf)
(entry "languages.toml" langs)
(entry "ignore" ignore)
]
++ themes
)
);
config.env.XDG_CONFIG_HOME = lib.mkIf hasConfig config.generatedConfig.placeholder;
config.passthru = lib.optionalAttrs hasConfig {
generatedConfig = "${
config.wrapper.${config.generatedConfig.output}
}/${config.binName}-config/helix";
};
config.drv.extraSettings = config.extraSettings;
config.drv.passAsFile = [ "extraSettings" ];
config.constructFiles = {
config = lib.mkIf (config.settings != { } && config.extraSettings != "") {
relPath = lib.mkOverride 0 "${config.binName}-config/helix/config.toml";
output = lib.mkOverride 0 config.generatedConfig.output;
content = builtins.toJSON config.settings;
builder = ''
mkdir -p "$(dirname "$2")" && \
${pkgs.remarshal}/bin/json2toml "$1" "$2" && \
cat "$extraSettingsPath" >> "$2"
'';
};
languages = lib.mkIf (config.languages != { }) {
relPath = lib.mkOverride 0 "${config.binName}-config/helix/languages.toml";
output = lib.mkOverride 0 config.generatedConfig.output;
content = builtins.toJSON config.languages;
builder = ''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
};
ignore = lib.mkIf (config.ignores != [ ]) {
relPath = lib.mkOverride 0 "${config.binName}-config/helix/ignore";
output = lib.mkOverride 0 config.generatedConfig.output;
content = lib.strings.concatLines config.ignores;
};
}
// lib.pipe config.themes [
(lib.filterAttrs (_: theme: theme != { }))
(lib.mapAttrsToList (
name: theme:
lib.nameValuePair name {
relPath = lib.mkOverride 0 "${config.binName}-config/helix/themes/${name}.toml";
output = lib.mkOverride 0 config.generatedConfig.output;
content = if builtins.isString theme then theme else builtins.toJSON theme;
${if builtins.isString theme then null else "builder"} =
''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
}
))
(lib.imap0 (
i: v:
v
// {
value = v.value // {
key = "theme_${toString i}";
};
}
))
builtins.listToAttrs
];
config.meta.maintainers = [ wlib.maintainers.birdee ];
}
7 changes: 6 additions & 1 deletion wrapperModules/j/jujutsu/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ in
config = {
package = lib.mkDefault pkgs.jujutsu;
env = {
JJ_CONFIG = builtins.toString (tomlFmt.generate "jujutsu.toml" config.settings);
JJ_CONFIG = config.constructFiles.generatedConfig.path;
};
constructFiles.generatedConfig = {
content = builtins.toJSON config.settings;
relPath = "${config.binName}-config.toml";
builder = ''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
};

meta.maintainers = [ wlib.maintainers.birdee ];
Expand Down
12 changes: 10 additions & 2 deletions wrapperModules/m/mako/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ in
options = {
"--config" = lib.mkOption {
type = wlib.types.file pkgs;
default.path = iniFormat.generate "mako-settings" { globalSection = config.settings; };
default.path = config.constructFiles.generatedConfig.path;
default.content = "";
description = ''
Path to the generated Mako configuration file.

Expand Down Expand Up @@ -51,7 +52,14 @@ in
"share/systemd/user/*.service"
"lib/systemd/user/*.service"
];

config.constructFiles.generatedConfig = {
content =
if config."--config".content or "" != "" then
config."--config".content
else
lib.generators.toINIWithGlobalSection { } { globalSection = config.settings; };
relPath = "${config.binName}-config.ini";
};
config.package = lib.mkDefault pkgs.mako;

config.meta.maintainers = [ wlib.maintainers.birdee ];
Expand Down
13 changes: 11 additions & 2 deletions wrapperModules/n/notmuch/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ in
};
configFile = lib.mkOption {
type = wlib.types.file pkgs;
default.path = iniFmt.generate "notmuch.ini" config.settings;
default.path = config.constructFiles.generatedConfig.path;
default.content = "";
description = ''
Path or inline definition of the generated Notmuch configuration file.

Expand All @@ -44,7 +45,15 @@ in
'';
};
};
config.package = pkgs.notmuch;
config.constructFiles.generatedConfig = {
content =
if config.configFile.content or "" != "" then
config.configFile.content
else
lib.generators.toINI { } config.settings;
relPath = "${config.binName}.ini";
};
config.package = lib.mkDefault pkgs.notmuch;
config.env.NOTMUCH_CONFIG = config.configFile.path;
config.meta.maintainers = [ wlib.maintainers.birdee ];
}
7 changes: 6 additions & 1 deletion wrapperModules/t/tealdeer/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ in
};
};
config.flags = {
"--config-path" = tomlFmt.generate "tealdeer.toml" config.settings;
"--config-path" = config.constructFiles.generatedConfig.path;
};
config.constructFiles.generatedConfig = {
content = builtins.toJSON config.settings;
relPath = "${config.binName}-config.toml";
builder = ''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
};
config.package = lib.mkDefault pkgs.tealdeer;
meta.maintainers = [ wlib.maintainers.birdee ];
Expand Down
5 changes: 2 additions & 3 deletions wrapperModules/y/yazi/check.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
self,
}:
let
yaziWrapper = self.wrappers.yazi.apply { inherit pkgs; };
cfgdir = yaziWrapper.env.YAZI_CONFIG_HOME.data;
yaziWrapper = self.wrappers.yazi.wrap { inherit pkgs; };
in
pkgs.runCommand "yazi-test" { } ''
"${yaziWrapper.wrapper}/bin/yazi" --debug | grep "${cfgdir}"
"${yaziWrapper}/bin/yazi" --debug | grep "${yaziWrapper.generatedConfig}"
touch $out
''
68 changes: 41 additions & 27 deletions wrapperModules/y/yazi/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
}:
let
tomlFmt = pkgs.formats.toml { };

yazi = tomlFmt.generate "yazi" config.settings.yazi;
keymap = tomlFmt.generate "keymap" config.settings.keymap;
theme = tomlFmt.generate "theme" config.settings.theme;
vfs = tomlFmt.generate "vfs" config.settings.vfs;
package = tomlFmt.generate "package" config.settings.package;
in
{
imports = [ wlib.modules.default ];
Expand Down Expand Up @@ -437,28 +431,48 @@ in
};
};
};
options.generatedConfig.output = lib.mkOption {
type = lib.types.str;
default = config.outputName;
description = ''
The derivation output for the config generated by this wrapper module
'';
};
options.generatedConfig.placeholder = lib.mkOption {
type = lib.types.str;
default = "${placeholder config.generatedConfig.output}/${config.binName}-config";
readOnly = true;
description = ''
The placeholder accessible in the wrapper derivation build script for the config generated by this wrapper module
'';
};

config.package = lib.mkDefault pkgs.yazi;
config.env = {
YAZI_CONFIG_HOME = pkgs.linkFarm "yazi-merged-config" (
map
(a: {
inherit (a) path;
name = a.name;
})
(
let
entry = name: path: { inherit name path; };
in
[
(entry "yazi.toml" yazi)
(entry "keymap.toml" keymap)
(entry "theme.toml" theme)
(entry "vfs.toml" vfs)
(entry "package.toml" package)
]
)
);
};
config.env.YAZI_CONFIG_HOME = config.generatedConfig.placeholder;
# make `finalpackage.generatedConfig` point to the generated config so it can be used from outside of the wrapper module
config.passthru.generatedConfig = "${
config.wrapper.${config.generatedConfig.output}
}/${config.binName}-config";
# using constructFiles instead of (pkgs.formats.toml {}).generate allows placeholders to refer to the final wrapper derivation in the options.
config.constructFiles =
builtins.mapAttrs
(n: v: {
# generate the directory of toml files
# use lib.mkOverride 0 to force the value to make sure they stay together
relPath = lib.mkOverride 0 "${config.binName}-config/${n}.toml";
output = lib.mkOverride 0 config.generatedConfig.output;
content = builtins.toJSON v;
# redefine builder to convert the result to toml.
# This is how pkgs.format.toml works
# https://github.com/NixOS/nixpkgs/blob/27298c9e6596851fe781e04e54704d705d91f38b/pkgs/pkgs-lib/formats.nix#L455-L477
builder = ''mkdir -p "$(dirname "$2")" && ${pkgs.remarshal}/bin/json2toml "$1" "$2"'';
})
{
yazi = config.settings.yazi;
keymap = config.settings.keymap;
theme = config.settings.theme;
vfs = config.settings.vfs;
package = config.settings.package;
};
config.meta.maintainers = [ wlib.maintainers.apetrovic6 ];
}
Loading