Home

nixfig @main - refs - log -
-
https://git.jolheiser.com/nixfig.git
Nix as a Config
drwxrwxrwx
38 B
testdata/
-rw-r--r--
20 B
.gitignore
-rw-r--r--
1.1 kB
LICENSE
-rw-r--r--
771 B
README.md
-rw-r--r--
269 B
go.mod
-rw-r--r--
2.4 kB
go.sum
-rw-r--r--
2.9 kB
nixfig.go
-rw-r--r--
1.4 kB
nixfig_test.go

nixfig

Read a nix file as a config.

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

Allows parsing the following:

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:

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