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;
};
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 = {
home-manager = {

View file

@ -30,7 +30,6 @@
mercurial = pkgs.mercurialFull.withExtensions (pm: with pm; [
hg-evolve
]);
netbox = pkgs.python3Packages.callPackage ./netbox {};
ubi_reader = pkgs.python3Packages.callPackage ./ubi_reader {};
prometheus-bird-exporter-lfty = pkgs.callPackage ./prometheus-bird-exporter-lfty.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
inherit (depot.ops) secrets;
netbox = depot.nix.pkgs.netbox.override {
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,
},
}
netboxConfiguration = ''
SECRET_KEY = '${secrets.netbox.secretKey}'
ADMINS = []
@ -61,8 +39,6 @@ let
INTERNAL_IPS = ('127.0.0.1', '::1')
LOGGING = {}
LOGIN_REQUIRED = True
LOGIN_TIMEOUT = None
@ -125,7 +101,6 @@ let
DATETIME_FORMAT = 'Y-m-d g:i a'
SHORT_DATETIME_FORMAT = 'Y-m-d H:i'
'';
};
in {
imports = [
../lib/bvm.nix
@ -150,62 +125,51 @@ in {
my.ip.tailscale = "100.81.27.52";
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.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;
};
users.groups.netbox = {};
users.users.netbox = {
home = "/srv/netbox";
isSystemUser = true;
createHome = true;
group = "netbox";
};
environment.systemPackages = with pkgs; [
netbox
];
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;
dataDir = "/srv/netbox";
extraConfig = lib.mkAfter (netboxConfiguration + ''
with open("${config.my.vault.secrets.netbox-s3-access-key.path}", "r") as f:
STORAGE_CONFIG['AWS_ACCESS_KEY_ID'] = f.readline()
with open("${config.my.vault.secrets.netbox-s3-secret-access-key.path}", "r") as f:
STORAGE_CONFIG['AWS_SECRET_ACCESS_KEY'] = f.readline()
'');
listenAddress = "127.0.0.1";
port = 8001;
package = pkgs.netbox_3_6;
secretKeyFile = config.my.vault.secrets.netbox-secret-key.path;
settings = {
ALLOWED_HOSTS = ["netbox.int.lukegb.com"];
};
};
@ -214,7 +178,7 @@ in {
recommendedProxySettings = true;
virtualHosts."netbox.int.lukegb.com" = {
locations."/static/" = {
alias = "${netbox}/share/netbox/netbox/static/";
alias = "/srv/netbox/static";
};
locations."/" = {
proxyPass = "http://127.0.0.1:8001";

View file

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