Skip to content

Commit

Permalink
Merge pull request #269 from barrucadu/rust-bookmarks
Browse files Browse the repository at this point in the history
Switch to rust bookmarks
  • Loading branch information
barrucadu authored Feb 17, 2024
2 parents 97ef760 + 8876ce2 commit eba463d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 183 deletions.
122 changes: 1 addition & 121 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions hosts/carcosa/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ in

# bookmarks
nixfiles.bookmarks.enable = true;
nixfiles.bookmarks.baseURI = "https://bookmarks.barrucadu.co.uk";
nixfiles.bookmarks.readOnly = true;

# concourse
Expand Down Expand Up @@ -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
[
Expand Down
5 changes: 1 addition & 4 deletions hosts/nyarlathotep/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" = { };


###############################################################################
Expand Down Expand Up @@ -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 \
Expand Down
6 changes: 2 additions & 4 deletions hosts/nyarlathotep/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
34 changes: 17 additions & 17 deletions packages/bookmarks/default.nix
Original file line number Diff line number Diff line change
@@ -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 ];
}
10 changes: 5 additions & 5 deletions shared/bookmarks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand All @@ -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"
Expand Down
28 changes: 11 additions & 17 deletions shared/bookmarks/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
'';
};
};
Expand Down

0 comments on commit eba463d

Please sign in to comment.