I am trying to install Grafana and Clickhouse plugin for it via modified recipe and nix-env commands on my Linux Mint machine. Almost all the recipes for Grafana and the Clickhouse plugin are original and they were all taken from the official Nix repository. The only difference is that I changed the code in the post Install block of the recipe for Grafana. What I did it for will be described below.
Сommand with which I am trying to install the application and plugin: nix-env -i -f recipe.nix
Code from recipe.nix:
with import <nixpkgs> {};
let
grafanaPlugin = callPackage ./plugins/grafana-plugin.nix {};
in {
clickhousePLugin = callPackage ./plugins/grafana-clickhouse-datasource/default.nix {inherit grafanaPlugin;};
grafana = callPackage ./default.nix {};
}
Code from default.nix recipe for Grafana (here is only the postInstall part where I changed the code):
postInstall = ''
tar -xvf $srcStatic
mkdir -p $out/share/grafana
mv grafana-*/{public,conf,tools} $out/share/grafana/
cp ./conf/defaults.ini $out/share/grafana/conf/
pluginPath=`here should be the path to the found folder with Clickhouse plugin in the /nix/store/ directory using the "find" command`
mkdir -p $out/share/grafana/data/plugins
ln -s $pluginPath $out/share/grafana/data/plugins/clickhouse-plugin
chmod -R 777 $out/share/grafana/
'';
What am I trying to do:
I want that after installing Grafana and the plugin for it, I only need to create a service file for systemd so that Grafana itself starts automatically. Everything is fine, but there are some difficulties here.
- By creating a symlink in the
$out/share/grafana/data/pluginsdirectory, I'm trying to make Grafana start seeing this plugin and install it at startup. Another option: just copy the entire plugin folder to this directory, but it's not rational in my opinion.
Result: the symlink is not created for some unknown reason, although by the time the command to create it is executed, the folder with the plugin already exists
- To start the Grafana service, you need files that have been moved to the
$out/share/grafanadirectory. It follows that you need to run Grafana in this very directory. But there is a problem here: when Grafana starts, it creates several more files and folders in the working directory. And Nix makes all its folders with a resolution of 555 for almost all files and folders, so it is impossible to create anything in them because of permissions. So I decided to use the commandchmod -R 777 $out/share/grafana/
Result: the file folders remained with the same permissions as they were (555). It is not possible to run Grafana in this directory
Can someone explain why it is not possible to create a symlink and change the permissions of folders in postInstall scripts?
If this is possible or there are any other suggestions on how to solve these problems, I will be glad if you let me know.