Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netbox: 3.3.9 -> 3.4.7, netbox_3_3: init at 3.3.10, RFC42-style options, more tests #206983

Merged
merged 13 commits into from
Apr 5, 2023
Prev Previous commit
Next Next commit
netbox_3_3: init
reintroduce previous version, use in NixOS module if stateVersion < 23.05
  • Loading branch information
minijackson authored and RaitoBezarius committed Apr 4, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 78eb4d64e70b95389670f24d8b00631db00653b3
13 changes: 12 additions & 1 deletion nixos/modules/services/web-apps/netbox.nix
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ let
};
configFile = pkgs.concatText "configuration.py" [ settingsFile extraConfigFile ];

pkg = (pkgs.netbox.overrideAttrs (old: {
pkg = (cfg.package.overrideAttrs (old: {
installPhase = old.installPhase + ''
ln -s ${configFile} $out/opt/netbox/netbox/netbox/configuration.py
'' + optionalString cfg.enableLdap ''
@@ -74,6 +74,17 @@ in {
'';
};

package = mkOption {
type = types.package;
default = if versionAtLeast config.system.stateVersion "23.05" then pkgs.netbox else pkgs.netbox_3_3;
defaultText = literalExpression ''
if versionAtLeast config.system.stateVersion "23.05" then pkgs.netbox else pkgs.netbox_3_3;
'';
description = lib.mdDoc ''
NetBox package to use.
'';
};

port = mkOption {
type = types.port;
default = 8001;
3 changes: 2 additions & 1 deletion nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
@@ -460,7 +460,8 @@ in {
netdata = handleTest ./netdata.nix {};
networking.networkd = handleTest ./networking.nix { networkd = true; };
networking.scripted = handleTest ./networking.nix { networkd = false; };
netbox = handleTest ./web-apps/netbox.nix {};
netbox = handleTest ./web-apps/netbox.nix { inherit (pkgs) netbox; };
netbox_3_3 = handleTest ./web-apps/netbox.nix { netbox = pkgs.netbox_3_3; };
# TODO: put in networking.nix after the test becomes more complete
networkingProxy = handleTest ./networking-proxy.nix {};
nextcloud = handleTest ./nextcloud {};
3 changes: 2 additions & 1 deletion nixos/tests/web-apps/netbox.nix
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ let
testUser = "alice";
testPassword = "verySecure";
testGroup = "netbox-users";
in import ../make-test-python.nix ({ lib, pkgs, ... }: {
in import ../make-test-python.nix ({ lib, pkgs, netbox, ... }: {
name = "netbox";

meta = with lib.maintainers; {
@@ -18,6 +18,7 @@ in import ../make-test-python.nix ({ lib, pkgs, ... }: {
nodes.machine = { config, ... }: {
services.netbox = {
enable = true;
package = netbox;
secretKeyFile = pkgs.writeText "secret" ''
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
'';
114 changes: 114 additions & 0 deletions pkgs/servers/web-apps/netbox/3.3.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{ lib
, pkgs
, fetchFromGitHub
, fetchpatch
, nixosTests
, python3

, plugins ? ps: [] }:

let
py = python3.override {
packageOverrides = self: super: {
django = super.django_4;
};
};

extraBuildInputs = plugins py.pkgs;
in
py.pkgs.buildPythonApplication rec {
pname = "netbox";
version = "3.3.9";

format = "other";

src = fetchFromGitHub {
owner = "netbox-community";
repo = pname;
rev = "refs/tags/v${version}";
sha256 = "sha256-KhnxD5pjlEIgISl4RMbhLCDwgUDfGFRi88ZcP1ndMhI=";
};

patches = [
# Allow setting the STATIC_ROOT from within the configuration and setting a custom redis URL
./config_3_3.patch
./graphql-3_2_0.patch
# fix compatibility ith django 4.1
(fetchpatch {
url = "https://github.com/netbox-community/netbox/pull/10341/commits/ce6bf9e5c1bc08edc80f6ea1e55cf1318ae6e14b.patch";
sha256 = "sha256-aCPQp6k7Zwga29euASAd+f13hIcZnIUu3RPAzNPqgxc=";
})
];

propagatedBuildInputs = with py.pkgs; [
bleach
django_4
django-cors-headers
django-debug-toolbar
django-filter
django-graphiql-debug-toolbar
django-mptt
django-pglocks
django-prometheus
django-redis
django-rq
django-tables2
django-taggit
django-timezone-field
djangorestframework
drf-yasg
swagger-spec-validator # from drf-yasg[validation]
graphene-django
jinja2
markdown
markdown-include
netaddr
pillow
psycopg2
pyyaml
sentry-sdk
social-auth-core
social-auth-app-django
svgwrite
tablib
jsonschema
] ++ extraBuildInputs;

buildInputs = with py.pkgs; [
mkdocs-material
mkdocs-material-extensions
mkdocstrings
mkdocstrings-python
];

nativeBuildInputs = [
py.pkgs.mkdocs
];

postBuild = ''
PYTHONPATH=$PYTHONPATH:netbox/
python -m mkdocs build
'';

installPhase = ''
mkdir -p $out/opt/netbox
cp -r . $out/opt/netbox
chmod +x $out/opt/netbox/netbox/manage.py
makeWrapper $out/opt/netbox/netbox/manage.py $out/bin/netbox \
--prefix PYTHONPATH : "$PYTHONPATH"
'';

passthru = {
# PYTHONPATH of all dependencies used by the package
pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs;

tests.netbox = nixosTests.netbox_3_3;
};

meta = with lib; {
homepage = "https://github.com/netbox-community/netbox";
description = "IP address management (IPAM) and data center infrastructure management (DCIM) tool";
license = licenses.asl20;
maintainers = with maintainers; [ n0emis raitobezarius ];
};
}
50 changes: 50 additions & 0 deletions pkgs/servers/web-apps/netbox/config_3_3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
index d5a7bfaec..68754a8c5 100644
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -222,6 +222,7 @@ TASKS_REDIS_PASSWORD = TASKS_REDIS.get('PASSWORD', '')
TASKS_REDIS_DATABASE = TASKS_REDIS.get('DATABASE', 0)
TASKS_REDIS_SSL = TASKS_REDIS.get('SSL', False)
TASKS_REDIS_SKIP_TLS_VERIFY = TASKS_REDIS.get('INSECURE_SKIP_TLS_VERIFY', False)
+TASKS_REDIS_URL = TASKS_REDIS.get('URL')

# Caching
if 'caching' not in REDIS:
@@ -236,11 +237,12 @@ CACHING_REDIS_SENTINELS = REDIS['caching'].get('SENTINELS', [])
CACHING_REDIS_SENTINEL_SERVICE = REDIS['caching'].get('SENTINEL_SERVICE', 'default')
CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis'
CACHING_REDIS_SKIP_TLS_VERIFY = REDIS['caching'].get('INSECURE_SKIP_TLS_VERIFY', False)
+CACHING_REDIS_URL = REDIS['caching'].get('URL', f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}')

CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
- 'LOCATION': f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}',
+ 'LOCATION': CACHING_REDIS_URL,
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
'PASSWORD': CACHING_REDIS_PASSWORD,
@@ -383,7 +385,7 @@ USE_X_FORWARDED_HOST = True
X_FRAME_OPTIONS = 'SAMEORIGIN'

# Static files (CSS, JavaScript, Images)
-STATIC_ROOT = BASE_DIR + '/static'
+STATIC_ROOT = getattr(configuration, 'STATIC_ROOT', os.path.join(BASE_DIR, 'static')).rstrip('/')
STATIC_URL = f'/{BASE_PATH}static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'project-static', 'dist'),
@@ -562,6 +564,14 @@ if TASKS_REDIS_USING_SENTINEL:
'socket_connect_timeout': TASKS_REDIS_SENTINEL_TIMEOUT
},
}
+elif TASKS_REDIS_URL:
+ RQ_PARAMS = {
+ 'URL': TASKS_REDIS_URL,
+ 'PASSWORD': TASKS_REDIS_PASSWORD,
+ 'SSL': TASKS_REDIS_SSL,
+ 'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required',
+ 'DEFAULT_TIMEOUT': RQ_DEFAULT_TIMEOUT,
+ }
else:
RQ_PARAMS = {
'HOST': TASKS_REDIS_HOST,
21 changes: 21 additions & 0 deletions pkgs/servers/web-apps/netbox/graphql-3_2_0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/netbox/netbox/graphql/scalars.py b/netbox/netbox/graphql/scalars.py
index 7d14189dd..0a18e79d2 100644
--- a/netbox/netbox/graphql/scalars.py
+++ b/netbox/netbox/graphql/scalars.py
@@ -1,6 +1,6 @@
from graphene import Scalar
from graphql.language import ast
-from graphql.type.scalars import MAX_INT, MIN_INT
+from graphql.type.scalars import GRAPHQL_MAX_INT, GRAPHQL_MIN_INT


class BigInt(Scalar):
@@ -10,7 +10,7 @@ class BigInt(Scalar):
@staticmethod
def to_float(value):
num = int(value)
- if num > MAX_INT or num < MIN_INT:
+ if num > GRAPHQL_MAX_INT or num < GRAPHQL_MIN_INT:
return float(num)
return num

2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
@@ -10202,6 +10202,8 @@ with pkgs;

netbox = callPackage ../servers/web-apps/netbox { };

netbox_3_3 = callPackage ../servers/web-apps/netbox/3.3.nix { };

netcat = libressl.nc;

netcat-gnu = callPackage ../tools/networking/netcat { };