1- # TODO: redefine your wrapperFunction redefinition using your fancy new helper functions
21maybe_compile :
32{
43 config ,
54 wlib ,
65 lib ,
76 luajit ,
8- dieHook ,
97 makeWrapper ,
108 makeBinaryWrapper ,
9+ dieHook ,
1110 ...
1211} :
1312let
14- generateArgsFromFlags = genArgs flaggenfunc ;
15- genArgs =
16- f : default-sep : dag :
17- wlib . dag . dagToDal (
18- builtins . mapAttrs (
19- n : v :
20- let
21- genArgs =
22- sep : name : value :
23- if lib . isList value then lib . concatMap ( v : f true sep name v ) value else f false sep name value ;
24- in
25- v // { data = genArgs ( if v . sep or null != null then v . sep else default-sep ) n v . data ; }
26- ) dag
27- ) ;
28- flaggenfunc =
29- is_list : flagSeparator : name : value :
30- if ! is_list && ( value == false || value == null ) then
31- [ ]
32- else if ! is_list && value == true then
33- [
34- "--add-flag"
35- name
36- ]
37- else if lib . trim flagSeparator == "" && flagSeparator != "" then
13+ argv0 =
14+ if builtins . isString ( config . argv0 or null ) then
3815 [
39- "--add-flag"
40- name
41- "--add-flag"
42- ( toString value )
16+ "--argv0"
17+ ( lib . escapeShellArg config . argv0 )
4318 ]
19+ else if config . argv0type or null == "resolve" then
20+ [ "--resolve-argv0" ]
4421 else
45- [
46- "--add-flag"
47- "${ name } ${ flagSeparator } ${ toString value } "
48- ] ;
49-
50- argv0 = [
22+ [ "--inherit-argv0" ] ;
23+ split = wlib . makeWrapper . splitDal (
24+ wlib . makeWrapper . aggregateSingleOptionSet {
25+ inherit config ;
26+ sortResult = false ;
27+ }
28+ ) ;
29+ cliArgs = lib . pipe split . args [
30+ ( wlib . makeWrapper . fixArgs { sep = config . flagSeparator or null ; } )
5131 (
52- if builtins . isString config . argv0 then
53- {
54- data = [
55- "--argv0"
56- config . argv0
32+ { addFlag , appendFlag } :
33+ let
34+ mapArgs =
35+ name :
36+ lib . flip lib . pipe [
37+ ( map (
38+ v :
39+ let
40+ esc-fn = if v . esc-fn or null != null then v . esc-fn else config . escapingFunction ;
41+ in
42+ if builtins . isList ( v . data or null ) then
43+ map esc-fn v . data
44+ else if v ? data && v . data or null != null then
45+ esc-fn v . data
46+ else
47+ [ ]
48+ ) )
49+ lib . flatten
50+ ( builtins . concatMap ( v : [
51+ "--${ name } "
52+ v
53+ ] ) )
5754 ] ;
58- }
59- else if config . argv0type == "resolve" then
60- { data = [ "--resolve-argv0" ] ; }
61- else
62- { data = [ "--inherit-argv0" ] ; }
55+ in
56+ mapArgs "add-flag" addFlag ++ mapArgs "append-flag" ( wlib . dag . unwrapSort "appendFlag" appendFlag )
6357 )
6458 ] ;
65- envVarsDefault = lib . optionals ( config . envDefault != { } ) (
66- wlib . dag . mapDagToDal ( n : v : [
67- "--set-default"
68- n
69- ( toString v )
70- ] ) config . envDefault
71- ) ;
72- envVars = lib . optionals ( config . env != { } ) (
73- wlib . dag . mapDagToDal ( n : v : [
74- "--set"
75- n
76- ( toString v )
77- ] ) config . env
78- ) ;
79- flags = lib . optionals ( config . flags != { } ) (
80- generateArgsFromFlags ( config . flagSeparator or " " ) config . flags
81- ) ;
82- mapargs =
83- n : argname : single :
84- wlib . dag . lmap (
85- v :
86- if builtins . isList v then
87- if single then
88- lib . concatMap ( val : [
89- "--${ argname } "
90- ( toString val )
91- ] ) v
92- else
93- [ "--${ argname } " ] ++ v
94- else
95- [
96- "--${ argname } "
97- ( toString v )
98- ]
99- ) config . ${ n } ;
100-
101- other =
102- mapargs "unsetVar" "unset" true
103- ++ mapargs "chdir" "chdir" true
104- ++ mapargs "prefixVar" "prefix" false
105- ++ mapargs "suffixVar" "suffix" false ;
106- conditionals =
107- if config . wrapperImplementation != "binary" then
108- mapargs "runShell" "run" true
109- ++ mapargs "prefixContent" "prefix-contents" false
110- ++ mapargs "suffixContent" "suffix-contents" false
111- else
112- [ ] ;
113-
114- finalArgs =
115- argv0
116- ++ mapargs "addFlag" "add-flag" true
117- ++ flags
118- ++ mapargs "appendFlag" "append-flag" true
119- ++ envVars
120- ++ envVarsDefault
121- ++ other
122- ++ conditionals ;
12359
12460 luarc-path = "${ placeholder "out" } /${ config . binName } -rc.lua" ;
125- baseArgs = lib . escapeShellArgs [
61+ baseArgs = map lib . escapeShellArg [
12662 ( if config . exePath == "" then "${ config . package } " else "${ config . package } /${ config . exePath } " )
127- "${ placeholder "out" } /bin/${ config . binName } "
63+ "${ placeholder "out" } /${ config . binDir or " bin" } /${ config . binName } "
12864 "--add-flag"
12965 "--cmd"
13066 "--add-flag"
@@ -136,59 +72,109 @@ let
13672 manifest-path = lib . escapeShellArg "${ placeholder "out" } /${ config . binName } -rplugin.vim" ;
13773 makeWrapperCmd =
13874 isFinal :
139- lib . pipe finalArgs [
75+ lib . pipe split . other [
14076 (
14177 val :
14278 lib . optional isFinal {
14379 name = "NVIM_SYSTEM_RPLUGIN_MANIFEST" ;
144- esc-fn = x : x ;
145- data = "--set-default NVIM_SYSTEM_RPLUGIN_MANIFEST ${ manifest-path } " ;
80+ esc-fn = lib . escapeShellArg ;
81+ attr-name = "NVIM_SYSTEM_RPLUGIN_MANIFEST" ;
82+ type = "envDefault" ;
83+ data = manifest-path ;
14684 }
14785 ++ val
14886 ++ [
14987 {
15088 name = "NIX_PROPAGATED_LUA_PATH" ;
15189 esc-fn = x : x ;
152- data =
153- "--suffix LUA_PATH ';' ${ lib . escapeShellArg NVIM_LUA_PATH } "
154- + "--suffix LUA_PATH ';' \" $LUA_PATH\" " ;
90+ type = "UNPROCESSED" ;
91+ data = [
92+ "--suffix"
93+ "LUA_PATH"
94+ "';'"
95+ "${ lib . escapeShellArg NVIM_LUA_PATH } "
96+ "--suffix"
97+ "LUA_PATH"
98+ "';'"
99+ "\" $LUA_PATH\" "
100+ ] ;
155101 }
156102 {
157103 name = "NIX_PROPAGATED_LUA_CPATH" ;
158104 esc-fn = x : x ;
159- data =
160- "--suffix LUA_CPATH ';' ${ lib . escapeShellArg NVIM_LUA_CPATH } "
161- + "--suffix LUA_CPATH ';' \" $LUA_CPATH\" " ;
105+ type = "UNPROCESSED" ;
106+ data = [
107+ "--suffix"
108+ "LUA_CPATH"
109+ "';'"
110+ "${ lib . escapeShellArg NVIM_LUA_CPATH } "
111+ "--suffix"
112+ "LUA_CPATH"
113+ "';'"
114+ "\" $LUA_CPATH\" "
115+ ] ;
162116 }
163117 ]
164118 ++ lib . optional isFinal {
165119 name = "NIX_GENERATED_VIMINIT" ;
166- esc-fn = x : x ;
167- data = "--set-default VIMINIT 'lua require(${ builtins . toJSON "${ config . settings . info_plugin_name } .init_main" } )'" ;
120+ type = "envDefault" ;
121+ esc-fn = lib . escapeShellArg ;
122+ attr-name = "VIMINIT" ;
123+ data = "lua require(${ builtins . toJSON "${ config . settings . info_plugin_name } .init_main" } )" ;
168124 }
169125 )
170126 ( wlib . dag . unwrapSort "makeWrapper" )
171- ( map (
127+ ( builtins . concatMap (
172128 v :
173129 let
174130 esc-fn = if v . esc-fn or null != null then v . esc-fn else config . escapingFunction ;
131+ esc-list = map esc-fn ;
175132 in
176- if builtins . isList v . data then map esc-fn v . data else esc-fn v . data
133+ if v . type or null == "unsetVar" then
134+ [ "--unset" ] ++ [ ( esc-fn v . data ) ]
135+ else if v . type or null == "env" then
136+ [ "--set" ]
137+ ++ esc-list [
138+ v . attr-name
139+ v . data
140+ ]
141+ else if v . type or null == "envDefault" then
142+ [ "--set-default" ]
143+ ++ esc-list [
144+ v . attr-name
145+ v . data
146+ ]
147+ else if v . type or null == "UNPROCESSED" then
148+ v . data
149+ else if v . type or null == "prefixVar" then
150+ [ "--prefix" ] ++ esc-list v . data
151+ else if v . type or null == "suffixVar" then
152+ [ "--suffix" ] ++ esc-list v . data
153+ else if v . type or null == "chdir" then
154+ [ "--chdir" ] ++ [ ( esc-fn v . data ) ]
155+ else if config . wrapperImplementation or null != "binary" then
156+ if v . type or null == "prefixContent" then
157+ [ "--prefix-contents" ] ++ esc-list v . data
158+ else if v . type or null == "suffixContent" then
159+ [ "--suffix-contents" ] ++ esc-list v . data
160+ else if v . type or null == "runShell" then
161+ [ "--run" ] ++ [ ( esc-fn v . data ) ]
162+ else
163+ [ ]
164+ else
165+ [ ]
177166 ) )
178- lib . flatten
179- (
180- v :
181- [
182- "makeWrapper"
183- baseArgs
184- ]
185- ++ v
186- )
167+ ( res : [ "makeWrapper" ] ++ baseArgs ++ argv0 ++ cliArgs ++ res )
187168 ( builtins . concatStringsSep " " )
188169 ] ;
170+
189171 srcsetup = p : "source ${ lib . escapeShellArg "${ p } /nix-support/setup-hook" } " ;
190172in
191- if config . binName == "" then
173+ if
174+ ! builtins . isString ( config . binName or null )
175+ || config . binName == ""
176+ || ! ( lib . isStringLike ( config . package or null ) )
177+ then
192178 ""
193179else
194180 /* bash */ ''
0 commit comments