asxpio/nix/package.nix
Sergei Poljanski 4c0b6c3eef
All checks were successful
Build and Deploy to Production / test (push) Successful in 10m15s
Build and Deploy to Production / build (push) Successful in 59s
Build and Deploy to Production / deploy (push) Successful in 1m42s
Build the app as a Nix package, with a NixOS module to run it
packages.default is the app with its gems (bundlerEnv from Gemfile.lock
and gemset.nix, generated by bundix): bin/asxpio is Puma serving
config.ru, bin/asxpio-monitor the reachability worker. Photos are
resized with ImageMagick 7's magick. nixosModules.default
(services.asxpio) runs both as hardened systemd services with a dynamic
user, the web one with readiness from Puma (Type=notify); settings and
secrets come from one environment file. CI checks that gemset.nix
matches Gemfile.lock (bin/check-gemset) and builds the package.

Checked locally: migrations on an empty database, /healthz and /, an
invoice PDF with the Noto fonts, a photo resized to WebP and cropped.

The container deploy stays until the NixOS service has taken over.

Assisted-by: Claude:opus-5-5
2026-11-17 14:01:16 +04:00

57 lines
1.7 KiB
Nix

# The app with its gems (bundlerEnv, from Gemfile.lock and gemset.nix;
# after changing Gemfile.lock run `nix run nixpkgs#bundix` to refresh
# gemset.nix). bin/asxpio is Puma serving config.ru (pass -b and -t like
# to puma); bin/asxpio-monitor is the reachability worker (bin/monitor).
{
lib,
stdenvNoCC,
bundlerEnv,
makeWrapper,
ruby_4_0,
imagemagick,
version,
}:
let
root = ../.;
gems = bundlerEnv {
name = "asxpio-gems";
ruby = ruby_4_0;
gemfile = root + "/Gemfile";
lockfile = root + "/Gemfile.lock";
gemset = root + "/gemset.nix";
groups = [ "default" ];
};
share = "$out/share/asxpio";
in
stdenvNoCC.mkDerivation {
pname = "asxpio";
inherit version;
src = lib.fileset.toSource {
inherit root;
fileset = lib.fileset.unions [
../asxpio.rb
../config.ru
../lib
../views
../public
../db
../bin/monitor
];
};
nativeBuildInputs = [ makeWrapper ];
# The lock lists precompiled pg/ffi/prism for many platforms; Nix builds
# the source gems, so Bundler must not look for the others. Photos are
# resized with ImageMagick 7's magick (the image had 6's convert).
installPhase = ''
mkdir -p $out/share $out/bin
cp -r . ${share}
common=(--chdir ${share} --set-default RACK_ENV production --set BUNDLE_FORCE_RUBY_PLATFORM true
--set-default BINGO_CONVERT ${imagemagick}/bin/magick)
makeWrapper ${gems}/bin/puma $out/bin/asxpio "''${common[@]}" \
--add-flags "--preload ${share}/config.ru"
makeWrapper ${gems.wrappedRuby}/bin/ruby $out/bin/asxpio-monitor "''${common[@]}" \
--add-flags ${share}/bin/monitor
'';
passthru = { inherit gems; };
meta.mainProgram = "asxpio";
}