Build the app as a Nix package, with a NixOS module to run it
All checks were successful
Build and Deploy to Production / test (push) Successful in 11m36s
Build and Deploy to Production / build (push) Successful in 49s
Build and Deploy to Production / deploy (push) Successful in 1m6s

packages.default is the app with its gems (bundlerEnv from Gemfile.lock
and gemset.nix, generated by bundix); bin/datacenterbingo is Puma serving
config.ru. nixosModules.default (services.datacenterbingo) runs it as a
hardened systemd service with a dynamic user, readiness from Puma
(Type=notify), settings in environment and secrets from a file. CI
checks that gemset.nix matches Gemfile.lock (bin/check-gemset) and
builds the package.

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

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 13:38:19 +04:00
commit adc6e824e5
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

51
nix/package.nix Normal file
View file

@ -0,0 +1,51 @@
# 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/datacenterbingo is Puma serving config.ru; pass -b and
# -t like to puma.
{
lib,
stdenvNoCC,
bundlerEnv,
makeWrapper,
ruby_4_0,
version,
}:
let
root = ../.;
gems = bundlerEnv {
name = "datacenterbingo-gems";
ruby = ruby_4_0;
gemfile = root + "/Gemfile";
lockfile = root + "/Gemfile.lock";
gemset = root + "/gemset.nix";
groups = [ "default" ];
};
in
stdenvNoCC.mkDerivation {
pname = "datacenterbingo";
inherit version;
src = lib.fileset.toSource {
inherit root;
fileset = lib.fileset.unions [
../app.rb
../config.ru
../lib
../views
../assets
];
};
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/share $out/bin
cp -r . $out/share/datacenterbingo
# The lock lists precompiled pg/ffi/prism for many platforms; Nix
# builds the source gems, so Bundler must not look for the others
makeWrapper ${gems}/bin/puma $out/bin/datacenterbingo \
--chdir $out/share/datacenterbingo \
--set-default RACK_ENV production \
--set BUNDLE_FORCE_RUBY_PLATFORM true \
--add-flags "--preload $out/share/datacenterbingo/config.ru"
'';
passthru = { inherit gems; };
meta.mainProgram = "datacenterbingo";
}