MCPcopy Create free account
hub / github.com/jetify-com/devbox / appendConfigInclude

Function appendConfigInclude

internal/nix/config.go:128–170  ·  view source on GitHub ↗
(srcPath, includePath string)

Source from the content-addressed store, hash-verified

126}
127
128func appendConfigInclude(srcPath, includePath string) (appended bool, err error) {
129 nixConf, err := os.OpenFile(srcPath, os.O_RDWR, 0)
130 if err != nil {
131 return false, err
132 }
133 defer nixConf.Close()
134
135 confb, err := io.ReadAll(nixConf)
136 if err != nil {
137 return false, err
138 }
139 for _, line := range strings.Split(string(confb), "\n") {
140 line = strings.TrimSpace(line)
141 if line == "" {
142 // <whitespace>
143 continue
144 }
145 if strings.HasPrefix(line, "#") {
146 // # comment
147 continue
148 }
149
150 path := strings.TrimSpace(strings.TrimPrefix(line, "include"))
151 if path == includePath {
152 // include devbox-nix.conf
153 return false, nil
154 }
155 path = strings.TrimSpace(strings.TrimPrefix(line, "!include"))
156 if path == includePath {
157 // !include devbox-nix.conf
158 return false, nil
159 }
160 }
161
162 include := "\ninclude " + includePath + "\n"
163 if _, err := nixConf.WriteString(include); err != nil {
164 return false, redact.Errorf("append %q to %s: %v", redact.Safe(include), srcPath, err)
165 }
166 if err := nixConf.Close(); err != nil {
167 return false, redact.Errorf("append %q to %s: %v", redact.Safe(include), srcPath, err)
168 }
169 return true, nil
170}

Callers 1

IncludeDevboxConfigFunction · 0.85

Calls 2

ErrorfFunction · 0.92
SafeFunction · 0.92

Tested by

no test coverage detected