Make entrance-exam a flake
This commit is contained in:
parent
5bd1e821f7
commit
6ccd23c06a
6 changed files with 1276 additions and 35 deletions
120
flake.nix
Normal file
120
flake.nix
Normal file
|
@ -0,0 +1,120 @@
|
|||
{
|
||||
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";
|
||||
|
||||
buildPhase = ''
|
||||
# Compile bootsnap cache
|
||||
${gems}/bin/bundle exec bootsnap precompile --gemfile app/ lib/
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cp -r * $out
|
||||
rm -r $out/public
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
assets = pkgs.stdenv.mkDerivation {
|
||||
inherit src version;
|
||||
|
||||
pname = "entrance-exam-assets";
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
nodejs
|
||||
yarnConfigHook
|
||||
yarnBuildHook
|
||||
];
|
||||
|
||||
yarnOfflineCache = pkgs.fetchYarnDeps {
|
||||
yarnLock = src + "/yarn.lock";
|
||||
hash = "sha256-jmVSCKHjDT1vmVRyXinKka7hK5hA37ZyE/pvRZ7z6T0=";
|
||||
};
|
||||
|
||||
buildPhase = ''
|
||||
SECRET_KEY_BASE=000000 RAILS_ENV=production SKIP_YARN_INSTALL=1 ${gems}/bin/bundle exec rails assets:precompile
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
cp -r public $out
|
||||
'';
|
||||
};
|
||||
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
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue