This commit is contained in:
2025-05-29 18:19:57 +02:00
parent 7517ee5534
commit de03590cf7
5 changed files with 112 additions and 121 deletions

6
flake.lock generated
View File

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1742422364,
"narHash": "sha256-mNqIplmEohk5jRkqYqG19GA8MbQ/D4gQSK0Mu4LvfRQ=",
"lastModified": 1748370509,
"narHash": "sha256-QlL8slIgc16W5UaI3w7xHQEP+Qmv/6vSNTpoZrrSlbk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a84ebe20c6bc2ecbcfb000a50776219f48d134cc",
"rev": "4faa5f5321320e49a78ae7848582f684d64783e9",
"type": "github"
},
"original": {

View File

@ -5,81 +5,24 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = {
outputs =
{
self,
nixpkgs,
...
} @ inputs: let
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
}@inputs:
let
supportedSystems = [ "x86_64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}.extend overlay);
overlay = final: prev: rec {
python3Packages = prev.python3Packages.overrideScope (pfinal: pprev: {
packageNameToDrv = x: builtins.getAttr (cleanPythonPackageName x) final.python3Packages;
});
cleanPythonPackageName = x: let
cleanName = builtins.match "([a-z,A-Z,0-9,_,-]+).*" x;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
in
if cleanName != null
then builtins.elemAt cleanName 0
else builtins.warn "Could not determine package name from '${x}'" null;
};
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
buildDependencies = forAllSystems (system: builtins.map pkgs.${system}.python3Packages.packageNameToDrv pyproject.build-system.requires);
runtimeDependencies = forAllSystems (system: builtins.map pkgs.${system}.python3Packages.packageNameToDrv pyproject.project.dependencies);
optionalDependencies = forAllSystems (system: builtins.mapAttrs (name: value: builtins.map pkgs.${system}.python3Packages.packageNameToDrv value) pyproject.project.optional-dependencies);
in {
{
# `nix build`
packages = forAllSystems (system: let
buildProject = {skipCheck ? false}:
pkgs.${system}.python3Packages.buildPythonPackage {
pname = pyproject.project.name;
version = pyproject.project.version;
src = ./.;
pyproject = true;
build-system = buildDependencies.${system};
dependencies = runtimeDependencies.${system};
optional-dependencies = optionalDependencies.${system};
nativeCheckInputs = optionalDependencies.${system}.dev;
checkPhase = let
dev = builtins.map (x: x.pname) optionalDependencies.${system}.dev;
in ''
${
if builtins.elem "pytest" dev && !skipCheck
then "pytest tests"
else ""
}
${
if builtins.elem "mypy" dev && !skipCheck
then "mypy src"
else ""
}
${
if builtins.elem "pylint" dev && !skipCheck
then "pylint src"
else ""
}
'';
};
in {
default = self.packages.${system}."${pyproject.project.name}";
"${pyproject.project.name}" = buildProject {skipCheck = false;};
quick = buildProject {skipCheck = true;};
packages = forAllSystems (system: rec {
default = cloudns;
cloudns = pkgs.${system}.callPackage ./nix/package.nix { src = ./.; };
});
# `nix fmt`
formatter = forAllSystems (system: pkgs.${system}.alejandra);
# `nix develop`
devShells = forAllSystems (system: rec {
default = venv;

View File

@ -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 { };
configFile = format.generate "config.json" cfg.settings;
in {
in
{
options.cloudns = {
enable = mkEnableOption "cloudns";
@ -23,9 +31,10 @@ in {
};
settings = mkOption {
type = with types; let
type =
with types;
let
valueType = nullOr (oneOf [
# TODO: restrict type to actual config file structure
bool
int
float

44
nix/package.nix Normal file
View 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
'';
}

View File

@ -1,22 +1,17 @@
[project]
name = "cloudns"
version = "0.1.0"
version = "0.1.1"
requires-python = "~=3.12, <4"
dependencies = ["requests~=2.32.3", "pydantic~=2.10.5"]
dependencies = ["requests~=2.32.3", "pydantic~=2.11.1"]
[project.optional-dependencies]
dev = [
"pytest~=8.3",
"mypy~=1.13",
"pylint~=3.3",
"types-requests~=2.32.0.20241016",
]
dev = ["pytest~=8.3", "mypy~=1.13", "pylint~=3.3", "types-requests~=2.32"]
[project.scripts]
cloudns = "cloudns.main:main"
[build-system]
requires = ["setuptools~=75.1"]
requires = ["setuptools~=78.1"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]