Skip to content

Commit 561c0a5

Browse files
committed
document a classical nix setup
1 parent c4f734d commit 561c0a5

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

docs/book/usage.md

+61-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
11
# Usage
22
For all the modules options take a look [here](modules/index.md).
3-
And there is a quite elaborate example [here](https://github.com/Janik-Haag/nixos-dns/tree/main/example), you can also use it as a template by doing: `nix flake init -t github:Janik-Haag/nixos-dns`.
3+
There is a quite elaborate example [here](https://github.com/Janik-Haag/nixos-dns/tree/main/example), you can also use it as a template (`nix flake init -t github:Janik-Haag/nixos-dns`).
44

5-
## classic
5+
## classical nix
66

7-
There is a `default.nix` in the project root with `flake-compat`, I was told that it should be enough to use it in a classical NixOS environment, but have no idea how to do so (probably adding a channel?).
8-
This would probably be a easy contribution if you are more familiar.
7+
Please note that the following code uses colmena to retrieve the DNS information from the hosts configurations, and npins for version pinning.
8+
You can of course use nixos-dns without colmena, you'll just have to figure out how to reference nixosConfigurations.
9+
10+
```nix
11+
# default.nix
12+
let
13+
pins = import ./npins;
14+
in
15+
{ pkgs ? import pins.nixpkgs { }
16+
, colmena ? pins.colmena
17+
, nixos-dns ? import pins.nixos-dns
18+
}:
19+
let
20+
generate = nixos-dns.utils.generate pkgs;
21+
in {
22+
dns = generate.octodnsConfig {
23+
config = {
24+
providers = {
25+
hetzner = {
26+
class = "octodns_hetzner.HetznerProvider";
27+
token = "env/HETZNER_DNS_API";
28+
};
29+
};
30+
};
31+
zones = {
32+
"example.com." = nixos-dns.utils.octodns.generateZoneAttrs [ "hetzner" ];
33+
};
34+
dnsConfig = {
35+
nixosConfigurations = (import "${colmena}/src/nix/hive/eval.nix" {
36+
rawHive = (import ./hive.nix { inherit pkgs nixos-dns; });
37+
}).nodes;
38+
extraConfig = import ./dns.nix;
39+
};
40+
};
41+
}
42+
```
43+
44+
```nix
45+
# hive.nix
46+
{ pkgs, nixos-dns }: {
47+
meta = {
48+
nixpkgs = pkgs;
49+
};
50+
defaults = { pkgs, lib, config, ... }: {
51+
imports = [
52+
((import nixos-dns).nixosModules.default)
53+
];
54+
};
55+
exampleHost = {
56+
deployment.targetHost = "host.example.com";
57+
deployment.tags = [ "infra" ];
58+
imports = [
59+
./hosts/exampleHost.nix
60+
];
61+
};
62+
}
63+
```
64+
65+
Now you just need to run `nix-build -A dns` to realize the zonefiles and octodns config.
966

1067
## flakes
1168

@@ -18,7 +75,6 @@ This would probably be a easy contribution if you are more familiar.
1875
nixos-dns.inputs.nixpkgs.follows = "nixpkgs";
1976
};
2077
21-
# Nothing special here
2278
outputs = inputs @ {
2379
self,
2480
nixpkgs,

0 commit comments

Comments
 (0)