Turn program into a flake

This commit is contained in:
Danila Fedorin 2022-03-27 18:28:20 -07:00
parent 2b8397f319
commit 0caba82b7c
3 changed files with 119 additions and 3 deletions

View File

@ -1,4 +1,4 @@
{ bundlerEnv, ruby, stdenv }:
{ bundlerEnv, ruby, stdenv, katex-server }:
let
gems = bundlerEnv {
@ -13,14 +13,18 @@ in
stdenv.mkDerivation {
name = "katex-converter";
src = ./convert.rb;
buildInputs = [ gems ruby ];
buildInputs = [ katex-server gems ruby ];
unpackPhase = "echo 'Skipping unpack phase (nothing to unpack)'";
installPhase = ''
mkdir -p $out/{bin,share/katex-converter}
cp $src $out/share/katex-converter/convert.rb
cat > $out/bin/katex-converter <<EOF
#!/bin/sh -e
exec ${gems}/bin/bundle exec ${ruby}/bin/ruby $out/share/katex-converter/convert.rb \$@
${katex-server}/bin/katex-server &
server_pid=\$!
sleep 1
${gems}/bin/bundle exec ${ruby}/bin/ruby $out/share/katex-converter/convert.rb \$@
kill -KILL \$server_pid
EOF
chmod +x $out/bin/katex-converter
'';

92
flake.lock Normal file
View File

@ -0,0 +1,92 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1648297722,
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1648297722,
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"katex-server": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1648429554,
"narHash": "sha256-jNRd9gzrOIYlvuVr/Je2Uh6/FXRoGwAIjgVHhf2NOoE=",
"ref": "master",
"rev": "a277542d9b7eb23806b123aed41a0bd441ff669b",
"revCount": 4,
"type": "git",
"url": "https://dev.danilafe.com/Nix-Configs/katex-server"
},
"original": {
"type": "git",
"url": "https://dev.danilafe.com/Nix-Configs/katex-server"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1648425779,
"narHash": "sha256-0tcpEiiq3f3Hh77ax7QFuF15AnPaBIdDSbvrCUeyb9k=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1edfe6d91bd8348cfccacd72e82d1d06ad470117",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1648425779,
"narHash": "sha256-0tcpEiiq3f3Hh77ax7QFuF15AnPaBIdDSbvrCUeyb9k=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1edfe6d91bd8348cfccacd72e82d1d06ad470117",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"katex-server": "katex-server",
"nixpkgs": "nixpkgs_2"
}
}
},
"root": "root",
"version": 7
}

20
flake.nix Normal file
View File

@ -0,0 +1,20 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
katex-server.url = "git+https://dev.danilafe.com/Nix-Configs/katex-server";
};
outputs = { self, nixpkgs, flake-utils, katex-server }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
katex-html = pkgs.callPackage ./default.nix { katex-server = katex-server.defaultPackage.${system}; };
in
{
packages = { inherit katex-html; };
defaultPackage = katex-html;
}
);
}