From db85e40f318ce354b3a431ec46d573316d88afee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 11 Apr 2020 17:25:48 +0200 Subject: [PATCH] Add fiche module (a program to submit paste from command line) --- modules/default.nix | 1 + modules/webapps/fiche.nix | 53 +++++++++++++++++++++++++++++++++++++++ pkgs/default.nix | 2 ++ pkgs/fiche/default.nix | 7 ++++++ pkgs/fiche/fiche.json | 15 +++++++++++ 5 files changed, 78 insertions(+) create mode 100644 modules/webapps/fiche.nix create mode 100644 pkgs/fiche/default.nix create mode 100644 pkgs/fiche/fiche.json diff --git a/modules/default.nix b/modules/default.nix index 9ff6ea62..a503f922 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -9,6 +9,7 @@ mastodon = ./webapps/mastodon.nix; mediagoblin = ./webapps/mediagoblin.nix; peertube = ./webapps/peertube.nix; + fiche = ./webapps/fiche.nix; opendmarc = ./opendmarc.nix; openarc = ./openarc.nix; diff --git a/modules/webapps/fiche.nix b/modules/webapps/fiche.nix new file mode 100644 index 00000000..9061b2ea --- /dev/null +++ b/modules/webapps/fiche.nix @@ -0,0 +1,53 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.services.fiche; +in +{ + options.services.fiche = { + enable = lib.mkEnableOption "Enable fiche’s service"; + port = lib.mkOption { + type = lib.types.port; + description = "Port to listen to"; + }; + domain = lib.mkOption { + type = lib.types.str; + description = "Domain"; + }; + dataDir = lib.mkOption { + type = lib.types.path; + default = "/var/lib/fiche"; + description = "Directory where to place the pastes"; + }; + https = lib.mkEnableOption "Use https"; + }; + + config = lib.mkIf cfg.enable { + networking.firewall.allowedTCPPorts = [ cfg.port ]; + + + system.activationScripts.fiche = '' + mkdir -p /var/lib/fiche + ''; + systemd.services.fiche = { + description = "Fiche server"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + script = '' + exec ${pkgs.fiche}/bin/fiche -o ${cfg.dataDir} -d ${cfg.domain} ${lib.optionalString cfg.https "-S "} -p ${builtins.toString cfg.port} + ''; + + serviceConfig = { + ExecStartPre = [ + "+${pkgs.coreutils}/bin/install -m 0755 -o fiche -d /var/lib/fiche" + ]; + DynamicUser = true; + User = "fiche"; + PrivateTmp = true; + Restart = "always"; + WorkingDirectory = cfg.dataDir; + ReadWritePaths = cfg.dataDir; + }; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index a6630feb..b02c63ec 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -75,4 +75,6 @@ rec { }) {}).monero; niv = (import sources.niv {}).niv; + + fiche = callPackage ./fiche { inherit mylibs; }; } diff --git a/pkgs/fiche/default.nix b/pkgs/fiche/default.nix new file mode 100644 index 00000000..cc67fb09 --- /dev/null +++ b/pkgs/fiche/default.nix @@ -0,0 +1,7 @@ +{ stdenv, mylibs }: +stdenv.mkDerivation (mylibs.fetchedGithub ./fiche.json // rec { + installPhase = '' + mkdir -p $out/bin + install -m 0755 fiche $out/bin/ + ''; +}) diff --git a/pkgs/fiche/fiche.json b/pkgs/fiche/fiche.json new file mode 100644 index 00000000..036de7fc --- /dev/null +++ b/pkgs/fiche/fiche.json @@ -0,0 +1,15 @@ +{ + "tag": "4bba916-master", + "meta": { + "name": "fiche", + "url": "https://github.com/solusipse/fiche", + "branch": "master" + }, + "github": { + "owner": "solusipse", + "repo": "fiche", + "rev": "4bba916e0f4a54d98a3947df7e2d0714d92a8bab", + "sha256": "060pxn8ns2zqszv1dlf7zcaf42avn9svya6irwy5d1ry29hp2ds9", + "fetchSubmodules": true + } +} -- 2.41.0