Home

nixfig @main - refs - log - search -
https://git.jolheiser.com/nixfig.git
Nix as a Config
README.md - raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# nixfig

Read a nix file as a config.

Essentially just wraps `nix eval (--json) --expr`.


Allows parsing the following:
```nix
let
  user = "jolheiser";
in {
  log = {
    level = "warn";
    # Name the log file after the user....for reasons
    file = "${user}.log";
  };
  http = {
    host = "0.0.0.0";
    port = 1234;
    # Make user an admin, but also make a generic admin user
    admins = [user "admin"];
  };
}
```

Into a struct like:
```go
type Config struct {
	Log struct {
		Level string // warn
		File  string // jolheiser.log
	}
	HTTP struct {
		Host   string   // 0.0.0.0
		Port   int      // 1234
		Admins []string // [jolheiser admin]
	}
}
```

It can also marshal a struct into a valid (albeit minified) nix expression.


## License

[MIT](LICENSE)