CurrentConfig reads the current Nix configuration.
(ctx context.Context)
| 36 | |
| 37 | // CurrentConfig reads the current Nix configuration. |
| 38 | func CurrentConfig(ctx context.Context) (Config, error) { |
| 39 | // `nix show-config` is deprecated in favor of `nix config show`, but we |
| 40 | // want to remain compatible with older Nix versions. |
| 41 | cmd := Command("show-config", "--json") |
| 42 | out, err := cmd.Output(ctx) |
| 43 | var exitErr *exec.ExitError |
| 44 | if errors.As(err, &exitErr) && len(exitErr.Stderr) != 0 { |
| 45 | return Config{}, redact.Errorf("command %s: %v: %s", redact.Safe(cmd), err, exitErr.Stderr) |
| 46 | } |
| 47 | if err != nil { |
| 48 | return Config{}, redact.Errorf("command %s: %v", cmd, err) |
| 49 | } |
| 50 | cfg := Config{} |
| 51 | if err := json.Unmarshal(out, &cfg); err != nil { |
| 52 | return Config{}, redact.Errorf("unmarshal JSON output from %s: %v", redact.Safe(cmd), err) |
| 53 | } |
| 54 | return cfg, nil |
| 55 | } |
| 56 | |
| 57 | // IsUserTrusted reports if the current OS user is in the trusted-users list. If |
| 58 | // there are any groups in the list, it also checks if the user belongs to any |