Skip to content

Commit 7055ad4

Browse files
committed
clean up lib.mdDoc, update flake.lock, introduce treefmt-nix/nixfmt, cleanup patches, use specialArgs where sensible. (#12)
* feat: use specialArgs where sensible * flake.lock: Update Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/666fc80e7b2afb570462423cb0e1cf1a3a34fedd' (2023-12-09) → 'github:NixOS/nixpkgs/5672bc9dbf9d88246ddab5ac454e82318d094bb8' (2024-04-16) * feat: introduce treefmt-nix ++ nixfmt-rfc-style * purge: lib.mdDoc * cleanup: nixdoc patch landed in nixpkgs
1 parent 7dc6942 commit 7055ad4

29 files changed

+1455
-859
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: nix run nixpkgs#statix -- check .
2424

2525
- name: "Check formatting"
26-
run: nix fmt -- --check .
26+
run: nix fmt -- --fail-on-change
2727

2828
- name: "Try building docs"
2929
run: nix build .#docs

default.nix

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
(import
2-
(
3-
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
4-
fetchTarball {
5-
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
6-
sha256 = lock.nodes.flake-compat.locked.narHash;
7-
}
8-
)
9-
{ src = ./.; }
10-
).defaultNix
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
in
5+
fetchTarball {
6+
url =
7+
lock.nodes.flake-compat.locked.url
8+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
9+
sha256 = lock.nodes.flake-compat.locked.narHash;
10+
}
11+
) { src = ./.; }).defaultNix

docs/default.nix

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
{ lib, utils, pkgs }:
1+
{
2+
lib,
3+
utils,
4+
pkgs,
5+
}:
26
# docs = pkgs.callPackage ./docs.nix { };
37
let
48
# can be removed once https://github.com/rust-lang/mdBook/pull/2262 lands

docs/modules.nix

+34-25
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
1-
{ utils }: { lib, runCommand, nixosOptionsDoc, ... }:
1+
{ utils }:
2+
{
3+
lib,
4+
runCommand,
5+
nixosOptionsDoc,
6+
...
7+
}:
28
let
3-
mkModuleDocs = module: (nixosOptionsDoc {
4-
inherit (lib.evalModules {
5-
modules = [
6-
# ignores the configs part in modules
7-
# which is good since we only want the options
8-
{
9-
config._module.check = false;
10-
options._module.args = lib.mkOption { visible = false; };
11-
}
9+
mkModuleDocs =
10+
module:
11+
(nixosOptionsDoc {
12+
inherit
13+
(lib.evalModules {
14+
modules = [
15+
# ignores the configs part in modules
16+
# which is good since we only want the options
17+
{
18+
config._module.check = false;
19+
options._module.args = lib.mkOption { visible = false; };
20+
}
1221

13-
module
14-
];
15-
}) options;
16-
}).optionsCommonMark;
22+
module
23+
];
24+
specialArgs = {
25+
inherit utils;
26+
};
27+
})
28+
options
29+
;
30+
}).optionsCommonMark;
1731
modules = {
18-
dnsConfig = import ../modules/dnsConfig.nix { inherit utils; };
32+
dnsConfig = import ../modules/dnsConfig.nix;
33+
extraConfig = import ../modules/extraConfig.nix;
1934

20-
# darwin = import ../modules/darwin.nix { inherit utils; };
2135
nixos = import ../modules/nixos.nix { inherit utils; };
22-
extraConfig = import ../modules/extraConfig.nix { inherit utils; };
23-
36+
# darwin = import ../modules/darwin.nix { inherit utils; };
2437
};
2538
in
2639
runCommand "modules" { } ''
2740
mkdir -p $out
2841
cp ${./modules.md} $out/index.md
29-
${
30-
lib.concatLines (
31-
lib.mapAttrsToList (name: module:
32-
"cat ${mkModuleDocs module} > $out/${name}.md"
33-
) modules
34-
)
35-
}
42+
${lib.concatLines (
43+
lib.mapAttrsToList (name: module: "cat ${mkModuleDocs module} > $out/${name}.md") modules
44+
)}
3645
''

docs/utils.nix

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
{ utils }: { lib
2-
, fetchpatch
3-
, nixdoc
4-
, nixosOptionsDoc
5-
, runCommand
6-
, ...
7-
}:
1+
{ utils }:
2+
{
3+
lib,
4+
fetchpatch,
5+
nixdoc,
6+
nixosOptionsDoc,
7+
runCommand,
8+
...
9+
}:
810
let
9-
utilNames = lib.mapAttrsToList (name: value: name) (builtins.removeAttrs utils [ "__unfix__" "extend" ]);
10-
patchedNixdoc = nixdoc.overrideAttrs (o: {
11-
patches = (o.patches or [ ]) ++ [
12-
(fetchpatch {
13-
url = "https://github.com/nix-community/nixdoc/commit/b4480a2143464d8238402514dd35c78b6f9b9928.patch";
14-
hash = "sha256-WZ/tA2q+u4h7G1gUn2nkAutsjYHNxqXwjqAKpxYTf7k=";
15-
})
16-
];
17-
});
11+
utilNames = lib.mapAttrsToList (name: value: name) (
12+
builtins.removeAttrs utils [
13+
"__unfix__"
14+
"extend"
15+
]
16+
);
1817
in
1918
runCommand "utils" { } ''
2019
mkdir -p $out
2120
cp ${./utils.md} $out/index.md
22-
${
23-
lib.concatLines (builtins.map (name: "${lib.getExe' patchedNixdoc "nixdoc"} --file ${../utils/${name}.nix} --prefix 'utils' --category '${name}' --description '${name}' > $out/${name}.md") utilNames)
24-
}
21+
${lib.concatLines (
22+
builtins.map (
23+
name:
24+
"${lib.getExe' nixdoc "nixdoc"} --file ${../utils/${name}.nix} --prefix 'utils' --category '${name}' --description '${name}' > $out/${name}.md"
25+
) utilNames
26+
)}
2527
''

