Skip to content

Commit

Permalink
clean up lib.mdDoc, update flake.lock, introduce treefmt-nix/nixfmt, …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Janik-Haag authored Apr 17, 2024
1 parent 0205c8c commit 1cf30ea
Show file tree
Hide file tree
Showing 29 changed files with 1,455 additions and 859 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: nix run nixpkgs#statix -- check .

- name: "Check formatting"
run: nix fmt -- --check .
run: nix fmt -- --fail-on-change

- name: "Try building docs"
run: nix build .#docs
Expand Down
21 changes: 11 additions & 10 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url =
lock.nodes.flake-compat.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
) { src = ./.; }).defaultNix
6 changes: 5 additions & 1 deletion docs/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ lib, utils, pkgs }:
{
lib,
utils,
pkgs,
}:
# docs = pkgs.callPackage ./docs.nix { };
let
# can be removed once https://github.com/rust-lang/mdBook/pull/2262 lands
Expand Down
59 changes: 34 additions & 25 deletions docs/modules.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
{ utils }: { lib, runCommand, nixosOptionsDoc, ... }:
{ utils }:
{
lib,
runCommand,
nixosOptionsDoc,
...
}:
let
mkModuleDocs = module: (nixosOptionsDoc {
inherit (lib.evalModules {
modules = [
# ignores the configs part in modules
# which is good since we only want the options
{
config._module.check = false;
options._module.args = lib.mkOption { visible = false; };
}
mkModuleDocs =
module:
(nixosOptionsDoc {
inherit
(lib.evalModules {
modules = [
# ignores the configs part in modules
# which is good since we only want the options
{
config._module.check = false;
options._module.args = lib.mkOption { visible = false; };
}

module
];
}) options;
}).optionsCommonMark;
module
];
specialArgs = {
inherit utils;
};
})
options
;
}).optionsCommonMark;
modules = {
dnsConfig = import ../modules/dnsConfig.nix { inherit utils; };
dnsConfig = import ../modules/dnsConfig.nix;
extraConfig = import ../modules/extraConfig.nix;

# darwin = import ../modules/darwin.nix { inherit utils; };
nixos = import ../modules/nixos.nix { inherit utils; };
extraConfig = import ../modules/extraConfig.nix { inherit utils; };

# darwin = import ../modules/darwin.nix { inherit utils; };
};
in
runCommand "modules" { } ''
mkdir -p $out
cp ${./modules.md} $out/index.md
${
lib.concatLines (
lib.mapAttrsToList (name: module:
"cat ${mkModuleDocs module} > $out/${name}.md"
) modules
)
}
${lib.concatLines (
lib.mapAttrsToList (name: module: "cat ${mkModuleDocs module} > $out/${name}.md") modules
)}
''
40 changes: 21 additions & 19 deletions docs/utils.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
{ utils }: { lib
, fetchpatch
, nixdoc
, nixosOptionsDoc
, runCommand
, ...
}:
{ utils }:
{
lib,
fetchpatch,
nixdoc,
nixosOptionsDoc,
runCommand,
...
}:
let
utilNames = lib.mapAttrsToList (name: value: name) (builtins.removeAttrs utils [ "__unfix__" "extend" ]);
patchedNixdoc = nixdoc.overrideAttrs (o: {
patches = (o.patches or [ ]) ++ [
(fetchpatch {
url = "https://github.com/nix-community/nixdoc/commit/b4480a2143464d8238402514dd35c78b6f9b9928.patch";
hash = "sha256-WZ/tA2q+u4h7G1gUn2nkAutsjYHNxqXwjqAKpxYTf7k=";
})
];
});
utilNames = lib.mapAttrsToList (name: value: name) (
builtins.removeAttrs utils [
"__unfix__"
"extend"
]
);
in
runCommand "utils" { } ''
mkdir -p $out
cp ${./utils.md} $out/index.md
${
lib.concatLines (builtins.map (name: "${lib.getExe' patchedNixdoc "nixdoc"} --file ${../utils/${name}.nix} --prefix 'utils' --category '${name}' --description '${name}' > $out/${name}.md") utilNames)
}
${lib.concatLines (
builtins.map (
name:
"${lib.getExe' nixdoc "nixdoc"} --file ${../utils/${name}.nix} --prefix 'utils' --category '${name}' --description '${name}' > $out/${name}.md"
) utilNames
)}
''
6 changes: 5 additions & 1 deletion example/dns.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"example.com" = {
"" = {
ns = {
data = [ "ns1.invalid" "ns2.invalid" "ns3.invalid" ];
data = [
"ns1.invalid"
"ns2.invalid"
"ns3.invalid"
];
};
};
};
Expand Down
15 changes: 10 additions & 5 deletions example/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
};

outputs =
inputs @ { self
, nixpkgs
, nixos-dns
inputs@{
self,
nixpkgs,
nixos-dns,
}:
let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
];
dnsConfig = {
inherit (self) nixosConfigurations;
extraConfig = import ./dns.nix;
Expand Down Expand Up @@ -43,7 +47,8 @@
# nix eval .#dnsDebugConfig
dnsDebugConfig = nixos-dns.utils.debug.config dnsConfig;

packages = forAllSystems (system:
packages = forAllSystems (
system:
let
generate = nixos-dns.utils.generate nixpkgs.legacyPackages.${system};
in
Expand Down
44 changes: 40 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 50 additions & 32 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,74 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};

outputs =
{ self
, nixpkgs
, flake-compat
{
self,
nixpkgs,
flake-compat,
systems,
treefmt-nix,
}:
let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
in
{
nixosModules = rec {
dns = import ./modules/nixos.nix { inherit (self) utils; };
default = dns;
};
utils = import ./utils { inherit (nixpkgs) lib; };
lib = pkgs:
lib =
pkgs:
import ./lib.nix {
inherit pkgs;
inherit (nixpkgs) lib;
inherit (self) utils;
};
# __unfix__ and extend are filtered because of the fix point stuff. generate is filtered because it needs special architecture dependent treatment.
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" ]);
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = pkgs.mkShell {
buildInputs = with pkgs; [
bind
glow
mdbook
nixpkgs-fmt
nix-unit
nixdoc
statix
];
};
});
packages = forAllSystems (system:
{
docs = import ./docs { inherit (self) utils; inherit (nixpkgs) lib; pkgs = nixpkgs.legacyPackages.${system}; };
}
);
formatter = forAllSystems (
system:
nixpkgs.legacyPackages.${system}.nixpkgs-fmt
);
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"
]
);
devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
buildInputs = with pkgs; [
bind
glow
mdbook
nix-unit
nixdoc
statix
nixfmt-rfc-style
];
};
});
packages = eachSystem (pkgs: {
docs = import ./docs {
inherit (self) utils;
inherit (pkgs) lib;
inherit pkgs;
};
});
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
templates = {
default = {
path = ./example;
Expand Down
2 changes: 1 addition & 1 deletion modules/defaultTTL.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# We do this because the option is needed by multiple modules
{ lib }:
lib.mkOption {
description = lib.mdDoc ''
description = ''
this ttl will be applied to any record not explicitly having one set.
'';
default = 3600;
Expand Down
Loading

0 comments on commit 1cf30ea

Please sign in to comment.