diff --git a/pkgs/servers/web-apps/netbox/config.patch b/pkgs/servers/web-apps/netbox/config.patch new file mode 100644 index 000000000000..1adc0b537a4e --- /dev/null +++ b/pkgs/servers/web-apps/netbox/config.patch @@ -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, diff --git a/pkgs/servers/web-apps/netbox/default.nix b/pkgs/servers/web-apps/netbox/default.nix new file mode 100644 index 000000000000..9ae6a520e968 --- /dev/null +++ b/pkgs/servers/web-apps/netbox/default.nix @@ -0,0 +1,112 @@ +{ lib +, pkgs +, fetchFromGitHub +, python3 + +, plugins ? ps: [] }: + +let + py = python3.override { + packageOverrides = self: super: { + django = super.django_3; + graphql-core = super.graphql-core.overridePythonAttrs (old: rec { + version = "3.1.7"; + src = fetchFromGitHub { + owner = "graphql-python"; + repo = old.pname; + rev = "v${version}"; + sha256 = "1mwwh55qd5bcpvgy6pyliwn8jkmj4yk4d2pqb6mdkgqhdic2081l"; + }; + }); + jsonschema = super.jsonschema.overridePythonAttrs (old: rec { + version = "3.2.0"; + src = self.fetchPypi { + pname = old.pname; + inherit version; + sha256 = "c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a"; + }; + }); + lxml = super.lxml.overridePythonAttrs (old: rec { + pname = "lxml"; + version = "4.6.5"; + + src = self.fetchPypi { + inherit pname version; + sha256 = "6e84edecc3a82f90d44ddee2ee2a2630d4994b8471816e226d2b771cda7ac4ca"; + }; + }); + }; + }; + + extraBuildInputs = plugins py.pkgs; +in +py.pkgs.buildPythonApplication rec { + pname = "netbox"; + version = "3.1.10"; + + src = fetchFromGitHub { + owner = "netbox-community"; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-qREq4FJHHTA9Vm6f9kSfiYqur2omFmdsoZ4OdaPFcpU="; + }; + + format = "other"; + + patches = [ + # Allow setting the STATIC_ROOT from within the configuration and setting a custom redis URL + ./config.patch + ]; + + propagatedBuildInputs = with py.pkgs; [ + django_3 + 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 + graphene-django + jinja2 + markdown + markdown-include + mkdocs-material + netaddr + pillow + psycopg2 + pyyaml + social-auth-core + social-auth-app-django + svgwrite + tablib + jsonschema + ] ++ extraBuildInputs; + + 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; + }; + + 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 ]; + }; + } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 33c961448916..08479d754a1c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8266,6 +8266,8 @@ with pkgs; netbootxyz-efi = callPackage ../tools/misc/netbootxyz-efi { }; + netbox = callPackage ../servers/web-apps/netbox { }; + netcat = libressl.nc; netcat-gnu = callPackage ../tools/networking/netcat { };