fix(fmt): use nixfmt-rfc-style

This commit is contained in:
Jalil David Salamé Messina 2024-09-30 16:14:02 +02:00
parent 9fc79a0c7b
commit 144d5c45c6
Signed by: jalil
GPG key ID: F016B9E770737A0B
4 changed files with 139 additions and 112 deletions

View file

@ -1,7 +1,8 @@
{
lib,
rustPlatform,
}: let
}:
let
readToml = path: builtins.fromTOML (builtins.readFile path);
cargoToml = readToml ./Cargo.toml;
pname = cargoToml.package.name;
@ -11,7 +12,9 @@
name = "${pname}-source";
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
# no need to pull in crane for just this
filter = orig_path: type: let
filter =
orig_path: type:
let
path = toString orig_path;
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);

View file

@ -5,17 +5,23 @@
systems.url = "github:nix-systems/default";
};
outputs = {
outputs =
{
self,
nixpkgs,
systems,
}: let
}:
let
forEachSupportedSystem = nixpkgs.lib.genAttrs (import systems);
in {
checks = forEachSupportedSystem (system: let
in
{
checks = forEachSupportedSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (nixpkgs) lib;
in {
in
{
fmtRust = pkgs.callPackage ./run-cmd.nix {
src = self;
name = "fmt-rust";
@ -25,22 +31,28 @@
fmtNix = pkgs.callPackage ./run-cmd.nix {
src = self;
name = "fmt-nix";
cmd = "${lib.getExe pkgs.alejandra} --check .";
cmd = "${lib.getExe self.formatter.${system}} --check .";
};
lintNix = pkgs.callPackage ./run-cmd.nix {
src = self;
name = "lint-nix";
cmd = "${lib.getExe pkgs.statix} check .";
};
});
formatter = forEachSupportedSystem (system: nixpkgs.legacyPackages.${system}.alejandra);
}
);
formatter = forEachSupportedSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
packages = forEachSupportedSystem (system: let
packages = forEachSupportedSystem (
system:
let
webnsupdate = nixpkgs.legacyPackages.${system}.callPackage ./default.nix { };
in {
in
{
inherit webnsupdate;
default = webnsupdate;
});
}
);
overlays.default = final: prev: {
webnsupdate = final.callPackage ./default.nix { };
@ -48,9 +60,12 @@
nixosModules.default = ./module.nix;
devShells = forEachSupportedSystem (system: let
devShells = forEachSupportedSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in {
in
{
default = pkgs.mkShell {
packages = [
pkgs.cargo-insta
@ -58,6 +73,7 @@
pkgs.mold
];
};
});
}
);
};
}

View file

@ -3,10 +3,12 @@
pkgs,
config,
...
}: let
}:
let
cfg = config.services.webnsupdate;
inherit (lib) mkOption mkEnableOption types;
in {
in
{
options.services.webnsupdate = mkOption {
description = "An HTTP server for nsupdate.";
default = { };
@ -102,12 +104,12 @@ in {
};
};
config = let
config =
let
recordsFile =
if cfg.recordsFile != null
then cfg.recordsFile
else pkgs.writeText "webnsrecords" cfg.records;
args = lib.strings.escapeShellArgs ([
if cfg.recordsFile != null then cfg.recordsFile else pkgs.writeText "webnsrecords" cfg.records;
args = lib.strings.escapeShellArgs (
[
"--records"
recordsFile
"--key-file"
@ -121,7 +123,8 @@ in {
"--ttl"
(builtins.toString cfg.ttl)
]
++ cfg.extraArgs);
++ cfg.extraArgs
);
cmd = "${lib.getExe pkgs.webnsupdate} ${args}";
in
lib.mkIf cfg.enable {
@ -129,7 +132,9 @@ in {
# lib.optional (!config.services.bind.enable) "`webnsupdate` is expected to be used alongside `bind`. This is an unsopported configuration.";
assertions = [
{
assertion = (cfg.records != null || cfg.recordsFile != null) && !(cfg.records != null && cfg.recordsFile != null);
assertion =
(cfg.records != null || cfg.recordsFile != null)
&& !(cfg.records != null && cfg.recordsFile != null);
message = "Exactly one of `services.webnsupdate.records` and `services.webnsupdate.recordsFile` must be set.";
}
];
@ -137,7 +142,10 @@ in {
systemd.services.webnsupdate = {
description = "Web interface for nsupdate.";
wantedBy = [ "multi-user.target" ];
after = ["network.target" "bind.service"];
after = [
"network.target"
"bind.service"
];
preStart = "${cmd} verify";
path = [ pkgs.dig ];
startLimitIntervalSec = 60;