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/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:
parent
8de75012ad
commit
adc6e824e5
1 changed files with 536 additions and 1 deletions
51
nix/package.nix
Normal file
51
nix/package.nix
Normal 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";
|
||||
}
|
||||
Loading…
Reference in a new issue