Skip to content
Closed
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This library provides two main components:
vo=gpu
hwdec=auto
'';
"mpv.input".content = ''
"input.conf".content = ''
WHEEL_UP seek 10
WHEEL_DOWN seek -10
'';
Expand Down Expand Up @@ -140,12 +140,14 @@ Arguments:
- Example: `[ "--silent" "--connect-timeout" "30" ]`
- If provided, overrides automatic generation from `flags`
- `preHook`: Shell script executed before the command (default: `""`)
- `postHook`: Shell script executed after the command. This will leave a bash process running, use with caution (default: `""`)
- `passthru`: Additional attributes for the derivation's passthru (default: `{}`)
- `aliases`: List of additional symlink names for the executable (default: `[]`)
- `filesToPatch`: List of file paths (glob patterns) relative to package root to patch for self-references (default: `["share/applications/*.desktop"]`)
- Example: `["bin/*", "lib/*.sh"]` to replace original package paths with wrapped package paths
- Desktop files are patched by default to update Exec= and Icon= paths
- `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (default: `[]`)
- `patchHook`: Shell script that runs after patchPhase to modify the wrapper package files (default: `""`)
- `wrapper`: Custom wrapper function (optional, overrides default exec wrapper)

The function:
Expand All @@ -170,9 +172,12 @@ Built-in options (always available):
- `flagSeparator`: Separator between flag name and value (default: `" "`)
- `args`: Command-line arguments list (auto-generated from `flags` if not provided)
- `env`: Environment variables
- `preHook`: Shell script executed before the command (default: `""`)
- `postHook`: Shell script executed after the command. This will leave a bash process running, use with caution (default: `""`)
- `passthru`: Additional passthru attributes
- `filesToPatch`: List of file paths (glob patterns) to patch for self-references (default: `["share/applications/*.desktop"]`)
- `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (default: `[]`)
- `patchHook`: Shell script that runs after patchPhase to modify the wrapper package files (default `""`)
- `wrapper`: The resulting wrapped package (read-only, auto-generated from other options)
- `apply`: Function to extend the configuration with additional modules (read-only)

Expand Down Expand Up @@ -231,7 +236,7 @@ Wraps mpv with configuration file support and script management:
vo=gpu
profile=gpu-hq
'';
"mpv.input".content = ''
"input.conf".content = ''
RIGHT seek 5
LEFT seek -5
'';
Expand Down
4 changes: 3 additions & 1 deletion checks/formatting.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
}:

pkgs.runCommand "formatting-check" { } ''
${pkgs.lib.getExe self.formatter.${pkgs.system}} --no-cache --fail-on-change ${../.}
${
pkgs.lib.getExe self.formatter.${pkgs.stdenv.hostPlatform.system}
} --no-cache --fail-on-change ${../.}
touch $out
''
42 changes: 42 additions & 0 deletions checks/patchHook.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
pkgs,
self,
}:

let
# Create a dummy package with a desktop file that references itself
dummyPackage =
(pkgs.runCommand "dummy-app" { } ''
# empty dir as a package
mkdir -p $out
'')
// {
meta.mainProgram = "dummy-app";
};

# Wrap the package
wrappedPackage = self.lib.wrapPackage {
inherit pkgs;
package = dummyPackage;
patchHook = ''
touch $out/test
'';
};

in
pkgs.runCommand "patchHook-test"
{
wrappedPath = "${wrappedPackage}";
}
''
echo "Testing patchHook functionality..."
echo "Wrapped package path: $wrappedPath"

if [ ! -f "$wrappedPath/test" ]; then
echo "FAIL: file not created in patched package"
exit 1
fi

