Remove poetry2nix

This commit is contained in:
Andreas Zweili 2023-09-26 21:17:35 +02:00
parent af04821fb2
commit 7db42ab3a3
5 changed files with 53 additions and 158 deletions

8
.envrc
View File

@ -20,6 +20,7 @@ layout_poetry() {
if [[ -d ".venv" ]]; then
VIRTUAL_ENV="$(pwd)/.venv"
poetry install
else
VIRTUAL_ENV=$(
poetry env info --path 2>/dev/null
@ -38,11 +39,10 @@ layout_poetry() {
export VIRTUAL_ENV
}
if ! has nix; then
layout poetry
fi
layout poetry
export PROJECT_DIR=$(pwd)
export WEBPORT=$(($RANDOM + 1100))
export PGPORT=$(($WEBPORT + 100))
watch_file "$PGDATA/postgresql.conf"
watch_file ./dev.sh
watch_file ./pyproject.toml

View File

@ -13,6 +13,8 @@ jobs:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Environment setup
run: nix develop --command bash -c "poetry install"
- name: Test
run: nix develop --command bash -c "dev test"
env:

13
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
nix build && docker load <result && docker run --rm -ti network-inventory:latest
}
descriptions["build-container"]="Build and load OCI container."
tasks["build-container"]=build-container
@ -118,18 +118,21 @@ tasks["debug"]=debug
lint() {
echo "Running pylint"
pylint \
poetry run \
pylint \
--rc-file="$PROJECT_DIR/pyproject.toml" \
-j 0 \
-E "$PROJECT_DIR/src"
echo "Running mypy"
mypy --config-file="$PROJECT_DIR/pyproject.toml" "$PROJECT_DIR/src"
poetry run \
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 pytest \
DJANGO_SETTINGS_MODULE=network_inventory.settings.ram_test poetry run \
pytest \
-nauto \
--nomigrations \
--cov-config="$PROJECT_DIR/.coveragerc" \
@ -140,7 +143,7 @@ descriptions["test"]="Run the tests in the RAM DB and write a coverage report."
tasks["test"]=test
update() {
poetry update --lock
poetry update
}
descriptions["update"]="Update the dependencies."
tasks["update"]=update

View File

@ -18,45 +18,6 @@
"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,
@ -73,33 +34,10 @@
"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",
"poetry2nix": "poetry2nix"
"nixpkgs": "nixpkgs"
}
},
"systems": {
@ -116,21 +54,6 @@
"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",

109
flake.nix
View File

@ -3,34 +3,12 @@
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, 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:
outputs = { self, nixpkgs, flake-utils }:
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
inventory = pkgs.stdenv.mkDerivation {
src = ./.;
@ -45,40 +23,28 @@
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}")
];
# Put the venv on the repo, so direnv can access it
POETRY_VIRTUALENVS_IN_PROJECT = "true";
# Use python from path, so you can use a different version to the one
# bundled with poetry
POETRY_VIRTUALENVS_PREFER_ACTIVE_PYTHON = "true";
PYTHON_KEYRING_BACKEND = "keyring.backends.fail.Keyring";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc
# Add any missing library needed You can use the nix-index package
# to locate them, e.g.
# nix-locate -w --top-level --at-root /lib/libudev.so.1
];
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";
@ -86,38 +52,39 @@
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
inventory
pkgs.bashInteractive
pkgs.coreutils
inventory
pkgs.poetry
(pkgs.writeShellScriptBin "start-inventory" ''
if [ -f .first_run ]; then
sleep 2
${pkgs.inventoryEnv}/bin/django-admin collectstatic --noinput
${pkgs.inventoryEnv}/bin/django-admin makemigrations
${pkgs.inventoryEnv}/bin/django-admin migrate
django-admin collectstatic --noinput
django-admin makemigrations
django-admin migrate
else
${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')"
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')"
touch .first_run
fi
${pkgs.inventoryEnv}/bin/gunicorn network_inventory.wsgi:application --reload --bind 0.0.0.0:8000 --workers 3
gunicorn network_inventory.wsgi:application --reload --bind 0.0.0.0:8000 --workers 3
'')
];
};