Readd poetry2nix

I have less problems with it than without.
This commit is contained in:
Andreas Zweili 2023-08-28 20:12:20 +02:00
parent 7e4a7ec125
commit 93731bf2c8
4 changed files with 157 additions and 37 deletions

5
.envrc
View File

@ -38,7 +38,10 @@ layout_poetry() {
export VIRTUAL_ENV
}
layout poetry
if ! has nix; then
layout poetry
fi
export PROJECT_DIR=$(pwd)
export WEBPORT=$(($RANDOM + 1100))
export PGPORT=$(($WEBPORT + 100))

11
dev.sh
View File

@ -89,7 +89,7 @@ descriptions["venv"]="Build a pseudo venv that editors like VS Code can use."
tasks["venv"]=venv
build-container() {
nix build && docker load <result && docker run --rm -ti network-inventory:latest
nix build && docker load <result
}
descriptions["build-container"]="Build and load OCI container."
tasks["build-container"]=build-container
@ -118,21 +118,18 @@ tasks["debug"]=debug
lint() {
echo "Running pylint"
poetry run \
pylint \
pylint \
--rc-file="$PROJECT_DIR/pyproject.toml" \
-j 0 \
-E "$PROJECT_DIR/src"
echo "Running mypy"
poetry run \
mypy --config-file="$PROJECT_DIR/pyproject.toml" "$PROJECT_DIR/src"
mypy --config-file="$PROJECT_DIR/pyproject.toml" "$PROJECT_DIR/src"
}
descriptions["lint"]="Run the linters against the src directory."
tasks["lint"]=lint
test() {
DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test poetry run \
pytest \
DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test pytest \
-nauto \
--nomigrations \
--cov-config="$PROJECT_DIR/.coveragerc" \

View File

@ -18,6 +18,45 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1689068808,
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"poetry2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1688870561,
"narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "165b1650b753316aa7f1787f3005a8d2da0f5301",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1688918189,
@ -34,10 +73,33 @@
"type": "github"
}
},
"poetry2nix": {
"inputs": {
"flake-utils": "flake-utils_2",
"nix-github-actions": "nix-github-actions",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1693051011,
"narHash": "sha256-HNbuVCS/Fnl1YZOjBk9/MlIem+wM8fvIzTH0CVQrLSQ=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "5b3a5151cf212021ff8d424f215fb030e4ff2837",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "poetry2nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"poetry2nix": "poetry2nix"
}
},
"systems": {
@ -54,6 +116,21 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -3,12 +3,34 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils }:
(flake-utils.lib.eachDefaultSystem (system:
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
{
overlays.default = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlay
(final: prev: rec {
inventoryDevEnv = prev.poetry2nix.mkPoetryEnv
{
projectDir = ./.;
groups = [ "main" "dev" ];
};
inventoryPackage = prev.poetry2nix.mkPoetryApplication {
projectDir = ./.;
groups = [ "main" ];
};
inventoryEnv = inventoryPackage.dependencyEnv;
})
];
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
inventory = pkgs.stdenv.mkDerivation {
src = ./.;
@ -23,18 +45,40 @@
rec {
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.inventoryDevEnv
pkgs.poetry
pkgs.python310Packages.pip
pkgs.overmind
pkgs.postgresql_15
(pkgs.writeScriptBin "dev" "${builtins.readFile ./dev.sh}")
];
PYTHON_KEYRING_BACKEND = "keyring.backends.fail.Keyring";
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
shellHook = ''
export DJANGO_SETTINGS_MODULE=network_inventory.settings.local
'';
};
checks = {
tests = pkgs.stdenv.mkDerivation {
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontInstall = true;
doCheck = true;
name = "test";
src = ./.;
checkInputs = [ pkgs.inventoryDevEnv ];
checkPhase = ''
mkdir -p $out
pytest --ds=network_inventory.settings.ram_test \
-nauto \
--nomigrations \
--cov=./src \
./src
'';
};
};
packages = {
venv = pkgs.inventoryEnv;
container = pkgs.dockerTools.buildImage {
name = "network-inventory";
tag = "latest";
@ -42,39 +86,38 @@
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
inventory
pkgs.bashInteractive
pkgs.coreutils
pkgs.poetry
inventory
(pkgs.writeShellScriptBin "start-inventory" ''
if [ -f .first_run ]; then
sleep 2
django-admin collectstatic --noinput
django-admin makemigrations
django-admin migrate
${pkgs.inventoryEnv}/bin/django-admin collectstatic --noinput
${pkgs.inventoryEnv}/bin/django-admin makemigrations
${pkgs.inventoryEnv}/bin/django-admin migrate
else
django-admin collectstatic --noinput
django-admin makemigrations backups
django-admin makemigrations computers
django-admin makemigrations core
django-admin makemigrations customers
django-admin makemigrations devices
django-admin makemigrations licenses
django-admin makemigrations nets
django-admin makemigrations softwares
django-admin makemigrations users
django-admin makemigrations
django-admin migrate
django-admin loaddata backups
django-admin loaddata computers
django-admin loaddata core
django-admin loaddata devices
django-admin loaddata nets
django-admin loaddata softwares
django-admin shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'password')"
${pkgs.inventoryEnv}/bin/django-admin collectstatic --noinput
${pkgs.inventoryEnv}/bin/django-admin makemigrations backups
${pkgs.inventoryEnv}/bin/django-admin makemigrations computers
${pkgs.inventoryEnv}/bin/django-admin makemigrations core
${pkgs.inventoryEnv}/bin/django-admin makemigrations customers
${pkgs.inventoryEnv}/bin/django-admin makemigrations devices
${pkgs.inventoryEnv}/bin/django-admin makemigrations licenses
${pkgs.inventoryEnv}/bin/django-admin makemigrations nets
${pkgs.inventoryEnv}/bin/django-admin makemigrations softwares
${pkgs.inventoryEnv}/bin/django-admin makemigrations users
${pkgs.inventoryEnv}/bin/django-admin makemigrations
${pkgs.inventoryEnv}/bin/django-admin migrate
${pkgs.inventoryEnv}/bin/django-admin loaddata backups
${pkgs.inventoryEnv}/bin/django-admin loaddata computers
${pkgs.inventoryEnv}/bin/django-admin loaddata core
${pkgs.inventoryEnv}/bin/django-admin loaddata devices
${pkgs.inventoryEnv}/bin/django-admin loaddata nets
${pkgs.inventoryEnv}/bin/django-admin loaddata softwares
${pkgs.inventoryEnv}/bin/django-admin shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'password')"
touch .first_run
fi
gunicorn network_inventory.wsgi:application --reload --bind 0.0.0.0:8000 --workers 3
${pkgs.inventoryEnv}/bin/gunicorn network_inventory.wsgi:application --reload --bind 0.0.0.0:8000 --workers 3
'')
];
};