example/dns.nix

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"example.com" = {
55
"" = {
66
ns = {
7-
data = [ "ns1.invalid" "ns2.invalid" "ns3.invalid" ];
7+
data = [
8+
"ns1.invalid"
9+
"ns2.invalid"
10+
"ns3.invalid"
11+
];
812
};
913
};
1014
};

example/flake.nix

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
};
99

1010
outputs =
11-
inputs @ { self
12-
, nixpkgs
13-
, nixos-dns
11+
inputs@{
12+
self,
13+
nixpkgs,
14+
nixos-dns,
1415
}:
1516
let
16-
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
17+
forAllSystems = nixpkgs.lib.genAttrs [
18+
"x86_64-linux"
19+
"aarch64-linux"
20+
];
1721
dnsConfig = {
1822
inherit (self) nixosConfigurations;
1923
extraConfig = import ./dns.nix;
@@ -43,7 +47,8 @@
4347
# nix eval .#dnsDebugConfig
4448
dnsDebugConfig = nixos-dns.utils.debug.config dnsConfig;
4549

46-
packages = forAllSystems (system:
50+
packages = forAllSystems (
51+
system:
4752
let
4853
generate = nixos-dns.utils.generate nixpkgs.legacyPackages.${system};
4954
in

flake.lock

+40-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+50-32
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,74 @@
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
66
flake-compat.url = "github:edolstra/flake-compat";
77
flake-compat.flake = false;
8+
treefmt-nix.url = "github:numtide/treefmt-nix";
9+
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
810
};
911

1012
outputs =
11-
{ self
12-
, nixpkgs
13-
, flake-compat
13+
{
14+
self,
15+
nixpkgs,
16+
flake-compat,
17+
systems,
18+
treefmt-nix,
1419
}:
1520
let
16-
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
21+
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
22+
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
1723
in
1824
{
1925
nixosModules = rec {
2026
dns = import ./modules/nixos.nix { inherit (self) utils; };
2127
default = dns;
2228
};
2329
utils = import ./utils { inherit (nixpkgs) lib; };
24-
lib = pkgs:
30+
lib =
31+
pkgs:
2532
import ./lib.nix {
2633
inherit pkgs;
2734
inherit (nixpkgs) lib;
2835
inherit (self) utils;
2936
};
3037
# __unfix__ and extend are filtered because of the fix point stuff. generate is filtered because it needs special architecture dependent treatment.
31-
tests = nixpkgs.lib.mapAttrs (name: v: import "${./utils}/tests/${name}.nix" { inherit self; inherit (nixpkgs) lib; inherit (self) utils; }) (builtins.removeAttrs self.utils [ "__unfix__" "extend" "generate" ]);
32-
devShells = forAllSystems (system:
33-
let
34-
pkgs = nixpkgs.legacyPackages.${system};
35-
in
36-
{
37-
default = pkgs.mkShell {
38-
buildInputs = with pkgs; [
39-
bind
40-
glow
41-
mdbook
42-
nixpkgs-fmt
43-
nix-unit
44-
nixdoc
45-
statix
46-
];
47-
};
48-
});
49-
packages = forAllSystems (system:
50-
{
51-
docs = import ./docs { inherit (self) utils; inherit (nixpkgs) lib; pkgs = nixpkgs.legacyPackages.${system}; };
52-
}
53-
);
54-
formatter = forAllSystems (
55-
system:
56-
nixpkgs.legacyPackages.${system}.nixpkgs-fmt
57-
);
38+
tests =
39+
nixpkgs.lib.mapAttrs
40+
(
41+
name: v:
42+
import "${./utils}/tests/${name}.nix" {
43+
inherit self;
44+
inherit (nixpkgs) lib;
45+
inherit (self) utils;
46+
}
47+
)
48+
(
49+
builtins.removeAttrs self.utils [
50+
"__unfix__"
51+
"extend"
52+
"generate"
53+
]
54+
);
55+
devShells = eachSystem (pkgs: {
56+
default = pkgs.mkShell {
57+
buildInputs = with pkgs; [
58+
bind
59+
glow
60+
mdbook
61+
nix-unit
62+
nixdoc
63+
statix
64+
nixfmt-rfc-style
65+
];
66+
};
67+
});
68+
packages = eachSystem (pkgs: {
69+
docs = import ./docs {
70+
inherit (self) utils;
71+
inherit (pkgs) lib;
72+
inherit pkgs;
73+
};
74+
});
75+
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
5876
templates = {
5977
default = {
6078
path = ./example;

modules/defaultTTL.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# We do this because the option is needed by multiple modules
22
{ lib }:
33
lib.mkOption {
4-
description = lib.mdDoc ''
4+
description = ''
55
this ttl will be applied to any record not explicitly having one set.
66
'';
77
default = 3600;

0 commit comments

Comments
 (0)