git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #89444 from mweinelt/pinnwand-module

nixos/pinnwand: init; steck: init at 0.5.0; nixos/tests/pinnwand: init

commitf1efdd2c0b2efb3af9e2822bd490ede184a2bf6f authorMartin Weinelt <mweinelt@users.noreply.github.com> dateFri 14 Aug 2020, 22:09 (6 years ago) parentcee197145d5dc2
7 files changed+216−7
nixos/modules/module-list.nix+1 nixos/modules/services/misc/pinnwand.nix+78 nixos/tests/all-tests.nix+1 nixos/tests/pinnwand.nix+86 pkgs/servers/pinnwand/default.nix+17−7 pkgs/servers/pinnwand/steck.nix+31 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -489,6 +489,7 @@
489489 ./services/misc/parsoid.nix
490490 ./services/misc/plex.nix
491491 ./services/misc/tautulli.nix
492+ ./services/misc/pinnwand.nix
492493 ./services/misc/pykms.nix
493494 ./services/misc/radarr.nix
494495 ./services/misc/redmine.nix
nixos/modules/services/misc/pinnwand.nixnew file+78
@@ -0,0 +1,78 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.pinnwand;
7+
8+ format = pkgs.formats.toml {};
9+ configFile = format.generate "pinnwand.toml" cfg.settings;
10+in
11+{
12+ options.services.pinnwand = {
13+ enable = mkEnableOption "Pinnwand";
14+
15+ port = mkOption {
16+ type = types.port;
17+ description = "The port to listen on.";
18+ default = 8000;
19+ };
20+
21+ settings = mkOption {
22+ type = format.type;
23+ description = ''
24+ Your <filename>pinnwand.toml</filename> as a Nix attribute set. Look up
25+ possible options in the <link xlink:href="https://github.com/supakeen/pinnwand/blob/master/pinnwand.toml-example">pinnwand.toml-example</link>.
26+ '';
27+ default = {
28+ # https://github.com/supakeen/pinnwand/blob/master/pinnwand.toml-example
29+ database_uri = "sqlite:///var/lib/pinnwand/pinnwand.db";
30+ preferred_lexeres = [];
31+ paste_size = 262144;
32+ paste_help = ''
33+ <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>
34+ '';
35+ footer = ''
36+ 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.
37+ '';
38+ };
39+ };
40+ };
41+
42+ config = mkIf cfg.enable {
43+ systemd.services.pinnwand = {
44+ description = "Pinnwannd HTTP Server";
45+ after = [ "network.target" ];
46+ wantedBy = [ "multi-user.target" ];
47+
48+ unitConfig.Documentation = "https://pinnwand.readthedocs.io/en/latest/";
49+ serviceConfig = {
50+ ExecStart = "${pkgs.pinnwand}/bin/pinnwand --configuration-path ${configFile} http --port ${toString(cfg.port)}";
51+ StateDirectory = "pinnwand";
52+ StateDirectoryMode = "0700";
53+
54+ AmbientCapabilities = [];
55+ CapabilityBoundingSet = "";
56+ DevicePolicy = "closed";
57+ DynamicUser = true;
58+ LockPersonality = true;
59+ MemoryDenyWriteExecute = true;
60+ PrivateDevices = true;
61+ PrivateUsers = true;
62+ ProtectClock = true;
63+ ProtectControlGroups = true;
64+ ProtectKernelLogs = true;
65+ ProtectHome = true;
66+ ProtectHostname = true;
67+ ProtectKernelModules = true;
68+ ProtectKernelTunables = true;
69+ RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
70+ RestrictNamespaces = true;
71+ RestrictRealtime = true;
72+ SystemCallArchitectures = "native";
73+ SystemCallFilter = "@system-service";
74+ UMask = "0077";
75+ };
76+ };
77+ };
78+}
nixos/tests/all-tests.nix+1
@@ -269,6 +269,7 @@ in
269269 pgjwt = handleTest ./pgjwt.nix {};
270270 pgmanage = handleTest ./pgmanage.nix {};
271271 php = handleTest ./php {};
272+ pinnwand = handleTest ./pinnwand.nix {};
272273 plasma5 = handleTest ./plasma5.nix {};
273274 plotinus = handleTest ./plotinus.nix {};
274275 podman = handleTestOn ["x86_64-linux"] ./podman.nix {};
nixos/tests/pinnwand.nixnew file+86
@@ -0,0 +1,86 @@
1+import ./make-test-python.nix ({ pkgs, ...}:
2+let
3+ pythonEnv = pkgs.python3.withPackages (py: with py; [ appdirs toml ]);
4+
5+ port = 8000;
6+ baseUrl = "http://server:${toString port}";
7+
8+ configureSteck = pkgs.writeScript "configure.py" ''
9+ #!${pythonEnv.interpreter}
10+ import appdirs
11+ import toml
12+ import os
13+
14+ CONFIG = {
15+ "base": "${baseUrl}/",
16+ "confirm": False,
17+ "magic": True,
18+ "ignore": True
19+ }
20+
21+ os.makedirs(appdirs.user_config_dir('steck'))
22+ with open(os.path.join(appdirs.user_config_dir('steck'), 'steck.toml'), "w") as fd:
23+ toml.dump(CONFIG, fd)
24+ '';
25+in
26+{
27+ name = "pinnwand";
28+ meta = with pkgs.stdenv.lib.maintainers; {
29+ maintainers =[ hexa ];
30+ };
31+
32+ nodes = {
33+ server = { config, ... }:
34+ {
35+ networking.firewall.allowedTCPPorts = [
36+ port
37+ ];
38+
39+ services.pinnwand = {
40+ enable = true;
41+ port = port;
42+ };
43+ };
44+
45+ client = { pkgs, ... }:
46+ {
47+ environment.systemPackages = [ pkgs.steck ];
48+ };
49+ };
50+
51+ testScript = ''
52+ start_all()
53+
54+ server.wait_for_unit("pinnwand.service")
55+ client.wait_for_unit("network.target")
56+
57+ # create steck.toml config file
58+ client.succeed("${configureSteck}")
59+
60+ # wait until the server running pinnwand is reachable
61+ client.wait_until_succeeds("ping -c1 server")
62+
63+ # make sure pinnwand is listening
64+ server.wait_until_succeeds("ss -lnp | grep ${toString port}")
65+
66+ # send the contents of /etc/machine-id
67+ response = client.succeed("steck paste /etc/machine-id")
68+
69+ # parse the steck response
70+ raw_url = None
71+ removal_link = None
72+ for line in response.split("\n"):
73+ if line.startswith("View link:"):
74+ raw_url = f"${baseUrl}/raw/{line.split('/')[-1]}"
75+ if line.startswith("Removal link:"):
76+ removal_link = line.split(":", 1)[1]
77+
78+ # check whether paste matches what we sent
79+ client.succeed(f"curl {raw_url} > /tmp/machine-id")
80+ client.succeed("diff /tmp/machine-id /etc/machine-id")
81+
82+ # remove paste and check that it's not available any more
83+ client.succeed(f"curl {removal_link}")
84+ client.fail(f"curl --fail {raw_url}")
85+ '';
86+})
pkgs/servers/pinnwand/default.nix+17−7
@@ -1,4 +1,4 @@
1−{ lib, python3, fetchFromGitHub }:
1+{ lib, python3, fetchFromGitHub, poetry, nixosTests }:
22
33let
44 python = python3.override {
@@ -14,13 +14,20 @@ let
1414 };
1515in with python.pkgs; buildPythonApplication rec {
1616 pname = "pinnwand";
17− version = "1.1.2";
17+ version = "1.2.1";
18+ format = "pyproject";
1819
19− src = fetchPypi {
20− inherit pname version;
21− sha256 = "0iincxkfyyx85ggx9ilms2f8aq4lcbg3rkqgrr4wlsflzhljqd0p";
20+ src = fetchFromGitHub {
21+ owner = "supakeen";
22+ repo = pname;
23+ rev = "v${version}";
24+ sha256 = "1rk7rpyb4vmqxqqv8k9jpjmgakr3mn1iaqxyj34r74p1n5vfzimq";
2225 };
2326
27+ nativeBuildInputs = [
28+ poetry
29+ ];
30+
2431 propagatedBuildInputs = [
2532 click
2633 docutils
@@ -30,11 +37,14 @@ in with python.pkgs; buildPythonApplication rec {
3037 sqlalchemy
3138 ];
3239
33− # tests are only available when fetching from GitHub, where they in turn don't have a setup.py :(
40+ checkInputs = [ pytest ];
41+
3442 checkPhase = ''
35− $out/bin/pinnwand --help > /dev/null
43+ pytest
3644 '';
3745
46+ passthru.tests = nixosTests.pinnwand;
47+
3848 meta = with lib; {
3949 homepage = "https://supakeen.com/project/pinnwand/";
4050 license = licenses.mit;
pkgs/servers/pinnwand/steck.nixnew file+31
@@ -0,0 +1,31 @@
1+{ lib, pkgs, python3Packages, nixosTests }:
2+
3+python3Packages.buildPythonApplication rec {
4+ pname = "steck";
5+ version = "0.6.0";
6+
7+ src = python3Packages.fetchPypi {
8+ inherit pname version;
9+ sha256 = "07gc5iwbyprb8nihnjjl2zd06z8p4nl3a3drzh9a8ny35ig1khq0";
10+ };
11+
12+ propagatedBuildInputs = with python3Packages; [
13+ pkgs.git
14+ appdirs
15+ click
16+ python_magic
17+ requests
18+ termcolor
19+ toml
20+ ];
21+
22+ passthru.tests = nixosTests.pinnwand;
23+
24+ meta = with lib; {
25+ homepage = "https://github.com/supakeen/steck";
26+ license = licenses.mit;
27+ description = "Client for pinnwand pastebin.";
28+ maintainers = with maintainers; [ hexa ];
29+ };
30+}
31+
pkgs/top-level/all-packages.nix+2
@@ -6917,6 +6917,8 @@ in
69176917
69186918 stdman = callPackage ../data/documentation/stdman { };
69196919
6920+ steck = callPackage ../servers/pinnwand/steck.nix { };
6921+
69206922 stenc = callPackage ../tools/backup/stenc { };
69216923
69226924 stm32loader = with python3Packages; toPythonApplication stm32loader;