fix(fmt): use nixfmt-rfc-style
This commit is contained in:
parent
9fc79a0c7b
commit
144d5c45c6
4 changed files with 139 additions and 112 deletions
11
default.nix
11
default.nix
|
@ -1,7 +1,8 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
readToml = path: builtins.fromTOML (builtins.readFile path);
|
readToml = path: builtins.fromTOML (builtins.readFile path);
|
||||||
cargoToml = readToml ./Cargo.toml;
|
cargoToml = readToml ./Cargo.toml;
|
||||||
pname = cargoToml.package.name;
|
pname = cargoToml.package.name;
|
||||||
|
@ -11,7 +12,9 @@
|
||||||
name = "${pname}-source";
|
name = "${pname}-source";
|
||||||
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
|
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
|
||||||
# no need to pull in crane for just this
|
# no need to pull in crane for just this
|
||||||
filter = orig_path: type: let
|
filter =
|
||||||
|
orig_path: type:
|
||||||
|
let
|
||||||
path = toString orig_path;
|
path = toString orig_path;
|
||||||
base = baseNameOf path;
|
base = baseNameOf path;
|
||||||
parentDir = baseNameOf (dirOf path);
|
parentDir = baseNameOf (dirOf path);
|
||||||
|
@ -28,7 +31,7 @@
|
||||||
type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig;
|
type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
inherit pname version src;
|
inherit pname version src;
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
useNextest = true;
|
useNextest = true;
|
||||||
|
@ -39,4 +42,4 @@ in
|
||||||
homepage = "https://github.com/jalil-salame/webnsupdate";
|
homepage = "https://github.com/jalil-salame/webnsupdate";
|
||||||
mainProgram = "webnsupdate";
|
mainProgram = "webnsupdate";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
50
flake.nix
50
flake.nix
|
@ -5,52 +5,67 @@
|
||||||
systems.url = "github:nix-systems/default";
|
systems.url = "github:nix-systems/default";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs =
|
||||||
|
{
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
systems,
|
systems,
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
forEachSupportedSystem = nixpkgs.lib.genAttrs (import systems);
|
forEachSupportedSystem = nixpkgs.lib.genAttrs (import systems);
|
||||||
in {
|
in
|
||||||
checks = forEachSupportedSystem (system: let
|
{
|
||||||
|
checks = forEachSupportedSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
fmtRust = pkgs.callPackage ./run-cmd.nix {
|
fmtRust = pkgs.callPackage ./run-cmd.nix {
|
||||||
src = self;
|
src = self;
|
||||||
name = "fmt-rust";
|
name = "fmt-rust";
|
||||||
extraNativeBuildInputs = [pkgs.rustfmt];
|
extraNativeBuildInputs = [ pkgs.rustfmt ];
|
||||||
cmd = "${lib.getExe pkgs.cargo} fmt --all --check --verbose";
|
cmd = "${lib.getExe pkgs.cargo} fmt --all --check --verbose";
|
||||||
};
|
};
|
||||||
fmtNix = pkgs.callPackage ./run-cmd.nix {
|
fmtNix = pkgs.callPackage ./run-cmd.nix {
|
||||||
src = self;
|
src = self;
|
||||||
name = "fmt-nix";
|
name = "fmt-nix";
|
||||||
cmd = "${lib.getExe pkgs.alejandra} --check .";
|
cmd = "${lib.getExe self.formatter.${system}} --check .";
|
||||||
};
|
};
|
||||||
lintNix = pkgs.callPackage ./run-cmd.nix {
|
lintNix = pkgs.callPackage ./run-cmd.nix {
|
||||||
src = self;
|
src = self;
|
||||||
name = "lint-nix";
|
name = "lint-nix";
|
||||||
cmd = "${lib.getExe pkgs.statix} check .";
|
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 (
|
||||||
webnsupdate = nixpkgs.legacyPackages.${system}.callPackage ./default.nix {};
|
system:
|
||||||
in {
|
let
|
||||||
|
webnsupdate = nixpkgs.legacyPackages.${system}.callPackage ./default.nix { };
|
||||||
|
in
|
||||||
|
{
|
||||||
inherit webnsupdate;
|
inherit webnsupdate;
|
||||||
default = webnsupdate;
|
default = webnsupdate;
|
||||||
});
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
overlays.default = final: prev: {
|
overlays.default = final: prev: {
|
||||||
webnsupdate = final.callPackage ./default.nix {};
|
webnsupdate = final.callPackage ./default.nix { };
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosModules.default = ./module.nix;
|
nixosModules.default = ./module.nix;
|
||||||
|
|
||||||
devShells = forEachSupportedSystem (system: let
|
devShells = forEachSupportedSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.cargo-insta
|
pkgs.cargo-insta
|
||||||
|
@ -58,6 +73,7 @@
|
||||||
pkgs.mold
|
pkgs.mold
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
40
module.nix
40
module.nix
|
@ -3,13 +3,15 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}:
|
||||||
|
let
|
||||||
cfg = config.services.webnsupdate;
|
cfg = config.services.webnsupdate;
|
||||||
inherit (lib) mkOption mkEnableOption types;
|
inherit (lib) mkOption mkEnableOption types;
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
options.services.webnsupdate = mkOption {
|
options.services.webnsupdate = mkOption {
|
||||||
description = "An HTTP server for nsupdate.";
|
description = "An HTTP server for nsupdate.";
|
||||||
default = {};
|
default = { };
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
enable = mkEnableOption "webnsupdate";
|
enable = mkEnableOption "webnsupdate";
|
||||||
|
@ -18,8 +20,8 @@ in {
|
||||||
Extra arguments to be passed to the webnsupdate server command.
|
Extra arguments to be passed to the webnsupdate server command.
|
||||||
'';
|
'';
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [ ];
|
||||||
example = ["--ip-source"];
|
example = [ "--ip-source" ];
|
||||||
};
|
};
|
||||||
bindIp = mkOption {
|
bindIp = mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -102,12 +104,12 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config =
|
||||||
|
let
|
||||||
recordsFile =
|
recordsFile =
|
||||||
if cfg.recordsFile != null
|
if cfg.recordsFile != null then cfg.recordsFile else pkgs.writeText "webnsrecords" cfg.records;
|
||||||
then cfg.recordsFile
|
args = lib.strings.escapeShellArgs (
|
||||||
else pkgs.writeText "webnsrecords" cfg.records;
|
[
|
||||||
args = lib.strings.escapeShellArgs ([
|
|
||||||
"--records"
|
"--records"
|
||||||
recordsFile
|
recordsFile
|
||||||
"--key-file"
|
"--key-file"
|
||||||
|
@ -121,7 +123,8 @@ in {
|
||||||
"--ttl"
|
"--ttl"
|
||||||
(builtins.toString cfg.ttl)
|
(builtins.toString cfg.ttl)
|
||||||
]
|
]
|
||||||
++ cfg.extraArgs);
|
++ cfg.extraArgs
|
||||||
|
);
|
||||||
cmd = "${lib.getExe pkgs.webnsupdate} ${args}";
|
cmd = "${lib.getExe pkgs.webnsupdate} ${args}";
|
||||||
in
|
in
|
||||||
lib.mkIf cfg.enable {
|
lib.mkIf cfg.enable {
|
||||||
|
@ -129,20 +132,25 @@ in {
|
||||||
# lib.optional (!config.services.bind.enable) "`webnsupdate` is expected to be used alongside `bind`. This is an unsopported configuration.";
|
# lib.optional (!config.services.bind.enable) "`webnsupdate` is expected to be used alongside `bind`. This is an unsopported configuration.";
|
||||||
assertions = [
|
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.";
|
message = "Exactly one of `services.webnsupdate.records` and `services.webnsupdate.recordsFile` must be set.";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.webnsupdate = {
|
systemd.services.webnsupdate = {
|
||||||
description = "Web interface for nsupdate.";
|
description = "Web interface for nsupdate.";
|
||||||
wantedBy = ["multi-user.target"];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = ["network.target" "bind.service"];
|
after = [
|
||||||
|
"network.target"
|
||||||
|
"bind.service"
|
||||||
|
];
|
||||||
preStart = "${cmd} verify";
|
preStart = "${cmd} verify";
|
||||||
path = [pkgs.dig];
|
path = [ pkgs.dig ];
|
||||||
startLimitIntervalSec = 60;
|
startLimitIntervalSec = 60;
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = [cmd];
|
ExecStart = [ cmd ];
|
||||||
Type = "exec";
|
Type = "exec";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
src,
|
src,
|
||||||
name,
|
name,
|
||||||
cmd,
|
cmd,
|
||||||
extraBuildInputs ? [],
|
extraBuildInputs ? [ ],
|
||||||
extraNativeBuildInputs ? [],
|
extraNativeBuildInputs ? [ ],
|
||||||
}:
|
}:
|
||||||
stdenvNoCC.mkDerivation {
|
stdenvNoCC.mkDerivation {
|
||||||
name = "${name}-src";
|
name = "${name}-src";
|
||||||
|
|
Loading…
Reference in a new issue