blob: 186b7a0e1ff6f8e64d2a1f64faf3c54e9caff8ea [file] [log] [blame]
Skyler Grey3a9a2b12023-02-13 08:04:05 +00001{ pkgs, utils }:
2let
3 lib = pkgs.lib;
4in
5file: lib.pipe file [
6 builtins.readFile
7 (builtins.split "\\\$\\{\\{([^}]*)}}")
8 (map (part:
9 if builtins.typeOf part == "string"
10 then part
11 else
12 import
13 (
14 (
15 pkgs.writeText "generated.nix" ("pkgs: lib: " + (builtins.elemAt part 0))
16 ).outPath
17 )
18 pkgs
19 lib
20 ))
21 (map (part:
22 if builtins.typeOf part == "string" then part
23 else if builtins.typeOf part == "path" then
24 let
25 stringified = toString part;
26 in
27 builtins.toString (utils.interpolateFile (
28 file + "/.." + (builtins.substring
29 (builtins.stringLength "/nix/store")
30 (builtins.stringLength
31 stringified)
32 stringified)
33 # ^ Somewhat of a hack, works because we know that the file path
34 # is a text file (i.e. not a directory) as we read it earlier and
35 # relative paths end up in /nix/store due to the writeText. Absolute
36 # paths are not supported
37 ))
38 else
39 toString part
40 ))
41 (builtins.concatStringsSep "")
42]