From 4ceba930001259c6b4e3e7189a86b1463a2ccb9d Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 16 Feb 2020 03:05:47 +0100 Subject: machines/profpatsch/pkgs: clean up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove everything I haven’t been using: - nix with an override - some containerization attempt - taffybar with patches - git-annex with override - poezio - searx with patches - ghci with additional packages --- .../profpatsch/patches/searx-rm-soundcloud.patch | 15 -- machines/profpatsch/patches/searx-secret-key.patch | 250 --------------------- machines/profpatsch/patches/taffybar-color.patch | 40 ---- machines/profpatsch/patches/taffybar.patch | 71 ------ machines/profpatsch/pkgs.nix | 74 +----- machines/profpatsch/shiki.nix | 1 - 6 files changed, 1 insertion(+), 450 deletions(-) delete mode 100644 machines/profpatsch/patches/searx-rm-soundcloud.patch delete mode 100644 machines/profpatsch/patches/searx-secret-key.patch delete mode 100644 machines/profpatsch/patches/taffybar-color.patch delete mode 100644 machines/profpatsch/patches/taffybar.patch (limited to 'machines/profpatsch') diff --git a/machines/profpatsch/patches/searx-rm-soundcloud.patch b/machines/profpatsch/patches/searx-rm-soundcloud.patch deleted file mode 100644 index 35b427b9..00000000 --- a/machines/profpatsch/patches/searx-rm-soundcloud.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/searx/settings.yml b/searx/settings.yml -index 053cb44..48a542b 100644 ---- a/searx/settings.yml -+++ b/searx/settings.yml -@@ -437,10 +437,6 @@ engines: - engine : scanr_structures - disabled : True - -- - name : soundcloud -- engine : soundcloud -- shortcut : sc -- - - name : stackoverflow - engine : stackoverflow - shortcut : st diff --git a/machines/profpatsch/patches/searx-secret-key.patch b/machines/profpatsch/patches/searx-secret-key.patch deleted file mode 100644 index 448ef510..00000000 --- a/machines/profpatsch/patches/searx-secret-key.patch +++ /dev/null @@ -1,250 +0,0 @@ -diff --git a/README.rst b/README.rst -index 86334c3c..0f039cd5 100644 ---- a/README.rst -+++ b/README.rst -@@ -19,8 +19,7 @@ Installation - ``git clone https://github.com/asciimoo/searx.git && cd searx`` - - install dependencies: ``./manage.sh update_packages`` - - edit your -- `settings.yml `__ -- (set your ``secret_key``!) -+ `settings.yml ` - - run ``python searx/webapp.py`` to start the application - - For all the details, follow this `step by step -diff --git a/searx/settings.yml b/searx/settings.yml -index 00cac5fe..477b1da1 100644 ---- a/searx/settings.yml -+++ b/searx/settings.yml -@@ -10,7 +10,6 @@ search: - server: - port : 8888 - bind_address : "127.0.0.1" # address to listen on -- secret_key : "ultrasecretkey" # change this! - base_url : False # Set custom base_url. Possible values: False or "https://your.custom.host/location/" - image_proxy : False # Proxying image results through searx - http_protocol_version : "1.0" # 1.0 and 1.1 are supported -diff --git a/searx/settings_robot.yml b/searx/settings_robot.yml -index 070a0edb..27227f3a 100644 ---- a/searx/settings_robot.yml -+++ b/searx/settings_robot.yml -@@ -10,7 +10,6 @@ search: - server: - port : 11111 - bind_address : 127.0.0.1 -- secret_key : "ultrasecretkey" # change this! - base_url : False - image_proxy : False - http_protocol_version : "1.0" -diff --git a/searx/utils.py b/searx/utils.py -index 9494bdf3..6657e6f5 100644 ---- a/searx/utils.py -+++ b/searx/utils.py -@@ -3,6 +3,8 @@ import hashlib - import hmac - import os - import re -+import stat -+import xdg.BaseDirectory - - from babel.dates import format_date - from codecs import getincrementalencoder -@@ -336,3 +338,60 @@ def new_hmac(secret_key, url): - return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest() - else: - return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest() -+ -+ -+class SecretAppKeyError(IOError): -+ def __init__(self, reason, caught=None): -+ self.reason = reason -+ self.caught = caught -+ -+ def __str__(self): -+ err = "" -+ if self.caught is not None: -+ err = '\n' + str(self.caught) -+ return repr(self.reason) + err -+ -+ -+_secret_app_key_length = 512 -+ -+ -+_secret_app_key_file_name = "secret_key" -+ -+ -+# tries to read the secret key from the xdg cache directory, -+# if none exists it creates one -+# If directory is given it has to be an existing, readable directory. -+def get_secret_app_key(directory=None): -+ -+ if directory is None: -+ try: -+ directory = xdg.BaseDirectory.save_cache_path("searx") -+ except OSError as e: -+ raise SecretAppKeyError("could not get XDG_CACHE_HOME") -+ -+ # we save it as plaintext, assuming only the owner has access -+ f = os.path.join(directory, _secret_app_key_file_name) -+ -+ def saError(msg, e=None): -+ raise SecretAppKeyError("{} {}".format(f, msg), e) -+ -+ # if it exists, read it -+ if os.path.isfile(f): -+ try: -+ with open(f, 'r') as fh: -+ return fh.read() -+ except IOError as e: -+ saError("could not be read", e) -+ # if it doesn't, create it -+ else: -+ key = os.urandom(_secret_app_key_length) -+ try: -+ with open(f, 'w') as fh: -+ fh.write(key) -+ # the file should be readable/writable only by the owner -+ os.chmod(f, stat.S_IRUSR | stat.S_IWUSR) -+ return key -+ except IOError as e: -+ saError("could not be created", e) -+ except OSError as e: -+ saError("could not be chmodded to 600", e) -diff --git a/searx/webapp.py b/searx/webapp.py -index abbbce95..8614cf90 100644 ---- a/searx/webapp.py -+++ b/searx/webapp.py -@@ -29,6 +29,7 @@ import os - import sys - - import requests -+import xdg - - from searx import logger - logger = logger.getChild('webapp') -@@ -58,7 +59,7 @@ from searx.engines import ( - from searx.utils import ( - UnicodeWriter, highlight_content, html_to_text, get_resources_directory, - get_static_files, get_result_templates, get_themes, gen_useragent, -- dict_subset, prettify_url -+ dict_subset, prettify_url, get_secret_app_key - ) - from searx.version import VERSION_STRING - from searx.languages import language_codes -@@ -123,7 +124,11 @@ app = Flask( - - app.jinja_env.trim_blocks = True - app.jinja_env.lstrip_blocks = True --app.secret_key = settings['server']['secret_key'] -+ -+# notify the user that the secret_key is no longer used -+if 'secret_key' in settings['server']: -+ logger.warning(' The "secret_key" config key is no longer used.') -+app.secret_key = get_secret_app_key() - - if not searx_debug \ - or os.environ.get("WERKZEUG_RUN_MAIN") == "true" \ -@@ -280,7 +285,7 @@ def proxify(url): - url.encode('utf-8'), - hashlib.sha256).hexdigest() - -- return '{0}?{1}'.format(settings['result_proxy']['url'], -+ return '{0}?{1}'.format(settings['re sult_proxy']['url'], - urlencode(url_params)) - - -@@ -295,7 +300,7 @@ def image_proxify(url): - if settings.get('result_proxy'): - return proxify(url) - -- h = new_hmac(settings['server']['secret_key'], url.encode('utf-8')) -+ h = new_hmac(app.secret_key, url.encode('utf-8')) - - return '{0}?{1}'.format(url_for('image_proxy'), - urlencode(dict(url=url.encode('utf-8'), h=h))) -@@ -719,7 +724,7 @@ def image_proxy(): - if not url: - return '', 400 - -- h = new_hmac(settings['server']['secret_key'], url) -+ h = new_hmac(app.secret_key, url) - - if h != request.args.get('h'): - return '', 400 -diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py -index eb40e62e..b53aec27 100644 ---- a/tests/unit/test_utils.py -+++ b/tests/unit/test_utils.py -@@ -1,4 +1,8 @@ - # -*- coding: utf-8 -*- -+import os -+import tempfile -+import stat -+ - import mock - import sys - from searx.testing import SearxTestCase -@@ -103,3 +107,63 @@ class TestUnicodeWriter(SearxTestCase): - rows = [1, 2, 3] - self.unicode_writer.writerows(rows) - self.assertEqual(self.unicode_writer.writerow.call_count, len(rows)) -+ -+ -+class TestSecretAppKey(SearxTestCase): -+ -+ def setUp(self): -+ self.getkey = utils.get_secret_app_key -+ self.fn = utils._secret_app_key_file_name -+ -+ def keyfile(self, dir_): -+ return os.path.join(dir_, self.fn) -+ -+ @staticmethod -+ def freshdir(): -+ return tempfile.mkdtemp() -+ -+ # generation of a key -+ def test_empty_dir(self): -+ dir_ = self.freshdir() -+ key = self.getkey(dir_) -+ self.assertNotEqual(key, "") -+ file_ = self.keyfile(dir_) -+ self.assertTrue(os.path.isfile(file_)) -+ mode = os.stat(file_).st_mode -+ # equal to read and write for user -+ self.assertEquals(mode & (stat.S_IRWXG | stat.S_IRWXU | stat.S_IRWXO), -+ (stat.S_IRUSR | stat.S_IWUSR)) -+ -+ # generation & successive read of the generated key -+ def test_existing_key(self): -+ dir_ = self.freshdir() -+ key = self.getkey(dir_) -+ key2 = self.getkey(dir_) -+ self.assertEquals(key, key2) -+ -+ def test_not_nice(self): -+ def touch(f, mode): -+ open(f, 'w').close() -+ os.chmod(f, mode) -+ -+ def raisesappkeyerror(dir_): -+ with self.assertRaises(utils.SecretAppKeyError): -+ self.getkey(dir_) -+ -+ # input dir doesn't exist -+ raisesappkeyerror("") -+ -+ # read-only -+ d1 = self.freshdir() -+ touch(self.keyfile(d1), 0) -+ raisesappkeyerror(d1) -+ -+ # dir -+ d2 = self.freshdir() -+ os.mkdir(self.keyfile(d2)) -+ raisesappkeyerror(d2) -+ -+ # non-writable dir -+ d3 = self.freshdir() -+ os.chmod(d3, stat.S_IRUSR) -+ raisesappkeyerror(d3) diff --git a/machines/profpatsch/patches/taffybar-color.patch b/machines/profpatsch/patches/taffybar-color.patch deleted file mode 100644 index cfa1cce8..00000000 --- a/machines/profpatsch/patches/taffybar-color.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 45ff40992c8fe5593d5f3e03ef0765168c6325fb Mon Sep 17 00:00:00 2001 -From: Peder Stray -Date: Thu, 29 Oct 2015 17:37:56 +0100 -Subject: [PATCH] Load taffybar gtk configs after initGUI - -Since gtkrc files from themes seem to load anyway, load the default and -user gtkrc for taffybar after initGUI. please note that setting -gtk_color_scheme from any of these causes a lot of already loaded gtkrc -files to be reloaded. ---- - src/System/Taffybar.hs | 13 ++++++------- - 1 file changed, 6 insertions(+), 7 deletions(-) - -diff --git a/src/System/Taffybar.hs b/src/System/Taffybar.hs -index f119852..f7afe5e 100644 ---- a/src/System/Taffybar.hs -+++ b/src/System/Taffybar.hs -@@ -261,16 +261,15 @@ setTaffybarSize cfg window = do - - taffybarMain :: TaffybarConfig -> IO () - taffybarMain cfg = do -- -- Override the default GTK theme path settings. This causes the -- -- bar (by design) to ignore the real GTK theme and just use the -- -- provided minimal theme to set the background and text colors. -- -- Users can override this default. -- defaultGtkConfig <- getDefaultConfigFile "taffybar.rc" -- userGtkConfig <- getUserConfigFile "taffybar" "taffybar.rc" -- rcSetDefaultFiles [ defaultGtkConfig, userGtkConfig ] - - _ <- initGUI - -+ -- Load default and user gtk resources -+ defaultGtkConfig <- getDefaultConfigFile "taffybar.rc" -+ userGtkConfig <- getUserConfigFile "taffybar" "taffybar.rc" -+ rcParse defaultGtkConfig -+ rcParse userGtkConfig -+ - Just disp <- displayGetDefault - nscreens <- displayGetNScreens disp - screen <- case screenNumber cfg < nscreens of diff --git a/machines/profpatsch/patches/taffybar.patch b/machines/profpatsch/patches/taffybar.patch deleted file mode 100644 index a93fca1a..00000000 --- a/machines/profpatsch/patches/taffybar.patch +++ /dev/null @@ -1,71 +0,0 @@ -diff --git a/src/System/Taffybar/Battery.hs b/src/System/Taffybar/Battery.hs -index 5335eff..32c7efa 100644 ---- a/src/System/Taffybar/Battery.hs -+++ b/src/System/Taffybar/Battery.hs -@@ -9,6 +9,7 @@ - -- more advanced features could be supported if there is interest. - module System.Taffybar.Battery ( - batteryBarNew, -+ batteryIconNew, - textBatteryNew, - defaultBatteryConfig - ) where -@@ -108,30 +109,22 @@ defaultBatteryConfig = - | pct < 0.9 = (0.5, 0.5, 0.5) - | otherwise = (0, 1, 0) - ---- | A fancy graphical battery widget that represents the current ---- charge as a colored vertical bar. There is also a textual ---- percentage readout next to the bar. -+-- | - batteryBarNew :: BarConfig -- ^ Configuration options for the bar display -- -> Double -- ^ Polling period in seconds - -> IO Widget --batteryBarNew battCfg pollSeconds = do -+batteryBarNew battCfg = do - battCtxt <- batteryContextNew -- case battCtxt of -- Nothing -> do -- let lbl :: Maybe String -- lbl = Just "No battery" -- labelNew lbl >>= return . toWidget -- Just ctxt -> do -- -- This is currently pretty inefficient - each poll period it -- -- queries the battery twice (once for the label and once for -- -- the bar). -- -- -- -- Converting it to combine the two shouldn't be hard. -- b <- hBoxNew False 1 -- txt <- textBatteryNew "$percentage$%" pollSeconds -- r <- newIORef ctxt -- bar <- pollingBarNew battCfg pollSeconds (battPct r) -- boxPackStart b bar PackNatural 0 -- boxPackStart b txt PackNatural 0 -- widgetShowAll b -- return (toWidget b) -+ let noBat = toWidget <$> labelNew (Just "No battery" :: Maybe String) -+ maybe noBat (batteryIconNew battCfg) battCtxt -+ -+-- | A fancy graphical battery widget that represents the current -+-- charge as a colored vertical bar. -+batteryIconNew :: BarConfig -+ -> BatteryContext -+ -> IO Widget -+batteryIconNew cfg ctxt = do -+ icon <- pollingBarNew cfg pollSeconds . battPct =<< newIORef ctxt -+ widgetShowAll icon -+ return icon -+ where -+ pollSeconds = 5 -diff --git a/src/System/Taffybar/Widgets/PollingBar.hs b/src/System/Taffybar/Widgets/PollingBar.hs -index d30adaf..01f161c 100644 ---- a/src/System/Taffybar/Widgets/PollingBar.hs -+++ b/src/System/Taffybar/Widgets/PollingBar.hs -@@ -16,6 +16,7 @@ import Control.Monad ( forever ) - import Graphics.UI.Gtk - - import System.Taffybar.Widgets.VerticalBar -+import Debug.Trace - - pollingBarNew :: BarConfig -> Double -> IO Double -> IO Widget - pollingBarNew cfg pollSeconds action = do diff --git a/machines/profpatsch/pkgs.nix b/machines/profpatsch/pkgs.nix index 24d089c0..98a7988c 100644 --- a/machines/profpatsch/pkgs.nix +++ b/machines/profpatsch/pkgs.nix @@ -2,63 +2,12 @@ let - nix = pkgs.nix.overrideAttrs (old: { - patches = old.patches or [] ++ [ - (pkgs.fetchpatch { - url = "https://github.com/NixOS/nix/commit/486872150638d56483c2bc429ba9e137d9974ee8.patch"; - sha256 = "0g0bp7gw6aqrscxkfmg6ykw91vm7b602h2dwbl53ycsa92bqfayq"; - }) ]; - }); - - addPythonRuntimeDeps = drv: deps: drv.overrideDerivation (old: { - propagatedNativeBuildInputs = old.propagatedNativeBuildInputs ++ deps; - }); - - # containered = name: packages: users: { ... }: - # { - # containers."${name}" = { - # config = { - # environment.systemPackages = packages; - # users.users = users; - # services.sshd.enable = true; - # }; - # privateNetwork = true; - # localAddress = "127.0.0.2"; - # }; - # nixpkgs.config.allowUnfree = true; - # }; - - # pkgs - - taffybar = pkgs.taffybar.override { - ghcWithPackages = (pkgs.haskellPackages.override { - overrides = _: super: { - taffybar = super.taffybar.overrideDerivation (old: { - name = old.name + "foo"; - patches = (old.patches or []) ++ [ ./patches/taffybar.patch ]; - postPatch = old.postPathPhase or "" + '' - patch -R ${./patches/taffybar-color.patch} - ''; - }); - }; - }).ghcWithPackages; - }; - mpv = pkgs.mpv-with-scripts.override { scripts = [ pkgs.mpvScripts.convert ]; }; beets = pkgs.beets.override { enableAlternatives = true; }; - # git-annex = hplts.git-annex.overrideDerivation (old: { - # buildInputs = old.buildInputs ++ [ pkgs.makeWrapper ]; - # postFixup = '' - # wrapProgram $out/bin/git-annex --prefix PATH ":" "${getBin pkgs.lsof}/bin"; - # ''; - # }); - - poezio = pkgs.python34Packages.poezio; - vim = pkgs.vim_configurable; fast-init = pkgs.haskellPackages.callPackage (import "${(pkgs.fetchFromGitHub { @@ -69,22 +18,6 @@ let sha256 = "03006xzs250knzcyr6j564kn9jf2a6cp3mxkpqsqmmyp6v28w90z"; })}/overrides.nix") {}; - # searx = pkgs.searx.overrideAttrs (old: { - # propagatedBuildInputs = old.propagatedBuildInputs ++ [ pythonPackages.pyxdg ]; - # patches = old.patches or [] ++ [ - # ./patches/searx-secret-key.patch - # ./patches/searx-rm-soundcloud.patch - # ]; - # # xdg.BaseDirectory.save_cache_path() will try to create leading dirs, but - # # within the builder we don't have a writable home directory. - # preCheck = (old.preCheck or "") + '' - # export XDG_CACHE_HOME="$TMPDIR/cache" - # ''; - # }); - - # A ghci with some sane default packages in scope, & hoogle - saneGhci = pkgs.haskellPackages.ghcWithHoogle (h: with h; [ protolude pretty-show ]); - pyrnotify = let src = pkgs.fetchFromGitHub { owner = "arnottcr"; @@ -102,15 +35,10 @@ let in { inherit - nix - taffybar mpv beets - poezio vim - fast-init - saneGhci - /*searx*/ + # fast-init pyrnotify ; } diff --git a/machines/profpatsch/shiki.nix b/machines/profpatsch/shiki.nix index 90e91ffc..0bacb6e8 100644 --- a/machines/profpatsch/shiki.nix +++ b/machines/profpatsch/shiki.nix @@ -195,7 +195,6 @@ in { emacs # pretty neat operating system i guess feh # brother of meh, displays images in a meh way, but fast filezilla # FTP GUI business-ready interface framework - myPkgs.saneGhci # GloriousGlasgow Haskell Compiler, mostly for ghci gimp # graphics inkscape # vector graphics libreoffice # a giant ball of C++, that sometimes helps with proprietary shitformats -- cgit 1.4.1