From 8876ce2ac71f26d1edcd9567517187eec9752560 Mon Sep 17 00:00:00 2001 From: Michael Walker Date: Sat, 17 Feb 2024 02:57:26 +0000 Subject: [PATCH] Switch to rust bookmarks --- flake.lock | 122 +-------------------------- flake.nix | 13 +-- hosts/carcosa/configuration.nix | 4 +- hosts/nyarlathotep/configuration.nix | 5 +- hosts/nyarlathotep/secrets.yaml | 6 +- packages/bookmarks/default.nix | 34 ++++---- shared/bookmarks/default.nix | 10 +-- shared/bookmarks/options.nix | 28 +++--- 8 files changed, 39 insertions(+), 183 deletions(-) diff --git a/flake.lock b/flake.lock index 50874de0..6be738ff 100644 --- a/flake.lock +++ b/flake.lock @@ -1,46 +1,5 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": [ - "systems" - ] - }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nix-github-actions": { - "inputs": { - "nixpkgs": [ - "poetry2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1698974481, - "narHash": "sha256-yPncV9Ohdz1zPZxYHQf47S8S0VrnhV7nNhCawY46hDA=", - "owner": "nix-community", - "repo": "nix-github-actions", - "rev": "4bb5e752616262457bc7ca5882192a564c0472d2", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nix-github-actions", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1707978831, @@ -57,39 +16,10 @@ "type": "github" } }, - "poetry2nix": { - "inputs": { - "flake-utils": [ - "flake-utils" - ], - "nix-github-actions": "nix-github-actions", - "nixpkgs": [ - "nixpkgs" - ], - "systems": "systems", - "treefmt-nix": "treefmt-nix" - }, - "locked": { - "lastModified": 1707195113, - "narHash": "sha256-xPFxTMe4rKE/ZWLlOWv22qpGwpozpR+U1zhyf1040Zk=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "4eb2ac54029af42a001c9901194e9ce19cbd8a40", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "poetry2nix", - "type": "github" - } - }, "root": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "poetry2nix": "poetry2nix", - "sops-nix": "sops-nix", - "systems": "systems_2" + "sops-nix": "sops-nix" } }, "sops-nix": { @@ -114,56 +44,6 @@ "repo": "sops-nix", "type": "github" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "id": "systems", - "type": "indirect" - } - }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "poetry2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1699786194, - "narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "e82f32aa7f06bbbd56d7b12186d555223dc399d1", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 21255717..789c26c8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,29 +1,18 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; - poetry2nix = { - url = "github:nix-community/poetry2nix"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "flake-utils"; - }; sops-nix = { url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs-stable.follows = "nixpkgs"; }; - flake-utils = { - url = "github:numtide/flake-utils"; - inputs.systems.follows = "systems"; - }; - systems.url = "github:nix-systems/default"; }; - outputs = { self, nixpkgs, poetry2nix, sops-nix, ... }@flakeInputs: + outputs = { self, nixpkgs, sops-nix, ... }@flakeInputs: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; - overlays = [ poetry2nix.overlays.default ]; }; in { diff --git a/hosts/carcosa/configuration.nix b/hosts/carcosa/configuration.nix index cc7887fd..52a0339f 100644 --- a/hosts/carcosa/configuration.nix +++ b/hosts/carcosa/configuration.nix @@ -378,7 +378,6 @@ in # bookmarks nixfiles.bookmarks.enable = true; - nixfiles.bookmarks.baseURI = "https://bookmarks.barrucadu.co.uk"; nixfiles.bookmarks.readOnly = true; # concourse @@ -441,8 +440,7 @@ in ''; bookmarks-receive-elasticsearch = '' env ES_HOST=${config.systemd.services.bookmarks.environment.ES_HOST} \ - DELETE_EXISTING_INDEX=1 \ - ${pkgs.nixfiles.bookmarks}/bin/python -m bookmarks.index.create - + ${pkgs.nixfiles.bookmarks}/bin/bookmarks_ctl import-index --drop-existing ''; in [ diff --git a/hosts/nyarlathotep/configuration.nix b/hosts/nyarlathotep/configuration.nix index 11e3b945..8c70e014 100644 --- a/hosts/nyarlathotep/configuration.nix +++ b/hosts/nyarlathotep/configuration.nix @@ -288,9 +288,6 @@ in ############################################################################### nixfiles.bookmarks.enable = true; - nixfiles.bookmarks.baseURI = "http://bookmarks.nyarlathotep.lan"; - nixfiles.bookmarks.environmentFile = config.sops.secrets."nixfiles/bookmarks/env".path; - sops.secrets."nixfiles/bookmarks/env" = { }; ############################################################################### @@ -526,7 +523,7 @@ in set -ex env "ES_HOST=$ES_HOST" \ - ${pkgs.nixfiles.bookmarks}/bin/python -m bookmarks.index.dump | \ + ${pkgs.nixfiles.bookmarks}/bin/bookmarks_ctl export-index | \ ssh -i "$SSH_KEY_FILE" \ -o UserKnownHostsFile=/dev/null \ -o StrictHostKeyChecking=no \ diff --git a/hosts/nyarlathotep/secrets.yaml b/hosts/nyarlathotep/secrets.yaml index 4f6d65e0..405932e5 100644 --- a/hosts/nyarlathotep/secrets.yaml +++ b/hosts/nyarlathotep/secrets.yaml @@ -4,8 +4,6 @@ users: remote_sync: ssh_private_key: ENC[AES256_GCM,data:lOfo8ALZTCq7GVEZ+2KCDch+mOkOrSm5oqJKUNP+JVqfxA3r2GV8071ESFme8oTmsLIl/u5W9UxK6GMobM5M4ynZUTr1H3/yLRMNrbymTqIrKeGejaIy4hZRbF4Pv4NgtRTbnBfP7HHHnhykARuROmmtLQVITrAi4j9BJ7smyzOd8rdeyOsHBioOd784DLUGXQaGAmEvBRGuZ/pq3hEV0kQof5I94V82A7zWjZpD4yO76e+LYCA0Eu2FxM88P5jkiTPWLxFciY0z++2QvPguuYeXeAFkDc7yR2hiWFWT+rtfZSGsBL+Czse9PZbatugHn59ZPEzvUlv+FTnx5Vc1o9fQYGWCJGerZY2Sg6AtPglEdrmeTtEeELGVmnK/i5etlRaOER4fGSIIoIQ/xAor/GK0laoMQtU/MDLcuvw8BtD91/yTwFYbrghe8BEbnO36OUFQFh4OIWo8pHnkfbPZtJF+fRjXiO5yEdZpx29pMrqkhWqvEeujGurLZvTcQLX2iJ0utmQ3zv2/d8c+mzNHPNxUvHAEkp3kUjyktq0aylyjTdw=,iv:rxxAph3k6JEFJaq1LbWfIj6ah1E9r6locEBDghf/7gE=,tag:oEp4/ILyn5YfEDgC7eMhiw==,type:str] nixfiles: - bookmarks: - env: ENC[AES256_GCM,data:Hw+/ug7sKjD6BKScmlerAw+B3pO7zSA4moJ71u9FQdXdG+o/NNQVwWhMVzVna/Ib22+TsvsPLzQ=,iv:6jLNK0pFjt2B4kJHhwHgVLFBciUPuyANrBeS5dnI4HA=,tag:tFa/ClwFFfZJ151birgpnA==,type:str] restic-backups: env: ENC[AES256_GCM,data:K+JPrEyTiwClQ7z7p8IIv3CQZ2I2FMWKM7fZp2bGdahrezv5WihM1layoMXaZKK3sX4Mh1egaRUaDIW89+tvQFEN8zvekBOd7m2upmxVjsayCOLdV1wPSD/YZBPt15pZnNI8iIciaQWGSVZHvFn+V3H49PvXzQV4r0N1NQYiBPinCBVpcw6P9309CAPMVFmA0tCwPNUHp1JOJcDolhdmCIgPfTpDCeoZ8/1Ln9J+T4W5kZ6vrMXtRmTvD6ItAnRNsUx+07mAvTP2kosVAIgT1h8nC5Nt3rv3dCdOVaK6ILahSwCY0fnDq9mQU0ALADF8jGbi0xIfidQDdZp/7OaAbjhUiwTBkSoFu5KAfUk=,iv:MS5LRsfpKg5alaxpBuXiI0JWA5zFfLsMUPFoYLtzqoo=,tag:EItXOV+GgqbXRyYFmkuweg==,type:str] services: @@ -35,8 +33,8 @@ sops: UFVZQkpPSUY1YWZlRlFCbDNBcHhzVmcKzBqO5fMoaNerJw3ovWXCPLQM0cDfte03 ZiXMnrIUfIf2AntjjnZKc84jsnubTyD2fQLGNVkAetmQ3PTb3OKXqQ== -----END AGE ENCRYPTED FILE----- - lastmodified: "2024-01-26T23:48:16Z" - mac: ENC[AES256_GCM,data:Sj6PMYullYi16nqwqxRLvXrCGCfSIeABt2MBTwsw4xAIrutcH0f9DVg7RLq5VDMbOuUGnxQhmMK1hvrTn6ZPma4JlwROGmg+q7WG6KQaNLfMr0wlz/sKGkEgmZg83vk8VyOzJna+ymEBo3dWwXMBAbInOtClqovt8Fr9gucxiHU=,iv:roZkkE7HHydKCn5Q2R4FRBLUYdkzAaUA3E3ndaAl+wc=,tag:tAHHAWCtN4kGRYQPgcQ3OQ==,type:str] + lastmodified: "2024-02-17T02:55:22Z" + mac: ENC[AES256_GCM,data:aSOVomfoEY8J9Wwie2YN8uRKodptwKQqMWvS7QNgcTrm8QzFG2E73tWPln+OQoRYmdZVeM948v7u0fl73G5bkC3SwYdizdxOG0MEyDyDQs0k2YLPyJpQB8KPf+xv4ME6C6LSYwGzQKUYN98/03Vyt6YWe+LTYOi6ZlPlX/fNo/I=,iv:Mj65qQay08OTFc3p6fAoVdaDEhoR2do/VkUf08m7/wA=,tag:jPLX2vhTTxJ6oHLYS9xDyA==,type:str] pgp: [] unencrypted_suffix: _unencrypted version: 3.8.1 diff --git a/packages/bookmarks/default.nix b/packages/bookmarks/default.nix index 07d4a178..35aee6a5 100644 --- a/packages/bookmarks/default.nix +++ b/packages/bookmarks/default.nix @@ -1,24 +1,24 @@ # A database and web app to keep track of my bookmarks. -{ poetry2nix, fetchFromGitHub, ... }: +{ rustPlatform, fetchFromGitHub, openssl, pkg-config, ... }: let githubOwner = "barrucadu"; githubRepo = "bookmarks"; - githubRev = "afe9c2a59c1e9d385074e17d684ac0ae7556fced"; - - app = poetry2nix.mkPoetryApplication { - projectDir = fetchFromGitHub { - owner = githubOwner; - repo = githubRepo; - rev = githubRev; - sha256 = "sha256-uSsycnSWpIBc7SojptIgvjLkoZ0gTScelfygLJ9zvxI="; - }; + githubRev = "ba0355602445d02a818a03d7343eecf19eadde7f"; +in +rustPlatform.buildRustPackage { + pname = githubRepo; + version = githubRev; - overrides = poetry2nix.overrides.withDefaults (self: super: { - elastic-transport = super.elastic-transport.overridePythonAttrs (old: { - buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools ]; - }); - }); + src = fetchFromGitHub { + owner = githubOwner; + repo = githubRepo; + rev = githubRev; + sha256 = "sha256-XSpE7XnieEIjwXewGKij6AXOaonCsKZC6zwx60Z3foI="; }; -in -app.dependencyEnv + + cargoSha256 = "sha256-b2nFcK3UnYYSAfKdbQdhEyWDhp/FUBZXvN1/TfgKkHs="; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ openssl ]; +} diff --git a/shared/bookmarks/default.nix b/shared/bookmarks/default.nix index 482eb0ee..0c126e55 100644 --- a/shared/bookmarks/default.nix +++ b/shared/bookmarks/default.nix @@ -26,15 +26,15 @@ in after = [ "network-online.target" "${backend}-bookmarks-db.service" ]; requires = [ "${backend}-bookmarks-db.service" ]; serviceConfig = { - ExecStart = "${pkgs.nixfiles.bookmarks}/bin/gunicorn -w 4 -t 60 -b 127.0.0.1:${toString cfg.port} bookmarks.serve:app"; - EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; + ExecStart = "${pkgs.nixfiles.bookmarks}/bin/bookmarks ${optionalString (!cfg.readOnly) "--allow-writes"}"; DynamicUser = "true"; Restart = "always"; }; environment = { - ALLOW_WRITES = if cfg.readOnly then "0" else "1"; - BASE_URI = cfg.baseURI; + BOOKMARKS_ADDRESS = "127.0.0.1:${toString cfg.port}"; ES_HOST = "http://127.0.0.1:${toString cfg.elasticsearchPort}"; + RUST_LOG = cfg.logLevel; + RUST_LOG_FORMAT = cfg.logFormat; }; }; @@ -52,7 +52,7 @@ in nixfiles.restic-backups.backups.bookmarks = { prepareCommand = '' - env ES_HOST=http://127.0.0.1:${toString cfg.elasticsearchPort} ${pkgs.nixfiles.bookmarks}/bin/python -m bookmarks.index.dump > elasticsearch-dump.json + env ES_HOST=${config.systemd.services.bookmarks.environment.ES_HOST} ${pkgs.nixfiles.bookmarks}/bin/bookmarks_ctl export-index > elasticsearch-dump.json ''; paths = [ "elasticsearch-dump.json" diff --git a/shared/bookmarks/options.nix b/shared/bookmarks/options.nix index e670d65a..796e3911 100644 --- a/shared/bookmarks/options.nix +++ b/shared/bookmarks/options.nix @@ -36,14 +36,6 @@ with lib; ''; }; - baseURI = mkOption { - type = types.str; - example = "https://bookmarks.barrucadu.co.uk"; - description = mdDoc '' - URI which the service will be exposed on, used to generate URLs. - ''; - }; - readOnly = mkOption { type = types.bool; default = false; @@ -53,17 +45,19 @@ with lib; ''; }; - environmentFile = mkOption { - type = types.nullOr types.str; - default = null; + logLevel = mkOption { + type = types.str; + default = "info"; description = mdDoc '' - Environment file to pass secrets into the service. This is of the form: - - ```text - YOUTUBE_API_KEY="..." - ``` + Verbosity of the log messages. + ''; + }; - This is only required if not running in read-only mode. + logFormat = mkOption { + type = types.str; + default = "json,no-time"; + description = mdDoc '' + Format of the log messages. ''; }; };