summaryrefslogtreecommitdiffstats
path: root/nixos
diff options
context:
space:
mode:
authorMartin Weinelt <mweinelt@users.noreply.github.com>2020-08-14 22:09:33 +0200
committerGitHub <noreply@github.com>2020-08-14 22:09:33 +0200
commitf1efdd2c0b2efb3af9e2822bd490ede184a2bf6f (patch)
tree2e2980608cc785161f92329dc6393c37e782d98f /nixos
parentcee1971dfd89c432eaa8afcb89a12963cdf7be22 (diff)
parent45d5dc2aa928bac6dc52b9087ecdc3c8d065cab5 (diff)
Merge pull request #89444 from mweinelt/pinnwand-module
nixos/pinnwand: init; steck: init at 0.5.0; nixos/tests/pinnwand: init
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/misc/pinnwand.nix78
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/pinnwand.nix86
4 files changed, 166 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 0d7d86690d61..2cc360782236 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -489,6 +489,7 @@
./services/misc/parsoid.nix
./services/misc/plex.nix
./services/misc/tautulli.nix
+ ./services/misc/pinnwand.nix
./services/misc/pykms.nix
./services/misc/radarr.nix
./services/misc/redmine.nix
diff --git a/nixos/modules/services/misc/pinnwand.nix b/nixos/modules/services/misc/pinnwand.nix
new file mode 100644
index 000000000000..aa1ee5cfaa77
--- /dev/null
+++ b/nixos/modules/services/misc/pinnwand.nix
@@ -0,0 +1,78 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.pinnwand;
+
+ format = pkgs.formats.toml {};
+ configFile = format.generate "pinnwand.toml" cfg.settings;
+in
+{
+ options.services.pinnwand = {
+ enable = mkEnableOption "Pinnwand";
+
+ port = mkOption {
+ type = types.port;
+ description = "The port to listen on.";
+ default = 8000;
+ };
+
+ settings = mkOption {
+ type = format.type;
+ description = ''
+ Your <filename>pinnwand.toml</filename> as a Nix attribute set. Look up
+ possible options in the <link xlink:href="https://github.com/supakeen/pinnwand/blob/master/pinnwand.toml-example">pinnwand.toml-example</link>.
+ '';
+ default = {
+ # https://github.com/supakeen/pinnwand/blob/master/pinnwand.toml-example
+ database_uri = "sqlite:///var/lib/pinnwand/pinnwand.db";
+ preferred_lexeres = [];
+ paste_size = 262144;
+ paste_help = ''
+ <p>Welcome to pinnwand, this site is a pastebin. It allows you to share code with others. If you write code in the text area below and press the paste button you will be given a link you can share with others so they can view your code as well.</p><p>People with the link can view your pasted code, only you can remove your paste and it expires automatically. Note that anyone could guess the URI to your paste so don't rely on it being private.</p>
+ '';
+ footer = ''
+ View <a href="//github.com/supakeen/pinnwand" target="_BLANK">source code</a>, the <a href="/removal">removal</a> or <a href="/expiry">expiry</a> stories, or read the <a href="/about">about</a> page.
+ '';
+ };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ systemd.services.pinnwand = {
+ description = "Pinnwannd HTTP Server";
+ after = [ "network.target" ];
+ wantedBy = [ "multi-user.target" ];
+
+ unitConfig.Documentation = "https://pinnwand.readthedocs.io/en/latest/";
+ serviceConfig = {
+ ExecStart = "${pkgs.pinnwand}/bin/pinnwand --configuration-path ${configFile} http --port ${toString(cfg.port)}";
+ StateDirectory = "pinnwand";
+ StateDirectoryMode = "0700";
+
+ AmbientCapabilities = [];
+ CapabilityBoundingSet = "";
+ DevicePolicy = "closed";
+ DynamicUser = true;
+ LockPersonality = true;
+ MemoryDenyWriteExecute = true;
+ PrivateDevices = true;
+ PrivateUsers = true;
+ ProtectClock = true;
+ ProtectControlGroups = true;
+ ProtectKernelLogs = true;
+ ProtectHome = true;
+ ProtectHostname = true;
+ ProtectKernelModules = true;
+ ProtectKernelTunables = true;
+ RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
+ RestrictNamespaces = true;
+ RestrictRealtime = true;
+ SystemCallArchitectures = "native";
+ SystemCallFilter = "@system-service";
+ UMask = "0077";
+ };
+ };
+ };
+}
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 7c35ba8b29d6..10432e1cb529 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -269,6 +269,7 @@ in
pgjwt = handleTest ./pgjwt.nix {};
pgmanage = handleTest ./pgmanage.nix {};
php = handleTest ./php {};
+ pinnwand = handleTest ./pinnwand.nix {};
plasma5 = handleTest ./plasma5.nix {};
plotinus = handleTest ./plotinus.nix {};
podman = handleTestOn ["x86_64-linux"] ./podman.nix {};
diff --git a/nixos/tests/pinnwand.nix b/nixos/tests/pinnwand.nix
new file mode 100644
index 000000000000..2204e74b2c28
--- /dev/null
+++ b/nixos/tests/pinnwand.nix
@@ -0,0 +1,86 @@
+import ./make-test-python.nix ({ pkgs, ...}:
+let
+ pythonEnv = pkgs.python3.withPackages (py: with py; [ appdirs toml ]);
+
+ port = 8000;
+ baseUrl = "http://server:${toString port}";
+
+ configureSteck = pkgs.writeScript "configure.py" ''
+ #!${pythonEnv.interpreter}
+ import appdirs
+ import toml
+ import os
+
+ CONFIG = {
+ "base": "${baseUrl}/",
+ "confirm": False,
+ "magic": True,
+ "ignore": True
+ }
+
+ os.makedirs(appdirs.user_config_dir('steck'))
+ with open(os.path.join(appdirs.user_config_dir('steck'), 'steck.toml'), "w") as fd:
+ toml.dump(CONFIG, fd)
+ '';
+in
+{
+ name = "pinnwand";
+ meta = with pkgs.stdenv.lib.maintainers; {
+ maintainers =[ hexa ];
+ };
+
+ nodes = {
+ server = { config, ... }:
+ {
+ networking.firewall.allowedTCPPorts = [
+ port
+ ];
+
+ services.pinnwand = {
+ enable = true;
+ port = port;
+ };
+ };
+
+ client = { pkgs, ... }:
+ {
+ environment.systemPackages = [ pkgs.steck ];
+ };
+ };
+
+ testScript = ''
+ start_all()
+
+ server.wait_for_unit("pinnwand.service")
+ client.wait_for_unit("network.target")
+
+ # create steck.toml config file
+ client.succeed("${configureSteck}")
+
+ # wait until the server running pinnwand is reachable
+ client.wait_until_succeeds("ping -c1 server")
+
+ # make sure pinnwand is listening
+ server.wait_until_succeeds("ss -lnp | grep ${toString port}")
+
+ # send the contents of /etc/machine-id
+ response = client.succeed("steck paste /etc/machine-id")
+
+ # parse the steck response
+ raw_url = None
+ removal_link = None
+ for line in response.split("\n"):
+ if line.startswith("View link:"):
+ raw_url = f"${baseUrl}/raw/{line.split('/')[-1]}"
+ if line.startswith("Removal link:"):
+ removal_link = line.split(":", 1)[1]
+
+ # check whether paste matches what we sent
+ client.succeed(f"curl {raw_url} > /tmp/machine-id")
+ client.succeed("diff /tmp/machine-id /etc/machine-id")
+
+ # remove paste and check that it's not available any more
+ client.succeed(f"curl {removal_link}")
+ client.fail(f"curl --fail {raw_url}")
+ '';
+})