Something went wrong. Try again.
fork of ozone with nix stuff
Something went wrong. Try again.
ozone flake.nix
6.7 kB · 217 lines
Nix
at customized
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218{ description = "Bluesky Ozone moderation service";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
outputs = { self, nixpkgs, }: let supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
mkPackageSet = pkgs: pkgs.lib.makeScope pkgs.newScope (self: { # All the files needed to build the ozone UI and (most of) the backend: # the Next.js app sources, service entrypoints, lockfiles, config. src = let fs = pkgs.lib.fileset; in fs.toSource { root = ./.; fileset = fs.difference (fs.gitTracked ./.) (fs.unions [ ./nix ./flake.nix ]); };
# Minimal sources for reproducible yarn installs: just the manifests and # lockfiles that pin the dependency tree (no application code needed). yarnSrc = let fs = pkgs.lib.fileset; in fs.toSource { root = ./.; fileset = fs.unions [ ./package.json ./yarn.lock ./.yarnrc.yml ]; };
serviceYarnSrc = let fs = pkgs.lib.fileset; in fs.toSource { root = ./.; fileset = fs.unions [ ./service/package.json ./service/yarn.lock ./.yarnrc.yml ]; };
yarn-cli = self.callPackage ./nix/pkgs/yarn-cli.nix {};
# The full dependency tree, installed offline-safe into the store. The # hash is the pinned result of `yarn install --immutable`; bump it (or # the lockfile) and re-run to refresh. ozone-yarn-deps = self.callPackage ./nix/pkgs/yarn-deps.nix { yarn-cli = self.yarn-cli; } { name = "ozone-yarn-deps"; src = self.yarnSrc; outputHash = "sha256-YKTTpIWgresOam9GGXw+VEDXIvuW5pUPd+ZdpYJvOrQ="; };
# Minimal dependency tree for the service runtime only. ozone-service-yarn-deps = self.callPackage ./nix/pkgs/yarn-deps.nix { yarn-cli = self.yarn-cli; } { name = "ozone-service-yarn-deps"; src = self.serviceYarnSrc; subdir = "service"; outputHash = "sha256-+zcJ5N9FzzNtkZCel9cEKxJ9c/2FAzn4Gds9jdwB3X4="; };
ozone = self.callPackage ./nix/pkgs/ozone.nix { inherit (self) src ozone-yarn-deps ozone-service-yarn-deps; }; });
ozoneNixosFor = system: extraModules: nixpkgs.lib.nixosSystem { inherit system; modules = [self.nixosModules.ozone] ++ ( if builtins.isList extraModules then extraModules else [extraModules] ); };
# The Linux system to build the development VM for, given a host system. linuxVmSystem = system: let pkgs = nixpkgsFor.${system}; in if pkgs.stdenv.hostPlatform.isAarch64 then "aarch64-linux" else "x86_64-linux";
# Minimal disk bootstrap so the example configurations can be evaluated # (and acted upon) by e.g. `nixos-rebuild switch --flake .#ozone`. demoMachine = { system.stateVersion = "26.05"; fileSystems."/" = { device = "/dev/sda1"; fsType = "ext4"; }; boot.loader.grub.devices = ["/dev/sda"]; }; in { packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; packages = mkPackageSet pkgs; in { inherit (packages) ozone ozone-yarn-deps ozone-service-yarn-deps ; default = packages.ozone;
# The development VM runner (see nix/vm.nix). Built lazily by # `nix run .#vm` so that host environment variables are honored. vm = (import ./nix/vm.nix { inherit nixpkgs self; system = linuxVmSystem system; hostSystem = system; }) .config.system.build.vm; });
overlays.default = final: prev: { ozone = (mkPackageSet final).ozone; };
nixosModules.ozone = { lib, pkgs, ... }: { imports = [./nix/modules/ozone.nix];
services.ozone.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.ozone; };
nixosConfigurations = { # A full example Ozone server configuration. It enables the service, the # daemon, and a local PostgreSQL instance. Runtime secrets live in # /etc/ozone.env (see HOSTING.md for the exact variables) and are read # from disk at boot, keeping them out of the nix store. ozone = ozoneNixosFor "x86_64-linux" [ { services.ozone.enable = true; services.ozone.daemon.enable = true; services.ozone.database.enable = true; services.ozone.openFirewall = true; # or leave this out and set OZONE_DB_POSTGRES_URL via the env file services.ozone.database.password = "ozone"; services.ozone.environmentFile = "/etc/ozone.env"; } demoMachine ]; ozone-aarch64 = ozoneNixosFor "aarch64-linux" [ { services.ozone.enable = true; services.ozone.daemon.enable = true; } demoMachine ]; };
checks = let vmTestFor = system: { ozone-vm = import ./nix/tests/ozone.nix { inherit self; pkgs = nixpkgsFor.${system}; }; }; in { x86_64-linux = vmTestFor "x86_64-linux"; aarch64-linux = vmTestFor "aarch64-linux"; };
apps = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in { # `nix run .#vm` boots a development VM running Ozone. It forwards the # Ozone UI to localhost:3001 (configured in nix/vm.nix) and attaches the # serial console to the terminal. vm = { type = "app"; program = toString (pkgs.writeShellScript "launch-ozone-vm" '' rootDir="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" mkdir -p "$rootDir/nix/vm-data" cd "$rootDir/nix/vm-data" export TMPDIR=/tmp exec ${pkgs.lib.getExe (import ./nix/vm.nix { inherit self; nixpkgs = nixpkgs; system = linuxVmSystem system; hostSystem = system; }).config.system.build.vm} ''); }; });
formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); };}