update
This commit is contained in:
@ -1,16 +1,24 @@
|
||||
inputs: {
|
||||
inputs:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
}:
|
||||
let
|
||||
cfg = config.cloudns;
|
||||
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||
inherit (lib) mkIf mkEnableOption mkOption types;
|
||||
inherit (lib)
|
||||
mkIf
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
|
||||
format = pkgs.formats.json {};
|
||||
format = pkgs.formats.json { };
|
||||
configFile = format.generate "config.json" cfg.settings;
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.cloudns = {
|
||||
enable = mkEnableOption "cloudns";
|
||||
|
||||
@ -23,36 +31,37 @@ in {
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = with types; let
|
||||
valueType = nullOr (oneOf [
|
||||
# TODO: restrict type to actual config file structure
|
||||
bool
|
||||
int
|
||||
float
|
||||
str
|
||||
path
|
||||
(attrsOf valueType)
|
||||
(listOf valueType)
|
||||
]);
|
||||
in
|
||||
type =
|
||||
with types;
|
||||
let
|
||||
valueType = nullOr (oneOf [
|
||||
bool
|
||||
int
|
||||
float
|
||||
str
|
||||
path
|
||||
(attrsOf valueType)
|
||||
(listOf valueType)
|
||||
]);
|
||||
in
|
||||
valueType;
|
||||
default = throw "Please specify cloudns.settings";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [package];
|
||||
environment.systemPackages = [ package ];
|
||||
|
||||
systemd.services.cloudns = mkIf (cfg.timer != null) {
|
||||
script = "${package}/bin/cloudns --config ${configFile}";
|
||||
requires = ["network-online.target"];
|
||||
requires = [ "network-online.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.cloudns = mkIf (cfg.timer != null) {
|
||||
wantedBy = ["timers.target"];
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "0s";
|
||||
OnUnitActiveSec = "${toString cfg.timer}s";
|
||||
|
44
nix/package.nix
Normal file
44
nix/package.nix
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
src,
|
||||
python3Packages,
|
||||
}:
|
||||
let
|
||||
inherit (python3Packages)
|
||||
setuptools
|
||||
pydantic
|
||||
pytest
|
||||
requests
|
||||
types-requests
|
||||
mypy
|
||||
pylint
|
||||
;
|
||||
|
||||
project = (builtins.fromTOML (builtins.readFile "${src}/pyproject.toml")).project;
|
||||
pname = project.name;
|
||||
version = project.version;
|
||||
in
|
||||
python3Packages.buildPythonPackage {
|
||||
inherit pname version src;
|
||||
|
||||
pyproject = true;
|
||||
|
||||
build-system = [ setuptools ];
|
||||
|
||||
dependencies = [
|
||||
requests
|
||||
pydantic
|
||||
];
|
||||
|
||||
nativeCheckInputs = [
|
||||
pytest
|
||||
mypy
|
||||
types-requests
|
||||
pylint
|
||||
];
|
||||
|
||||
checkPhase = ''
|
||||
pytest tests
|
||||
mypy src
|
||||
pylint src
|
||||
'';
|
||||
}
|
Reference in New Issue
Block a user