netbox_3_3: init

reintroduce previous version, use in NixOS module if stateVersion < 23.05

authored by Minijackson and committed by Raito Bezarius 78eb4d64 6e054138

+203 -3
+12 -1
nixos/modules/services/web-apps/netbox.nix
··· 14 }; 15 configFile = pkgs.concatText "configuration.py" [ settingsFile extraConfigFile ]; 16 17 - pkg = (pkgs.netbox.overrideAttrs (old: { 18 installPhase = old.installPhase + '' 19 ln -s ${configFile} $out/opt/netbox/netbox/netbox/configuration.py 20 '' + optionalString cfg.enableLdap '' ··· 71 default = "[::1]"; 72 description = lib.mdDoc '' 73 Address the server will listen on. 74 ''; 75 }; 76
··· 14 }; 15 configFile = pkgs.concatText "configuration.py" [ settingsFile extraConfigFile ]; 16 17 + pkg = (cfg.package.overrideAttrs (old: { 18 installPhase = old.installPhase + '' 19 ln -s ${configFile} $out/opt/netbox/netbox/netbox/configuration.py 20 '' + optionalString cfg.enableLdap '' ··· 71 default = "[::1]"; 72 description = lib.mdDoc '' 73 Address the server will listen on. 74 + ''; 75 + }; 76 + 77 + package = mkOption { 78 + type = types.package; 79 + default = if versionAtLeast config.system.stateVersion "23.05" then pkgs.netbox else pkgs.netbox_3_3; 80 + defaultText = literalExpression '' 81 + if versionAtLeast config.system.stateVersion "23.05" then pkgs.netbox else pkgs.netbox_3_3; 82 + ''; 83 + description = lib.mdDoc '' 84 + NetBox package to use. 85 ''; 86 }; 87
+2 -1
nixos/tests/all-tests.nix
··· 460 netdata = handleTest ./netdata.nix {}; 461 networking.networkd = handleTest ./networking.nix { networkd = true; }; 462 networking.scripted = handleTest ./networking.nix { networkd = false; }; 463 - netbox = handleTest ./web-apps/netbox.nix {}; 464 # TODO: put in networking.nix after the test becomes more complete 465 networkingProxy = handleTest ./networking-proxy.nix {}; 466 nextcloud = handleTest ./nextcloud {};
··· 460 netdata = handleTest ./netdata.nix {}; 461 networking.networkd = handleTest ./networking.nix { networkd = true; }; 462 networking.scripted = handleTest ./networking.nix { networkd = false; }; 463 + netbox = handleTest ./web-apps/netbox.nix { inherit (pkgs) netbox; }; 464 + netbox_3_3 = handleTest ./web-apps/netbox.nix { netbox = pkgs.netbox_3_3; }; 465 # TODO: put in networking.nix after the test becomes more complete 466 networkingProxy = handleTest ./networking-proxy.nix {}; 467 nextcloud = handleTest ./nextcloud {};
+2 -1
nixos/tests/web-apps/netbox.nix
··· 8 testUser = "alice"; 9 testPassword = "verySecure"; 10 testGroup = "netbox-users"; 11 - in import ../make-test-python.nix ({ lib, pkgs, ... }: { 12 name = "netbox"; 13 14 meta = with lib.maintainers; { ··· 18 nodes.machine = { config, ... }: { 19 services.netbox = { 20 enable = true; 21 secretKeyFile = pkgs.writeText "secret" '' 22 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 23 '';
··· 8 testUser = "alice"; 9 testPassword = "verySecure"; 10 testGroup = "netbox-users"; 11 + in import ../make-test-python.nix ({ lib, pkgs, netbox, ... }: { 12 name = "netbox"; 13 14 meta = with lib.maintainers; { ··· 18 nodes.machine = { config, ... }: { 19 services.netbox = { 20 enable = true; 21 + package = netbox; 22 secretKeyFile = pkgs.writeText "secret" '' 23 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 24 '';
+114
pkgs/servers/web-apps/netbox/3.3.nix
···
··· 1 + { lib 2 + , pkgs 3 + , fetchFromGitHub 4 + , fetchpatch 5 + , nixosTests 6 + , python3 7 + 8 + , plugins ? ps: [] }: 9 + 10 + let 11 + py = python3.override { 12 + packageOverrides = self: super: { 13 + django = super.django_4; 14 + }; 15 + }; 16 + 17 + extraBuildInputs = plugins py.pkgs; 18 + in 19 + py.pkgs.buildPythonApplication rec { 20 + pname = "netbox"; 21 + version = "3.3.9"; 22 + 23 + format = "other"; 24 + 25 + src = fetchFromGitHub { 26 + owner = "netbox-community"; 27 + repo = pname; 28 + rev = "refs/tags/v${version}"; 29 + sha256 = "sha256-KhnxD5pjlEIgISl4RMbhLCDwgUDfGFRi88ZcP1ndMhI="; 30 + }; 31 + 32 + patches = [ 33 + # Allow setting the STATIC_ROOT from within the configuration and setting a custom redis URL 34 + ./config_3_3.patch 35 + ./graphql-3_2_0.patch 36 + # fix compatibility ith django 4.1 37 + (fetchpatch { 38 + url = "https://github.com/netbox-community/netbox/pull/10341/commits/ce6bf9e5c1bc08edc80f6ea1e55cf1318ae6e14b.patch"; 39 + sha256 = "sha256-aCPQp6k7Zwga29euASAd+f13hIcZnIUu3RPAzNPqgxc="; 40 + }) 41 + ]; 42 + 43 + propagatedBuildInputs = with py.pkgs; [ 44 + bleach 45 + django_4 46 + django-cors-headers 47 + django-debug-toolbar 48 + django-filter 49 + django-graphiql-debug-toolbar 50 + django-mptt 51 + django-pglocks 52 + django-prometheus 53 + django-redis 54 + django-rq 55 + django-tables2 56 + django-taggit 57 + django-timezone-field 58 + djangorestframework 59 + drf-yasg 60 + swagger-spec-validator # from drf-yasg[validation] 61 + graphene-django 62 + jinja2 63 + markdown 64 + markdown-include 65 + netaddr 66 + pillow 67 + psycopg2 68 + pyyaml 69 + sentry-sdk 70 + social-auth-core 71 + social-auth-app-django 72 + svgwrite 73 + tablib 74 + jsonschema 75 + ] ++ extraBuildInputs; 76 + 77 + buildInputs = with py.pkgs; [ 78 + mkdocs-material 79 + mkdocs-material-extensions 80 + mkdocstrings 81 + mkdocstrings-python 82 + ]; 83 + 84 + nativeBuildInputs = [ 85 + py.pkgs.mkdocs 86 + ]; 87 + 88 + postBuild = '' 89 + PYTHONPATH=$PYTHONPATH:netbox/ 90 + python -m mkdocs build 91 + ''; 92 + 93 + installPhase = '' 94 + mkdir -p $out/opt/netbox 95 + cp -r . $out/opt/netbox 96 + chmod +x $out/opt/netbox/netbox/manage.py 97 + makeWrapper $out/opt/netbox/netbox/manage.py $out/bin/netbox \ 98 + --prefix PYTHONPATH : "$PYTHONPATH" 99 + ''; 100 + 101 + passthru = { 102 + # PYTHONPATH of all dependencies used by the package 103 + pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs; 104 + 105 + tests.netbox = nixosTests.netbox_3_3; 106 + }; 107 + 108 + meta = with lib; { 109 + homepage = "https://github.com/netbox-community/netbox"; 110 + description = "IP address management (IPAM) and data center infrastructure management (DCIM) tool"; 111 + license = licenses.asl20; 112 + maintainers = with maintainers; [ n0emis raitobezarius ]; 113 + }; 114 + }
+50
pkgs/servers/web-apps/netbox/config_3_3.patch
···
··· 1 + diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py 2 + index d5a7bfaec..68754a8c5 100644 3 + --- a/netbox/netbox/settings.py 4 + +++ b/netbox/netbox/settings.py 5 + @@ -222,6 +222,7 @@ TASKS_REDIS_PASSWORD = TASKS_REDIS.get('PASSWORD', '') 6 + TASKS_REDIS_DATABASE = TASKS_REDIS.get('DATABASE', 0) 7 + TASKS_REDIS_SSL = TASKS_REDIS.get('SSL', False) 8 + TASKS_REDIS_SKIP_TLS_VERIFY = TASKS_REDIS.get('INSECURE_SKIP_TLS_VERIFY', False) 9 + +TASKS_REDIS_URL = TASKS_REDIS.get('URL') 10 + 11 + # Caching 12 + if 'caching' not in REDIS: 13 + @@ -236,11 +237,12 @@ CACHING_REDIS_SENTINELS = REDIS['caching'].get('SENTINELS', []) 14 + CACHING_REDIS_SENTINEL_SERVICE = REDIS['caching'].get('SENTINEL_SERVICE', 'default') 15 + CACHING_REDIS_PROTO = 'rediss' if REDIS['caching'].get('SSL', False) else 'redis' 16 + CACHING_REDIS_SKIP_TLS_VERIFY = REDIS['caching'].get('INSECURE_SKIP_TLS_VERIFY', False) 17 + +CACHING_REDIS_URL = REDIS['caching'].get('URL', f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}') 18 + 19 + CACHES = { 20 + 'default': { 21 + 'BACKEND': 'django_redis.cache.RedisCache', 22 + - 'LOCATION': f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_HOST}:{CACHING_REDIS_PORT}/{CACHING_REDIS_DATABASE}', 23 + + 'LOCATION': CACHING_REDIS_URL, 24 + 'OPTIONS': { 25 + 'CLIENT_CLASS': 'django_redis.client.DefaultClient', 26 + 'PASSWORD': CACHING_REDIS_PASSWORD, 27 + @@ -383,7 +385,7 @@ USE_X_FORWARDED_HOST = True 28 + X_FRAME_OPTIONS = 'SAMEORIGIN' 29 + 30 + # Static files (CSS, JavaScript, Images) 31 + -STATIC_ROOT = BASE_DIR + '/static' 32 + +STATIC_ROOT = getattr(configuration, 'STATIC_ROOT', os.path.join(BASE_DIR, 'static')).rstrip('/') 33 + STATIC_URL = f'/{BASE_PATH}static/' 34 + STATICFILES_DIRS = ( 35 + os.path.join(BASE_DIR, 'project-static', 'dist'), 36 + @@ -562,6 +564,14 @@ if TASKS_REDIS_USING_SENTINEL: 37 + 'socket_connect_timeout': TASKS_REDIS_SENTINEL_TIMEOUT 38 + }, 39 + } 40 + +elif TASKS_REDIS_URL: 41 + + RQ_PARAMS = { 42 + + 'URL': TASKS_REDIS_URL, 43 + + 'PASSWORD': TASKS_REDIS_PASSWORD, 44 + + 'SSL': TASKS_REDIS_SSL, 45 + + 'SSL_CERT_REQS': None if TASKS_REDIS_SKIP_TLS_VERIFY else 'required', 46 + + 'DEFAULT_TIMEOUT': RQ_DEFAULT_TIMEOUT, 47 + + } 48 + else: 49 + RQ_PARAMS = { 50 + 'HOST': TASKS_REDIS_HOST,
+21
pkgs/servers/web-apps/netbox/graphql-3_2_0.patch
···
··· 1 + diff --git a/netbox/netbox/graphql/scalars.py b/netbox/netbox/graphql/scalars.py 2 + index 7d14189dd..0a18e79d2 100644 3 + --- a/netbox/netbox/graphql/scalars.py 4 + +++ b/netbox/netbox/graphql/scalars.py 5 + @@ -1,6 +1,6 @@ 6 + from graphene import Scalar 7 + from graphql.language import ast 8 + -from graphql.type.scalars import MAX_INT, MIN_INT 9 + +from graphql.type.scalars import GRAPHQL_MAX_INT, GRAPHQL_MIN_INT 10 + 11 + 12 + class BigInt(Scalar): 13 + @@ -10,7 +10,7 @@ class BigInt(Scalar): 14 + @staticmethod 15 + def to_float(value): 16 + num = int(value) 17 + - if num > MAX_INT or num < MIN_INT: 18 + + if num > GRAPHQL_MAX_INT or num < GRAPHQL_MIN_INT: 19 + return float(num) 20 + return num 21 +
+2
pkgs/top-level/all-packages.nix
··· 10202 10203 netbox = callPackage ../servers/web-apps/netbox { }; 10204 10205 netcat = libressl.nc; 10206 10207 netcat-gnu = callPackage ../tools/networking/netcat { };
··· 10202 10203 netbox = callPackage ../servers/web-apps/netbox { }; 10204 10205 + netbox_3_3 = callPackage ../servers/web-apps/netbox/3.3.nix { }; 10206 + 10207 netcat = libressl.nc; 10208 10209 netcat-gnu = callPackage ../tools/networking/netcat { };