blob: 87639c6137ff4cea6e66fbe746aef4bc166c2650 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{
lib,
pkgs,
config,
}:
{
# We define mkScript as a function that takes the context it needs
mkScript =
name: path: env:
let
# Logic inside the helper
defaultShell =
if (config.tools.zsh.enable or false) then
(lib.getExe config.programs.zsh.package)
else
"/usr/bin/env sh";
envVars = lib.concatStringsSep "\n" (
lib.mapAttrsToList (n: v: "export ${n}=\"${toString v}\"") env
);
in
pkgs.writeTextFile {
inherit name;
executable = true;
destination = "/bin/${name}";
text = ''
#!${defaultShell}
${envVars}
${builtins.readFile path}
'';
};
}
|