( pkg Includable, filePath, contentPath, virtenvPath string, )
| 121 | } |
| 122 | |
| 123 | func (m *Manager) createFile( |
| 124 | pkg Includable, |
| 125 | filePath, contentPath, virtenvPath string, |
| 126 | ) error { |
| 127 | name := pkg.CanonicalName() |
| 128 | slog.Debug("Creating file %q from contentPath: %q", filePath, contentPath) |
| 129 | content, err := pkg.FileContent(contentPath) |
| 130 | if err != nil { |
| 131 | return errors.WithStack(err) |
| 132 | } |
| 133 | tmpl, err := template.New(filePath + "-template").Parse(string(content)) |
| 134 | if err != nil { |
| 135 | return errors.WithStack(err) |
| 136 | } |
| 137 | |
| 138 | var urlForInput, attributePath string |
| 139 | |
| 140 | if pkg, ok := pkg.(*devpkg.Package); ok { |
| 141 | attributePath, err = pkg.PackageAttributePath() |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | urlForInput = pkg.URLForFlakeInput() |
| 146 | } |
| 147 | |
| 148 | var buf bytes.Buffer |
| 149 | if err = tmpl.Execute(&buf, map[string]any{ |
| 150 | "DevboxDir": filepath.Join(m.ProjectDir(), devboxDirName, name), |
| 151 | "DevboxDirRoot": filepath.Join(m.ProjectDir(), devboxDirName), |
| 152 | "DevboxProfileDefault": filepath.Join(m.ProjectDir(), nix.ProfilePath), |
| 153 | "PackageAttributePath": attributePath, |
| 154 | "Packages": m.AllPackageNamesIncludingRemovedTriggerPackages(), |
| 155 | "System": nix.System(), |
| 156 | "URLForInput": urlForInput, |
| 157 | "Virtenv": filepath.Join(virtenvPath, name), |
| 158 | }); err != nil { |
| 159 | return errors.WithStack(err) |
| 160 | } |
| 161 | var fileMode fs.FileMode = 0o644 |
| 162 | if strings.Contains(filePath, "bin/") { |
| 163 | fileMode = 0o755 |
| 164 | } |
| 165 | |
| 166 | if err := os.WriteFile(filePath, buf.Bytes(), fileMode); err != nil { |
| 167 | return errors.WithStack(err) |
| 168 | } |
| 169 | if fileMode == 0o755 { |
| 170 | if err := createSymlink(m.ProjectDir(), filePath); err != nil { |
| 171 | return err |
| 172 | } |
| 173 | } |
| 174 | return nil |
| 175 | } |
| 176 | |
| 177 | // buildConfig returns a plugin.Config |
| 178 | func buildConfig(pkg Includable, projectDir, content string) (*Config, error) { |
no test coverage detected