I’m running API server with programmed endpoint to read a file content and return as a response.
File is placed in a /var
directory, but when I trying to read this file, using Python standart library, I bump into “File not found” exception.
I assume that my python script is unable to access /var directory of a filesystem, as it’s running inside some sort of it’s own environment.
I already bumped into similar issue, but with NixOS packages. When my systemd service needed access to some sort of packages, I did this:
systemd.services.serviceName = {
path = with pkgs; [
man
nix-channel
];
This time I tried to add required path into this systemd.services.<serviceName>.path
array:
systemd.services.api = {
path = [
"/var"
];
Although system was able to build with such approach, it also didn’t gave any positive results. cat
command that endpoint uses to read file contents still returns non-zero exit status and server sends 500 response.
Here’s a python code, that describes the endpoint(just to show, how paths are declared there):
#!/usr/bin/env python3
from flask import Flask, jsonify, request
from flask_restful import Resource, Api, reqparse
import pandas as pd
import ast
import subprocess
import os
@app.route("/getDKIM", methods=["GET"])
def getDkimKey():
with open("/var/domain") as domainFile:
domain = domainFile.readline()
domain = domain.rstrip("\n")
dkim = subprocess.check_output(["cat", "/var/dkim/" + domain + ".selector.txt"])
return jsonify(dkim)
if __name__ == '__main__':
app.run(port=5050, debug=False)
Please advice, how to give access to the /var
partition for the python script, packaged as a Nixpkgs package and running as systemd service