(ctx context.Context, username string)
| 107 | } |
| 108 | |
| 109 | func IncludeDevboxConfig(ctx context.Context, username string) error { |
| 110 | info, _ := nix.Default.Info() |
| 111 | path := cmp.Or(info.SystemConfig, "/etc/nix/nix.conf") |
| 112 | includePath := filepath.Join(filepath.Dir(path), "devbox-nix.conf") |
| 113 | b := fmt.Appendf(nil, "# This config was auto-generated by Devbox.\n\nextra-trusted-users = %s\n", username) |
| 114 | if err := os.WriteFile(includePath, b, 0o664); err != nil { |
| 115 | return redact.Errorf("write devbox nix.conf: %v", err) |
| 116 | } |
| 117 | |
| 118 | appended, err := appendConfigInclude(path, includePath) |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | if appended { |
| 123 | return restartDaemon(ctx) |
| 124 | } |
| 125 | return nil |
| 126 | } |
| 127 | |
| 128 | func appendConfigInclude(srcPath, includePath string) (appended bool, err error) { |
| 129 | nixConf, err := os.OpenFile(srcPath, os.O_RDWR, 0) |
no test coverage detected