echo "SUCCESS: patchHook executed correctly"
touch $out
''
19 changes: 15 additions & 4 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,14 @@ let
- `flagSeparator`: Separator between flag names and values when generating args from flags (optional, defaults to " ")
- `args`: List of command-line arguments like argv in execve (optional, auto-generated from flags if not provided)
- `preHook`: Shell script to run before executing the command (optional)
- `postHook`: Shell script to run after executing the command, removes the `exec` call. use with care (optional)
- `passthru`: Attribute set to pass through to the wrapped derivation (optional)
- `aliases`: List of additional names to symlink to the wrapped executable (optional)
- `filesToPatch`: List of file paths (glob patterns) to patch for self-references (optional, defaults to ["share/applications/*.desktop"])
- `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (optional, defaults to [])
- `patchHook`: Shell script that runs after patchPhase to modify the wrapper package files (optional)
- `wrapper`: Custom wrapper function (optional, defaults to exec'ing the original binary with args)
- Called with { env, flags, args, envString, flagsString, exePath, preHook }
- Called with { env, flags, args, envString, flagsString, exePath, preHook, postHook }

# Example

Expand Down Expand Up @@ -445,30 +447,33 @@ let
# " " for "--flag value" or "=" for "--flag=value"
args ? generateArgsFromFlags flags flagSeparator,
preHook ? "",
postHook ? "",
passthru ? { },
aliases ? [ ],
# List of file paths (glob patterns) relative to package root to patch for self-references (e.g., ["bin/*", "lib/*.sh"])
filesToPatch ? [ "share/applications/*.desktop" ],
# List of file paths (glob patterns) to exclude from the wrapped package (e.g., ["bin/unwanted-*", "share/doc/*"])
filesToExclude ? [ ],
patchHook ? "",
wrapper ? (
{
exePath,
flagsString,
envString,
preHook,
postHook,
...
}:
''
${envString}
${preHook}
exec ${exePath}${flagsString} "$@"
${lib.optionalString (postHook == "") "exec"} ${exePath}${flagsString} "$@"
${postHook}
''
),
}@funcArgs:
let
# lndir was moved from xorg.lndir to lndir in https://github.com/NixOS/nixpkgs/pull/402102
lndir = if pkgs ? xorg.lndir then pkgs.xorg.lndir else pkgs.lndir;
inherit (pkgs) lndir;

# Generate environment variable exports
envString =
Expand Down Expand Up @@ -496,6 +501,7 @@ let
flagsString
exePath
preHook
postHook
;
};

Expand All @@ -512,6 +518,7 @@ let
binName ? null,
filesToPatch ? [ ],
filesToExclude ? [ ],
patchHook ? "",
...
}@args:
pkgs.stdenv.mkDerivation (
Expand Down Expand Up @@ -567,6 +574,7 @@ let
done
'') filesToPatch}
''}
${patchHook}

# Create symlinks for aliases
${lib.optionalString (aliases != [ ] && binName != null) ''
Expand Down Expand Up @@ -605,6 +613,7 @@ let
"binName"
"filesToPatch"
"filesToExclude"
"patchHook"
])
);

Expand Down Expand Up @@ -639,6 +648,7 @@ let
binName
filesToPatch
filesToExclude
patchHook
;
passthru =
(package.passthru or { })
Expand All @@ -649,6 +659,7 @@ let
flags
args
preHook
postHook
aliases
;
override =
Expand Down
26 changes: 26 additions & 0 deletions lib/modules/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@
Example: [ "bin/unwanted-tool" "share/applications/*.desktop" ]
'';
};
options.patchHook = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Shell script that runs after patchPhase to modify the wrapper package files.
'';
};
options.preHook = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Shell script to run before executing the command.
'';
};
options.postHook = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Shell script to run after executing the command.
Removes the `exec` call in the wrapper script which will leave a bash process
in the background, therefore use with care.
'';
};
options.exePath = lib.mkOption {
type = lib.types.path;
description = ''
Expand Down Expand Up @@ -123,6 +146,9 @@
env = config.env;
filesToPatch = config.filesToPatch;
filesToExclude = config.filesToExclude;
preHook = config.preHook;
postHook = config.postHook;
patchHook = config.patchHook;
passthru = {
configuration = config;
}
Expand Down
38 changes: 38 additions & 0 deletions modules/fastfetch/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
config,
lib,
wlib,
...
}:
let
jsonFmt = config.pkgs.formats.json { };
in
{
_class = "wrapper";
options = {
settings = lib.mkOption {
type = jsonFmt.type;
default = { };
description = ''
fastfetch settings
see <https://github.com/fastfetch-cli/fastfetch/wiki/Configuration>
'';
};
"config.jsonc" = lib.mkOption {
type = wlib.types.file config.pkgs;
default.path = jsonFmt.generate "fastfetch-config" config.settings;
description = "fastfetch config file";
};
};
config = {
package = config.pkgs.fastfetch;
flags."--config" = "${config."config.jsonc".path}";
meta.maintainers = [
{
name = "holly";
github = "hollymlem";
githubId = 35699052;
}
];
};
}
29 changes: 21 additions & 8 deletions modules/foot/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
...
}:
let
iniFmt = config.pkgs.formats.ini {
iniFmt = config.pkgs.formats.iniWithGlobalSection {
# from https://github.com/NixOS/nixpkgs/blob/89f10dc1a8b59ba63f150a08f8cf67b0f6a2583e/nixos/modules/programs/foot/default.nix#L11-L29
listsAsDuplicateKeys = true;
mkKeyValue =
Expand All @@ -30,7 +30,12 @@ in
_class = "wrapper";
options = {
settings = lib.mkOption {
inherit (iniFmt) type;
type = lib.types.attrsOf (
lib.types.oneOf [
iniFmt.lib.types.atom
(lib.types.attrsOf iniFmt.lib.types.atom)
]
);
default = { };
description = ''
Configuration of foot terminal.
Expand All @@ -40,13 +45,21 @@ in
"foot.ini" = lib.mkOption {
type = wlib.types.file config.pkgs;
description = "foot.init configuration file.";
default.path = iniFmt.generate "foot.ini" config.settings;
default.path = iniFmt.generate "foot.ini" {
globalSection = lib.filterAttrs (name: value: builtins.typeOf value != "set") config.settings;
sections = lib.filterAttrs (name: value: builtins.typeOf value == "set") config.settings;
};
};
};
config.flags = {
"--config" = toString config."foot.ini".path;
config = {
filesToPatch = [ "share/systemd/user/foot-server.service" ];
flags = {
"--config" = toString config."foot.ini".path;
};
package = config.pkgs.foot;
meta = {
maintainers = [ lib.maintainers.randomdude ];
platforms = lib.platforms.linux;
};
};
config.package = config.pkgs.foot;
config.meta.maintainers = [ lib.maintainers.randomdude ];
config.meta.platforms = lib.platforms.linux;
}
32 changes: 20 additions & 12 deletions modules/ghostty/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,25 @@ in
'';
};
};
config.flagSeparator = "=";
config.flags = {
"--config-file" = toString config.configFile.path;
config = {
filesToPatch = [
"share/dbus-1/services/com.mitchellh.ghostty.service"
"share/systemd/user/app-com.mitchellh.ghostty.service"
];
flagSeparator = "=";
flags = {
"--config-file" = toString config.configFile.path;
};
package = config.pkgs.ghostty;
meta = {
platforms = lib.platforms.linux;
maintainers = [
{
name = "turbio";
github = "turbio";
githubId = 1428207;
}
];
};
};
config.package = config.pkgs.ghostty;
config.meta.platforms = lib.platforms.linux;
config.meta.maintainers = [
{
name = "turbio";
github = "turbio";
githubId = 1428207;
}
];
}
Loading