drop my own netbox build in favour of nixpkgs

This commit is contained in:
Luke Granger-Brown 2023-10-12 20:12:22 +00:00
parent 5e7c2d6cef
commit 6dd4431506
6 changed files with 110 additions and 1666 deletions

View file

@ -36,7 +36,7 @@ let
home-manager = depot.ops.home-manager-ext.built; home-manager = depot.ops.home-manager-ext.built;
}; };
aarch64-linux = builtins.removeAttrs x86_64-linux [ "home-manager" "pkg-authentik" ] // { aarch64-linux = builtins.removeAttrs x86_64-linux [ "home-manager" "pkg-authentik" ] // {
pkgs = builtins.removeAttrs x86_64-linux.pkgs [ "lutris" "plex-pass" "sheepshaver" "fr24feed" "netbox" "javaws-env" "copybara" ]; pkgs = builtins.removeAttrs x86_64-linux.pkgs [ "lutris" "plex-pass" "sheepshaver" "fr24feed" "javaws-env" "copybara" ];
}; };
x86_64-darwin = { x86_64-darwin = {
home-manager = { home-manager = {

View file

@ -30,7 +30,6 @@
mercurial = pkgs.mercurialFull.withExtensions (pm: with pm; [ mercurial = pkgs.mercurialFull.withExtensions (pm: with pm; [
hg-evolve hg-evolve
]); ]);
netbox = pkgs.python3Packages.callPackage ./netbox {};
ubi_reader = pkgs.python3Packages.callPackage ./ubi_reader {}; ubi_reader = pkgs.python3Packages.callPackage ./ubi_reader {};
prometheus-bird-exporter-lfty = pkgs.callPackage ./prometheus-bird-exporter-lfty.nix {}; prometheus-bird-exporter-lfty = pkgs.callPackage ./prometheus-bird-exporter-lfty.nix {};
eapol-test = pkgs.callPackage ./eapol-test.nix {}; eapol-test = pkgs.callPackage ./eapol-test.nix {};

View file

@ -1,105 +0,0 @@
{ buildPythonApplication
, overrideScope
, fetchFromGitHub
, lib
, callPackage
, configuration ? ""
, psycopg2
}:
let
deps = overrideScope (callPackage ./python-packages.nix {});
in
buildPythonApplication rec {
pname = "netbox";
version = "3.2.5";
src = fetchFromGitHub {
owner = "netbox-community";
repo = pname;
rev = "v${version}";
sha256 = "0blqlfl7djl1zb92cvqndy5l8drn0axjjqvhjc1q881h3sif123w";
};
propagatedBuildInputs = (with deps; [
bleach
django
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
gunicorn
Jinja2
Markdown
markdown-include
mkdocs-material
mkdocstrings
mkdocstrings-python-legacy
netaddr
pillow
PyYAML
sentry-sdk
social-auth-app-django
social-auth-core
svgwrite
tablib
tzdata
jsonschema
django-storages
]) ++ [
psycopg2
];
format = "other";
buildPhase = ''
runHook preBuild
# Do nothing.
runHook postBuild
'';
passAsFile = [ "configuration" ];
inherit configuration;
installPhase = ''
runHook preInstall
mkdir -p $out/share/netbox
cp -R . $out/share/netbox
PYVER="$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")"
PYDIR="$out/lib/python$PYVER"
mkdir -p $PYDIR
ln -s $out/share/netbox/netbox $PYDIR/site-packages
mkdir -p $out/bin
cp $out/share/netbox/netbox/manage.py $out/bin/netbox-manage
cat <<"EOF" >$out/bin/netbox-gunicorn
#!/usr/bin/python
import sys
from gunicorn.app.wsgiapp import run
if __name__ == '__main__':
sys.exit(run())
EOF
chmod +x $out/bin/netbox-gunicorn
cp $out/share/netbox/netbox/netbox/configuration_testing.py $out/share/netbox/netbox/netbox/configuration.py
PYTHONPATH=$PYDIR/site-packages:$PYTHONPATH python $out/bin/netbox-manage collectstatic --no-input
cp $configurationPath $out/share/netbox/netbox/netbox/configuration.py
runHook postInstall
'';
passthru.deps = deps;
}

File diff suppressed because it is too large Load diff

View file

@ -6,29 +6,7 @@
let let
inherit (depot.ops) secrets; inherit (depot.ops) secrets;
netbox = depot.nix.pkgs.netbox.override { netboxConfiguration = ''
configuration = ''
ALLOWED_HOSTS = ["netbox.int.lukegb.com"]
DATABASE = {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'netbox',
}
REDIS = {
'tasks': {
'HOST': 'localhost',
'PORT': 6379,
'DATABASE': 0,
'SSL': False,
},
'caching': {
'HOST': 'localhost',
'PORT': 6379,
'DATABASE': 1,
'SSL': False,
},
}
SECRET_KEY = '${secrets.netbox.secretKey}' SECRET_KEY = '${secrets.netbox.secretKey}'
ADMINS = [] ADMINS = []
@ -61,8 +39,6 @@ let
INTERNAL_IPS = ('127.0.0.1', '::1') INTERNAL_IPS = ('127.0.0.1', '::1')
LOGGING = {}
LOGIN_REQUIRED = True LOGIN_REQUIRED = True
LOGIN_TIMEOUT = None LOGIN_TIMEOUT = None
@ -125,7 +101,6 @@ let
DATETIME_FORMAT = 'Y-m-d g:i a' DATETIME_FORMAT = 'Y-m-d g:i a'
SHORT_DATETIME_FORMAT = 'Y-m-d H:i' SHORT_DATETIME_FORMAT = 'Y-m-d H:i'
''; '';
};
in { in {
imports = [ imports = [
../lib/bvm.nix ../lib/bvm.nix
@ -150,62 +125,51 @@ in {
my.ip.tailscale = "100.81.27.52"; my.ip.tailscale = "100.81.27.52";
my.ip.tailscale6 = "fd7a:115c:a1e0:ab12:4843:cd96:6251:1b34"; my.ip.tailscale6 = "fd7a:115c:a1e0:ab12:4843:cd96:6251:1b34";
services.postgresql = {
enable = true;
ensureDatabases = [
"netbox"
];
ensureUsers = [{
name = "netbox";
ensurePermissions = { "DATABASE netbox" = "ALL PRIVILEGES"; };
}];
};
services.postgresqlBackup.enable = true; services.postgresqlBackup.enable = true;
services.redis.servers."" = { my.vault.secrets.netbox-secret-key = {
restartUnits = ["netbox.service"];
group = "root";
template = ''
{{ with secret "kv/apps/netbox" }}
{{ .Data.data.secret-key }}
{{ end }}
'';
};
my.vault.secrets.netbox-s3-access-key = {
restartUnits = ["netbox.service"];
group = "root";
template = ''
{{ with secret "kv/apps/netbox" }}
{{ .Data.data.s3-access-key }}
{{ end }}
'';
};
my.vault.secrets.netbox-s3-secret-access-key = {
restartUnits = ["netbox.service"];
group = "root";
template = ''
{{ with secret "kv/apps/netbox" }}
{{ .Data.data.s3-secret-access-key }}
{{ end }}
'';
};
services.netbox = {
enable = true; enable = true;
}; dataDir = "/srv/netbox";
extraConfig = lib.mkAfter (netboxConfiguration + ''
users.groups.netbox = {}; with open("${config.my.vault.secrets.netbox-s3-access-key.path}", "r") as f:
users.users.netbox = { STORAGE_CONFIG['AWS_ACCESS_KEY_ID'] = f.readline()
home = "/srv/netbox"; with open("${config.my.vault.secrets.netbox-s3-secret-access-key.path}", "r") as f:
isSystemUser = true; STORAGE_CONFIG['AWS_SECRET_ACCESS_KEY'] = f.readline()
createHome = true; '');
group = "netbox"; listenAddress = "127.0.0.1";
}; port = 8001;
package = pkgs.netbox_3_6;
environment.systemPackages = with pkgs; [ secretKeyFile = config.my.vault.secrets.netbox-secret-key.path;
netbox settings = {
]; ALLOWED_HOSTS = ["netbox.int.lukegb.com"];
systemd.services.netbox-rq = {
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Type = "simple";
User = "netbox";
Group = "netbox";
WorkingDirectory = "/srv/netbox";
ExecStart = "${netbox}/bin/netbox-manage rqworker high default low";
Restart = "on-failure";
RestartSec = 30;
PrivateTmp = true;
};
};
systemd.services.netbox = {
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Type = "simple";
User = "netbox";
Group = "netbox";
WorkingDirectory = "/srv/netbox";
PIDFile = "/srv/netbox/gunicorn.pid";
ExecStart = "${netbox}/bin/netbox-gunicorn --pid /srv/netbox/gunicorn.pid --config ${netbox}/share/netbox/contrib/gunicorn.py netbox.wsgi";
Restart = "on-failure";
RestartSec = 30;
PrivateTmp = true;
}; };
}; };
@ -214,7 +178,7 @@ in {
recommendedProxySettings = true; recommendedProxySettings = true;
virtualHosts."netbox.int.lukegb.com" = { virtualHosts."netbox.int.lukegb.com" = {
locations."/static/" = { locations."/static/" = {
alias = "${netbox}/share/netbox/netbox/static/"; alias = "/srv/netbox/static";
}; };
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:8001"; proxyPass = "http://127.0.0.1:8001";

View file

@ -71,6 +71,7 @@
my.apps.ads-b = {}; my.apps.ads-b = {};
my.apps.nixbuild = {}; my.apps.nixbuild = {};
my.apps.tumblrandom = {}; my.apps.tumblrandom = {};
my.apps.netbox = {};
my.servers.etheroute-lon01.apps = [ "pomerium" ]; my.servers.etheroute-lon01.apps = [ "pomerium" ];
my.servers.howl.apps = [ "nixbuild" ]; my.servers.howl.apps = [ "nixbuild" ];
@ -85,4 +86,5 @@
my.servers.bvm-heptapod.apps = [ "gitlab-runner" ]; my.servers.bvm-heptapod.apps = [ "gitlab-runner" ];
my.servers.bvm-nixosmgmt.apps = [ "plex-pass" ]; my.servers.bvm-nixosmgmt.apps = [ "plex-pass" ];
my.servers.blade-tuvok.apps = [ "fup" ]; my.servers.blade-tuvok.apps = [ "fup" ];
my.servers.bvm-netbox.apps = [ "netbox" ];
} }