done
This commit is contained in:
parent
cc1950aa94
commit
f1ff6afdc8
5 changed files with 130 additions and 180 deletions
224
flake.nix
224
flake.nix
|
|
@ -7,138 +7,102 @@
|
|||
"github:nixos/nixpkgs/nixos-unstable"; # Specify the version or channel as needed
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, ... }: {
|
||||
packages.x86_64-linux.calDavToCsv =
|
||||
nixpkgs.python3.pkgs.buildPythonApplication rec {
|
||||
pname = "calDAVtoCSV";
|
||||
version = "0.1.0";
|
||||
pyproject = true;
|
||||
|
||||
src = builtins.fetchGit {
|
||||
url = "git+https://git.stuce.ch/Stuce/calDAVtoCSV.git";
|
||||
# rev = "ca6bdb889085893cd4494cd1612a00f8e164ffac";
|
||||
};
|
||||
|
||||
build-system = with nixpkgs.python3.pkgs; [ setuptools ];
|
||||
|
||||
dependencies = with nixpkgs.python3.pkgs; [ caldav flask gunicorn ];
|
||||
|
||||
meta = {
|
||||
description =
|
||||
"middleman program between my radicale server and my esp32";
|
||||
license = nixpkgs.lib.licenses.mit;
|
||||
maintainers = with nixpkgs.lib.maintainers; [ stuce-bot ];
|
||||
};
|
||||
};
|
||||
nixosModules.calDavToCsv = { config, lib, pkgs, ... }:
|
||||
let cfg = config.services.calDavToCsv;
|
||||
in {
|
||||
options.services.calDavToCsv = {
|
||||
enable = lib.mkEnableOption "calDavToCsv";
|
||||
settings = lib.mkOption {
|
||||
description = ''
|
||||
Your config as an attribute set
|
||||
'';
|
||||
default = { };
|
||||
#TODO: provide example
|
||||
example = ''
|
||||
{
|
||||
}
|
||||
'';
|
||||
type = lib.types.submodule {
|
||||
# freeformType = lib.format.type;
|
||||
caldav = {
|
||||
address = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "tcp://:5232/";
|
||||
example =
|
||||
"unix:///var/run/authelia.sock?path=authelia&umask=0117";
|
||||
description = "Address of the caldav calendar";
|
||||
};
|
||||
username = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
example = "John-doe";
|
||||
description = "Username of the caldav calendar";
|
||||
};
|
||||
password = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
example = "unsafe-password";
|
||||
description =
|
||||
"Password of the caldav calendar, NOT RECOMMENDED, use passwordFile instead !";
|
||||
};
|
||||
passwordFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
example = "/var/lib/calDavToCsv/caldavPassword";
|
||||
description =
|
||||
"Password of the caldav calendar, NOT RECOMMENDED, use passwordFile instead !";
|
||||
};
|
||||
};
|
||||
server = {
|
||||
port = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = 8000;
|
||||
example = "6000";
|
||||
description =
|
||||
"Port of the server, that will need to be reverse proxied into";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
# config = lib.mkOption {
|
||||
# type = lib.types.attrs;
|
||||
# calDavToCsv = {
|
||||
# calDAV = {
|
||||
# address = "localhost:5232";
|
||||
# username = "username";
|
||||
# password = "password";
|
||||
# passwordFile = "/path/to/password";
|
||||
# };
|
||||
# server = { port = 8000; };
|
||||
# };
|
||||
# description = "User-defined configuration for the service";
|
||||
# };
|
||||
};
|
||||
# options.NixosModule = {
|
||||
# enable = lib.mkEnableOption "Enable calDAVtoCSV service";
|
||||
# port = lib.mkOption {
|
||||
# type = lib.types.int;
|
||||
# calDavToCsv = 8000;
|
||||
# description = "Port on which calDAVtoCSV will listen";
|
||||
# };
|
||||
# url = lib.mkOption {
|
||||
# type = lib.types.str;
|
||||
# description = "url of the calendar";
|
||||
# };
|
||||
# calendarUsername = lib.mkOption {
|
||||
# type = lib.types.str;
|
||||
# description = "username of the calendar account";
|
||||
# };
|
||||
# calendarName = lib.mkOption {
|
||||
# type = lib.types.str;
|
||||
# description =
|
||||
# "name of the calendar we will fetch the todo items from";
|
||||
# };
|
||||
# calendarPasswordFile = lib.mkOption {
|
||||
# type = lib.types.str;
|
||||
# description =
|
||||
# "file where we need to look for password to connect, needs to be readeable by the service user";
|
||||
# };
|
||||
# };
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.etc."config.ini".text = ''
|
||||
${lib.toIni cfg.settings}
|
||||
outputs = { self, nixpkgs, ... }:
|
||||
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
in {
|
||||
nixosModules.calDavToCsv = { config, lib, pkgs, ... }:
|
||||
let
|
||||
flaskApp = ./main.py;
|
||||
cfg = config.services.calDavToCsv;
|
||||
python-env = pkgs.python3.withPackages (ps: [ ps.flask ps.caldav ]);
|
||||
app_ini = pkgs.writeText "api.ini" ''
|
||||
[uwsgi]
|
||||
wsgi-file = ${flaskApp}
|
||||
callable = app
|
||||
http = :${toString cfg.port}
|
||||
processes = 1
|
||||
threads = 1
|
||||
master = true
|
||||
chmod-socket = 660
|
||||
vacuum = true
|
||||
plugins = python3
|
||||
die-on-term = true
|
||||
uid = calDAVtoCSV
|
||||
gid = calDAVtoCSV
|
||||
'';
|
||||
systemd.services.calDavToCsv = {
|
||||
description = "calDAV to CSV Service";
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart =
|
||||
"${pkgs.python3.pkgs.gunicorn}/bin/gunicorn -w 1 -b 0.0.0.0:${cfg.settings.server.port} main:app";
|
||||
Restart = "on-failure";
|
||||
uwsgi = pkgs.uwsgi.override {
|
||||
python3 = python-env;
|
||||
plugins = [ "python3" ];
|
||||
};
|
||||
|
||||
run-with-wsgi = pkgs.writeShellApplication {
|
||||
name = "run-app";
|
||||
text = ''
|
||||
export PYTHONPATH="${python-env}/lib/python${
|
||||
builtins.substring 0 4 python-env.python.version
|
||||
}/site-packages"
|
||||
${uwsgi}/bin/uwsgi --ini ${app_ini}
|
||||
'';
|
||||
};
|
||||
|
||||
in {
|
||||
options.services.calDavToCsv = {
|
||||
enable = lib.mkEnableOption "calDavToCsv";
|
||||
port = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 8000;
|
||||
description = "Port on which calDAVtoCSV will listen";
|
||||
};
|
||||
calendarUrl = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "url of the calendar";
|
||||
};
|
||||
calendarUsername = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "username of the calendar account";
|
||||
};
|
||||
calendarName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description =
|
||||
"name of the calendar we will fetch the todo items from";
|
||||
};
|
||||
calendarPasswordFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description =
|
||||
"file where we need to look for password to connect, needs to be readeable by the service user";
|
||||
};
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = self.packages.x86_64-linux.calDavToCsv;
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.etc."calDAVtoCSV/config.ini".text = ''
|
||||
[calDAV]
|
||||
address = ${cfg.calendarUrl}
|
||||
username = ${cfg.calendarUsername}
|
||||
calendarName = ${cfg.calendarName}
|
||||
passwordFile = ${cfg.calendarPasswordFile}
|
||||
[server]
|
||||
port = ${toString cfg.port}
|
||||
'';
|
||||
users.groups."calDAVtoCSV".name = "calDAVtoCSV";
|
||||
users.users."calDAVtoCSV" = {
|
||||
name = "calDAVtoCSV";
|
||||
isSystemUser = true;
|
||||
group = "calDAVtoCSV";
|
||||
};
|
||||
systemd.services.calDavToCsv = {
|
||||
description =
|
||||
"calDAV to CSV Service used as a middleman between my esp32 and my caldav server";
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${run-with-wsgi}/bin/run-app";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue