105 lines
3.2 KiB
Nix
105 lines
3.2 KiB
Nix
{
|
|
description = "Entrance exam";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
devshell = {
|
|
url = "github:numtide/devshell";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, devshell, flake-utils }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlays.default ]; };
|
|
gems = pkgs.bundlerEnv rec {
|
|
name = "entrance-exam-env";
|
|
ruby = pkgs.ruby_3_4.override { jemallocSupport = true; };
|
|
gemfile = ./Gemfile;
|
|
lockfile = ./Gemfile.lock;
|
|
gemset = ./gemset.nix;
|
|
groups = [ "default" "development" "test" "production" ];
|
|
};
|
|
src = pkgs.lib.cleanSourceWith { filter = name: type: !(builtins.elem name [ ".github" "flake.lock" "flake.nix" ]); src = ./.; name = "source"; };
|
|
in
|
|
{
|
|
packages = rec {
|
|
default = entrance-exam;
|
|
entrance-exam = pkgs.stdenv.mkDerivation rec {
|
|
inherit src;
|
|
|
|
pname = "entrance-exam";
|
|
version = "0.1.0";
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
nodejs
|
|
yarnConfigHook
|
|
yarnBuildHook
|
|
];
|
|
|
|
yarnOfflineCache = pkgs.fetchYarnDeps {
|
|
yarnLock = src + "/yarn.lock";
|
|
hash = "sha256-jmVSCKHjDT1vmVRyXinKka7hK5hA37ZyE/pvRZ7z6T0=";
|
|
};
|
|
|
|
buildPhase = ''
|
|
# Compile bootsnap cache
|
|
${gems}/bin/bundle exec bootsnap precompile --gemfile app/ lib/
|
|
SECRET_KEY_BASE=000000 RAILS_ENV=production SKIP_YARN_INSTALL=1 ${gems}/bin/bundle exec rails assets:precompile
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp -r * $out
|
|
'';
|
|
|
|
passthru.env = gems;
|
|
};
|
|
};
|
|
|
|
devShells = rec {
|
|
default = entrance-exam;
|
|
entrance-exam = let
|
|
support-services = {
|
|
css.command = "yarn build:css --watch";
|
|
js.command = "yarn build:js --watch=forever";
|
|
};
|
|
all-services = support-services // {
|
|
rails = {
|
|
name = "server";
|
|
command = "rails s -p 3000";
|
|
};
|
|
};
|
|
in
|
|
pkgs.devshell.mkShell {
|
|
name = "Entrance Exam";
|
|
packages = [
|
|
gems
|
|
(pkgs.lowPrio gems.wrappedRuby)
|
|
pkgs.bundix
|
|
pkgs.nixpkgs-fmt
|
|
pkgs.yarn
|
|
pkgs.yarn2nix
|
|
];
|
|
serviceGroups = {
|
|
server.services = all-services;
|
|
server-support.services = support-services;
|
|
};
|
|
commands = [
|
|
{
|
|
name = "gems:update";
|
|
category = "dependencies";
|
|
help = "Update the `Gemfile.lock` and `gemset.nix` files";
|
|
command = ''
|
|
${pkgs.ruby_3_4}/bin/bundle lock
|
|
${pkgs.bundix}/bin/bundix
|
|
'';
|
|
}
|
|
];
|
|
};
|
|
};
|
|
}
|
|
);
|
|
}
|