updated
This commit is contained in:
@ -1,32 +1,41 @@
|
||||
inputs: {
|
||||
inputs:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
}:
|
||||
let
|
||||
cfg = config.services.testdata;
|
||||
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.services.testdata = {
|
||||
enable = mkEnableOption "testdata";
|
||||
|
||||
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 services.testdata.settings";
|
||||
};
|
||||
@ -43,7 +52,7 @@ in {
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [package];
|
||||
environment.systemPackages = [ package ];
|
||||
|
||||
systemd.services.testdata = {
|
||||
enable = true;
|
||||
@ -53,7 +62,7 @@ in {
|
||||
ExecStart = "${package}/bin/testdata --config ${configFile} --listen ${cfg.host} --port ${builtins.toString cfg.port}";
|
||||
};
|
||||
|
||||
wantedBy = ["multi-user.target"];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
46
nix/package.nix
Normal file
46
nix/package.nix
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
src,
|
||||
python3Packages,
|
||||
}:
|
||||
let
|
||||
inherit (python3Packages)
|
||||
setuptools
|
||||
fastapi
|
||||
uvicorn
|
||||
pydantic
|
||||
pytest
|
||||
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 = [
|
||||
fastapi
|
||||
uvicorn
|
||||
pydantic
|
||||
];
|
||||
|
||||
nativeCheckInputs = [
|
||||
pytest
|
||||
requests
|
||||
mypy
|
||||
pylint
|
||||
];
|
||||
|
||||
checkPhase = ''
|
||||
pytest tests
|
||||
mypy src
|
||||
pylint src
|
||||
'';
|
||||
}
|
Reference in New Issue
Block a user