-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed.xml
558 lines (500 loc) · 33.6 KB
/
feed.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><![CDATA[Magnus web site]]></title>
<description><![CDATA[Magnus web site]]></description>
<link>https://magnus.therning.org/</link>
<lastBuildDate>Sun, 01 Dec 2024 23:38:45 +0100</lastBuildDate>
<item>
<title><![CDATA[Servant and a weirdness in Keycloak]]></title>
<description><![CDATA[
<p>
When writing a small tool to interface with Keycloak I found an endpoint that
require the content type to be <code>application/json</code> while the body should be plain
text. (The details are in the <a href="https://github.com/keycloak/keycloak/issues/34401">issue</a>.) Since <a href="https://hackage.haskell.org/package/servant">servant</a> assumes that the content
type and the content match (I know, I'd always thought that was a safe
assumption to make too) it doesn't work with <code>ReqBody '[JSON] Text</code>. Instead I
had to create a custom type that's a combination of <a href="https://hackage.haskell.org/package/servant-0.20.2/docs/Servant-API-ContentTypes.html#t:JSON"><code>JSON</code></a> and <a href="https://hackage.haskell.org/package/servant-0.20.2/docs/Servant-API-ContentTypes.html#t:PlainText"><code>PlainText</code></a>,
something that turned out to required surprisingly little code:
</p>
<div class="org-src-container">
<pre class="src src-haskell"><span class="org-keyword">data</span> KeycloakJSON <span class="org-keyword">deriving</span> <span class="org-rainbow-delimiters-depth-1">(</span>Typeable<span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">instance</span> Accept <span class="org-type">KeycloakJSON</span> <span class="org-keyword">where</span>
<span class="org-function-name">contentType</span> _ = <span class="org-string">"application"</span> <span class="org-operator">//</span> <span class="org-string">"json"</span>
<span class="org-keyword">instance</span> MimeRender <span class="org-type">KeycloakJSON</span> <span class="org-type">Text</span> <span class="org-keyword">where</span>
<span class="org-function-name">mimeRender</span> _ = fromStrict <span class="org-operator">.</span> encodeUtf8
</pre>
</div>
<p>
The bug has already been fixed in Keycloak, but I'm sure there are other APIs
with similar weirdness so maybe this will be useful to someone else.
</p>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-haskell.html">haskell</a> <a href="https://magnus.therning.org/tag-servant.html">servant</a> </div>
]]></description>
<category><![CDATA[haskell]]></category>
<category><![CDATA[servant]]></category>
<link>https://magnus.therning.org/2024-12-01-servant-and-a-weirdness-in-keycloak.html</link>
<guid>https://magnus.therning.org/2024-12-01-servant-and-a-weirdness-in-keycloak.html</guid>
<pubDate>Sun, 01 Dec 2024 23:00:00 +0100</pubDate>
</item>
<item>
<title><![CDATA[Followup on secrets in my work notes]]></title>
<description><![CDATA[
<p>
I got the following question on my post on how I handle secrets in my work notes:
</p>
<blockquote>
<p>
Sounds like a nice approach for other secrets but how about <code>:dbconnection</code> for
Orgmode and <code>sql-connection-alist</code>?
</p>
</blockquote>
<p>
I have to admit I'd never come across the variable <code>sql-connection-alist</code>
before. I've never really used <code>sql-mode</code> for more than editing SQL queries and
setting up code blocks for running them was one of the first things I used
<a href="https://github.com/joaotavora/yasnippet">yasnippet</a> for.
</p>
<p>
I did a little reading and unfortunately it looks like <code>sql-connection-alist</code>
can only handle string values. However, there is a variable
<code>sql-password-search-wallet-function</code>, with the default value of
<code>sql-auth-source-search-wallet</code>, so using <a href="https://www.gnu.org/software/emacs/manual/html_mono/auth.html">auth-source</a> is already supported for
the password itself.
</p>
<p>
There seems to be a lack of good tutorials for setting up <code>sql-mode</code> in a secure
way – all articles I found place the password in clear-text in the config –
filling that gap would be a nice way to contribute to the Emacs community. I'm
sure it'd prompt me to re-evaluate incorporating <code>sql-mode</code> in my workflow.
</p>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-emacs.html">emacs</a> <a href="https://magnus.therning.org/tag-org-mode.html">org-mode</a> </div>
]]></description>
<category><![CDATA[emacs]]></category>
<category><![CDATA[org-mode]]></category>
<link>https://magnus.therning.org/2024-09-09-followup-on-secrets-in-my-work-notes.html</link>
<guid>https://magnus.therning.org/2024-09-09-followup-on-secrets-in-my-work-notes.html</guid>
<pubDate>Mon, 09 Sep 2024 22:36:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Improving how I handle secrets in my work notes]]></title>
<description><![CDATA[
<p>
At work I use org-mode to keep notes about useful ways to query our systems,
mostly that involves using the built-in SQL support to access DBs and <a href="https://github.com/ag91/ob-http">ob-http</a> to
send HTTP requests. In both cases I often need to provide credentials for the
systems. I'm embarrassed to admit it, but for a long time I've taken the easy
path and kept all credentials in clear text. Every time I've used one of those
code blocks I've thought I really ought to find a better way of handling these
secrets one of these days. Yesterday was that day.
</p>
<p>
I ended up with two functions that uses <a href="https://www.gnu.org/software/emacs/manual/html_mono/auth.html">auth-source</a> and its <code>~/.authinfo.gpg</code>
file.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">defun</span> <span class="org-function-name">mes/auth-get-pwd</span> <span class="org-rainbow-delimiters-depth-2">(</span>host<span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-doc">"Get the password for a host (authinfo.gpg)"</span>
<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-keyword">-></span> <span class="org-rainbow-delimiters-depth-3">(</span>auth-source-search <span class="org-builtin">:host</span> host<span class="org-rainbow-delimiters-depth-3">)</span>
car
<span class="org-rainbow-delimiters-depth-3">(</span>plist-get <span class="org-builtin">:secret</span><span class="org-rainbow-delimiters-depth-3">)</span>
funcall<span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">defun</span> <span class="org-function-name">mes/auth-get-key</span> <span class="org-rainbow-delimiters-depth-2">(</span>host key<span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-doc">"Get a key's value for a host (authinfo.gpg)</span>
<span class="org-doc">Not usable for getting the password (:secret), use '</span><span class="org-doc"><span class="org-constant">mes/auth-get-pwd</span></span><span class="org-doc">'</span>
<span class="org-doc">for that."</span>
<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-keyword">-></span> <span class="org-rainbow-delimiters-depth-3">(</span>auth-source-search <span class="org-builtin">:host</span> host<span class="org-rainbow-delimiters-depth-3">)</span>
car
<span class="org-rainbow-delimiters-depth-3">(</span>plist-get key<span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
It turns out that the library can handle more keys than the documentation
suggests so for DB entries I'm using a <code>machine</code> (<code>:host</code>) that's a bit shorter
and easier to remember than the full AWS hostname. Then I keep the DB host and
name in <code>dbhost</code> (<code>:dbhost</code>) and <code>dbname</code> (<code>:dbname</code>) respectively. That makes
an entry look like this:
</p>
<div class="org-src-container">
<pre class="src src-authinfo"><span class="org-variable-name">machine</span> <span class="org-builtin">db.svc</span> <span class="org-comment-delimiter">login</span> <span class="org-keyword">user</span> <span class="org-comment-delimiter">port</span> <span class="org-type">port</span> <span class="org-comment-delimiter">password</span> <span class="org-doc">pwd</span> <span class="org-constant">dbname</span> dbname <span class="org-constant">dbhost</span> dbhost
</pre>
</div>
<p>
If I use it in a property drawer it looks like this
</p>
<div class="org-src-container">
<pre class="src src-org"><span class="org-org-drawer">:PROPERTIES:</span>
<span class="org-org-special-keyword">:header-args:sql:</span> <span class="org-org-property-value">:engine postgresql</span>
<span class="org-org-special-keyword">:header-args:sql+:</span> <span class="org-org-property-value">:dbhost (mes/auth-get-key "db.svc" :dbhost)</span>
<span class="org-org-special-keyword">:header-args:sql+:</span> <span class="org-org-property-value">:dbport (string-to-number (mes/auth-get-key "db.svc" :port))</span>
<span class="org-org-special-keyword">:header-args:sql+:</span> <span class="org-org-property-value">:dbuser (mes/auth-get-key "db.svc" :user)</span>
<span class="org-org-special-keyword">:header-args:sql+:</span> <span class="org-org-property-value">:dbpassword (mes/auth-get-pwd "db.svc")</span>
<span class="org-org-special-keyword">:header-args:sql+:</span> <span class="org-org-property-value">:database (mes/auth-get-key "db.svc" :dbname)</span>
<span class="org-org-drawer">:END:</span>
</pre>
</div>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-emacs.html">emacs</a> <a href="https://magnus.therning.org/tag-org-mode.html">org-mode</a> </div>
]]></description>
<category><![CDATA[emacs]]></category>
<category><![CDATA[org-mode]]></category>
<link>https://magnus.therning.org/2024-09-01-improving-how-i-handle-secrets-in-my-work-notes.html</link>
<guid>https://magnus.therning.org/2024-09-01-improving-how-i-handle-secrets-in-my-work-notes.html</guid>
<pubDate>Sun, 01 Sep 2024 15:03:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Removing symlink question]]></title>
<description><![CDATA[
<p>
I'm not sure why, but all of a sudden I started getting this question every time
emacs starts
</p>
<blockquote>
<p>
Symbolic link to Git-controlled source file; follow link?
</p>
</blockquote>
<p>
After some searching I found out that it's <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Version-Control.html">VC</a> asking. I'm guessing this comes
from <a href="https://github.com/radian-software/straight.el">straight</a>'s very liberal use of symlinks. Though I'm still a little
surprised at VC kicking in when reading the config.
</p>
<p>
Anyway, there are two variables to consider, <code>vc-follow-symlinks</code> and
<code>vc-handled-backends</code>. I opted to modify the latter one, and since I don't use
VC at all I'm turning it off completely.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">setopt</span> vc-handled-backends nil<span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-emacs.html">emacs</a> </div>
]]></description>
<category><![CDATA[emacs]]></category>
<link>https://magnus.therning.org/2024-08-11-removing-symlink-question.html</link>
<guid>https://magnus.therning.org/2024-08-11-removing-symlink-question.html</guid>
<pubDate>Sun, 11 Aug 2024 08:41:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Emacs via Nix with mu4e]]></title>
<description><![CDATA[
<p>
I've been running development versions of Emacs ever since I switched to Wayland
and needed the PGTK code. The various <code>X-git</code> packages on <a href="https://aur.archlinux.org/">AUR</a> makes that easy,
as long as one doesn't mind building the packages locally, and regularly.
Building a large package like Emacs does get a bit tiring after a while though
so I started looking at the <a href="https://github.com/nix-community/emacs-overlay">emacs overlay</a> to see if I could keep up without
building quite that much.
</p>
<p>
The first attempt at this failed as I couldn't get my email setup working; emacs
simply refused to find the locally installed <code>mu4e</code> package. I felt I didn't
have time to solve it at the time, reverted back to doing the builds myself
again. It kept irritating me though, and today I made another attempt. This time
I invested a bit more time in reading up on how to install emacs via Nix with
packages. Something that paid off.
</p>
<p>
I'm managing my packages using <a href="https://nix.dev/manual/nix/2.23/command-ref/new-cli/nix3-profile.html">nix profile</a> and a <code>flake.nix</code>. To install emacs
with a working <code>mu4e</code> I started with adding the emacs overlay to the inputs
</p>
<div class="org-src-container">
<pre class="src src-nix"><span class="org-nix-attribute">inputs</span> = <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-nix-attribute">nixpkgs.url</span> = <span class="org-string">"github:nixos/nixpkgs?ref=nixpkgs-unstable"</span>;
...
<span class="org-nix-attribute">community-emacs.url</span> = <span class="org-string">"github:nix-community/emacs-overlay"</span>;
<span class="org-rainbow-delimiters-depth-1">}</span>;
</pre>
</div>
<p>
and in my outputs I made sure to use the overlay on <code>nixpkgs</code>
</p>
<div class="org-src-container">
<pre class="src src-nix"><span class="org-nix-attribute">outputs</span> = inputs@<span class="org-rainbow-delimiters-depth-1">{</span> nixpkgs, community-emacs, ... <span class="org-rainbow-delimiters-depth-1">}</span>:
<span class="org-nix-keyword">let</span>
<span class="org-nix-attribute">system</span> = <span class="org-string">"x86_64-linux"</span>;
<span class="org-nix-attribute">pkgs</span> = <span class="org-nix-builtin">import</span> nixpkgs <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-nix-keyword">inherit</span> system;
<span class="org-nix-attribute">overlays</span> = <span class="org-rainbow-delimiters-depth-2">[</span> community-emacs.overlays.emacs <span class="org-rainbow-delimiters-depth-2">]</span>;
<span class="org-rainbow-delimiters-depth-1">}</span>;
...
</pre>
</div>
<p>
and in the list of packages passed to <code>pkgs.buildEnv</code> I added
</p>
<div class="org-src-container">
<pre class="src src-nix">...
<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-rainbow-delimiters-depth-2">(</span>emacsPackagesFor emacs-pgtk<span class="org-rainbow-delimiters-depth-2">)</span>.emacsWithPackages
<span class="org-rainbow-delimiters-depth-2">(</span>epkgs: <span class="org-rainbow-delimiters-depth-3">[</span> epkgs.mu4e <span class="org-rainbow-delimiters-depth-3">]</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
mu
...
</pre>
</div>
<p>
That's all there's to it. After running <code>nix profile update 0</code> I had a build of
emacs with Wayland support that's less than a day old, all downloaded from the
community cache. Perfect!
</p>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-emacs.html">emacs</a> <a href="https://magnus.therning.org/tag-nix.html">nix</a> </div>
]]></description>
<category><![CDATA[emacs]]></category>
<category><![CDATA[nix]]></category>
<link>https://magnus.therning.org/2024-07-21-emacs-via-nix-with-mu4e.html</link>
<guid>https://magnus.therning.org/2024-07-21-emacs-via-nix-with-mu4e.html</guid>
<pubDate>Sun, 21 Jul 2024 01:04:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Hoogle setup for local development]]></title>
<description><![CDATA[
<p>
About a week ago I asked a <a href="https://discourse.nixos.org/t/haskell-shell-setup-with-working-hoogle-developpackage/48507/2">question on the Nix Discourse</a> about how to create a
setup for Hoogle that
</p>
<ul class="org-ul">
<li>includes the locally installed packages, and</li>
<li>the package I'm working on, and ideally also</li>
<li>have all local links, i.e. no links to <a href="https://hackage.haskell.org/">Hackage</a>.</li>
</ul>
<p>
I didn't get an answer there, but some people on the Nix Haskell channel on
Matrix helped a bit, but it seems this particular use case requires a bit of
manual work. The following commands get me an almost fully working setup:
</p>
<div class="org-src-container">
<pre class="src src-shell">cabal haddock --haddock-internal --haddock-quickjump --haddock-hoogle --haddock-html
<span class="org-variable-name">hoogle_dir</span>=$<span class="org-rainbow-delimiters-depth-1">(</span>dirname $<span class="org-rainbow-delimiters-depth-2">(</span>dirname $<span class="org-rainbow-delimiters-depth-3">(</span>readlink -f $<span class="org-rainbow-delimiters-depth-4">(</span><span class="org-builtin">which</span> hoogle<span class="org-rainbow-delimiters-depth-4">)</span><span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
hoogle generate --database=local.hoo <span class="org-sh-escaped-newline">\</span>
$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">for</span> d<span class="org-keyword"> in</span> $<span class="org-rainbow-delimiters-depth-2">(</span>fd -L .txt $<span class="org-rainbow-delimiters-depth-3">{</span><span class="org-variable-name">hoogle_dir</span><span class="org-rainbow-delimiters-depth-3">}</span><span class="org-rainbow-delimiters-depth-2">)</span>; <span class="org-keyword">do</span> printf <span class="org-string">"--local=%s "</span> $<span class="org-rainbow-delimiters-depth-2">(</span>dirname $<span class="org-variable-name">d</span><span class="org-rainbow-delimiters-depth-2">)</span>; <span class="org-keyword">done</span><span class="org-rainbow-delimiters-depth-1">)</span> <span class="org-sh-escaped-newline">\</span>
--local=./dist-newstyle/build/x86_64-linux/ghc-9.8.2/pkg-0.0.1/doc/html/pkg
hoogle server --local --database=local.foo
</pre>
</div>
<p>
What's missing is working links between the documentation of locally installed
packages. It looks like the links in the generated documention in Nix have a lot
of relative references containing <code>${pkgroot}/../../../../</code> which is what I
supect causes the broken links.
</p>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-haskell.html">haskell</a> <a href="https://magnus.therning.org/tag-nix.html">nix</a> </div>
]]></description>
<category><![CDATA[haskell]]></category>
<category><![CDATA[nix]]></category>
<link>https://magnus.therning.org/2024-07-13-hoogle-setup-for-local-development.html</link>
<guid>https://magnus.therning.org/2024-07-13-hoogle-setup-for-local-development.html</guid>
<pubDate>Sat, 13 Jul 2024 19:18:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[A function for jumping to a project TODO file]]></title>
<description><![CDATA[
<p>
I've had <a href="https://melpa.org/#/org-projectile">org-projectile</a> in my config since the beginning, and while it's worked
nicely for me in my main config it gave me some grief when I played around with
<a href="https://github.com/progfolio/elpaca">elpaca</a> the other week.<sup><a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>
</p>
<p>
I tried to get the install instructions to work, but kept on getting errors when
loading my config. Given that I only use it for one thing, to open the file
<code>TODO.org</code> in the current project's root, I decided to just write a function for
doing that instead.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">defun</span> <span class="org-function-name">mep-projectile-open-todo</span> <span class="org-rainbow-delimiters-depth-2">()</span>
<span class="org-doc">"Open the project's todo file."</span>
<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-keyword">interactive</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-keyword">if-let*</span> <span class="org-rainbow-delimiters-depth-3">(</span><span class="org-rainbow-delimiters-depth-4">(</span>proj-dir <span class="org-rainbow-delimiters-depth-5">(</span>projectile-project-root<span class="org-rainbow-delimiters-depth-5">)</span><span class="org-rainbow-delimiters-depth-4">)</span>
<span class="org-rainbow-delimiters-depth-4">(</span>proj-todo-file <span class="org-rainbow-delimiters-depth-5">(</span>f-join proj-dir <span class="org-string">"</span><span class="org-string"><span class="org-hl-todo"><span class="custom">TODO</span></span></span><span class="org-string">.org"</span><span class="org-rainbow-delimiters-depth-5">)</span><span class="org-rainbow-delimiters-depth-4">)</span><span class="org-rainbow-delimiters-depth-3">)</span>
<span class="org-rainbow-delimiters-depth-3">(</span>org-open-file proj-todo-file<span class="org-rainbow-delimiters-depth-3">)</span>
<span class="org-rainbow-delimiters-depth-3">(</span>message <span class="org-string">"Not in a project"</span><span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<div id="footnotes">
<h2 class="footnotes">Footnotes: </h2>
<div id="text-footnotes">
<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
This was the second time I gave up on using it instead of <a href="https://github.com/radian-software/straight.el">straight</a>, but
that's another story.
</p></div></div>
</div>
</div><div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-emacs.html">emacs</a> <a href="https://magnus.therning.org/tag-org-mode.html">org-mode</a> </div>
]]></description>
<category><![CDATA[emacs]]></category>
<category><![CDATA[org-mode]]></category>
<link>https://magnus.therning.org/2024-07-13-a-function-for-jumping-to-a-project-todo-file.html</link>
<guid>https://magnus.therning.org/2024-07-13-a-function-for-jumping-to-a-project-todo-file.html</guid>
<pubDate>Sat, 13 Jul 2024 10:24:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Nix, cabal, and tests]]></title>
<description><![CDATA[
<p>
At work I decided to attempt to change the setup of one of our projects from using
</p>
<ul class="org-ul">
<li><a href="https://github.com/input-output-hk/haskell.nix">haskell.nix</a></li>
<li><a href="https://docs.haskellstack.org/en/stable/">stack</a></li>
<li><a href="https://hackage.haskell.org/package/hpack">hpack</a></li>
</ul>
<p>
to the triplet I tend to prefer
</p>
<ul class="org-ul">
<li><code>developPackage</code> from <a href="https://github.com/NixOS/nixpkgs/">nixpkgs</a></li>
<li><a href="https://www.haskell.org/cabal/index.html">cabal</a> (the tool)</li>
<li><a href="https://cabal.readthedocs.io/en/stable/">cabal</a> (the spec)</li>
</ul>
<p>
During this I ran into two small issues relating to tests.
</p>
<div id="outline-container-org442482b" class="outline-2">
<h2 id="org442482b"><code>hspec-discover</code> both is, and isn't, available in the shell</h2>
<div class="outline-text-2" id="text-org442482b">
<p>
I found mentions of this mentioned in an open <a href="https://github.com/haskell/cabal/issues/8434">cabal ticket</a> and someone even made
a <a href="https://github.com/kenranunderscore/hspec-discover-repro">git repo</a> to explore it. I posted <a href="https://discourse.nixos.org/t/hspec-discover-not-available-in-shell/45563">a question</a> on the Nix discorse.
</p>
<p>
Basically, when running <code>cabal test</code> in a dev shell, started with <code>nix develop</code>,
the tool <code>hspec-discover</code> wasn't found. At the same time the packages was
installed
</p>
<div class="org-src-container">
<pre class="src src-shell"><span class="org-rainbow-delimiters-depth-1">(</span>ins<span class="org-rainbow-delimiters-depth-1">)</span>$ ghc-pkg list | rg hspec
hspec-2.9.7
hspec-core-2.9.7
<span class="org-rainbow-delimiters-depth-1">(</span>hspec-discover-2.9.7<span class="org-rainbow-delimiters-depth-1">)</span>
hspec-expectations-0.8.2
</pre>
</div>
<p>
and it was on the <code>$PATH</code>
</p>
<div class="org-src-container">
<pre class="src src-shell"><span class="org-rainbow-delimiters-depth-1">(</span>ins<span class="org-rainbow-delimiters-depth-1">)</span>$ whereis hspec-discover
hspec-discover: /nix/store/vaq3gvak92whk5l169r06xrbkx6c0lqp-ghc-9.2.8-with-packages/bin/hspec-discover /nix/store/986bnyyhmi042kg4v6d918hli32lh9dw-hspec-discover-2.9.7/bin/hspec-discover
</pre>
</div>
<p>
The solution, as the user <a href="https://discourse.nixos.org/u/julm">julm</a> pointed out, is to simply do what <code>cabal</code> tells
you and run <code>cabal update</code> first.
</p>
</div>
</div>
<div id="outline-container-org20e6fe8" class="outline-2">
<h2 id="org20e6fe8">Dealing with tests that won't run during build</h2>
<div class="outline-text-2" id="text-org20e6fe8">
<p>
The project's tests were set up in such a way that standalone tests and
integration tests are mixed into the same test executable. As the integration
tests need the just built service to be running they can't be run during <code>nix
build</code>. However, the only way of preventing that, without making code changes,
is to pass an argument to the test executable, <code>--skip=<prefix></code>, and I believe
that's not possible when using <code>developPackage</code>. It's not a big deal though,
it's perfectly fine to run the tests separately using <code>nix develop . command
...</code>. However, it turns out <code>developPackage</code> and the underlying machinery is
smart enough to skip installing package required for testing when it's turned
off (using <code>dontCheck</code>). This is the case also when <code>returnShellEnv</code> is <code>true</code>.
</p>
<p>
Luckily it's not too difficult to deal with it. I already had a variable
<code>isDevShell</code> so I could simply reuse it and add the following expression to
<code>modifier</code>
</p>
<div class="org-src-container">
<pre class="src src-nix"><span class="org-rainbow-delimiters-depth-1">(</span><span class="org-nix-keyword">if</span> isDevShell <span class="org-nix-keyword">then</span> hl.doCheck <span class="org-nix-keyword">else</span> hl.dontCheck<span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
</div>
</div>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-cabal.html">cabal</a> <a href="https://magnus.therning.org/tag-haskell.html">haskell</a> <a href="https://magnus.therning.org/tag-nix.html">nix</a> </div>
]]></description>
<category><![CDATA[cabal]]></category>
<category><![CDATA[haskell]]></category>
<category><![CDATA[nix]]></category>
<link>https://magnus.therning.org/2024-05-19-nix,-cabal,-and-tests.html</link>
<guid>https://magnus.therning.org/2024-05-19-nix,-cabal,-and-tests.html</guid>
<pubDate>Sun, 19 May 2024 17:21:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Orderless completion in lsp-mode]]></title>
<description><![CDATA[
<p>
If you, like me, are using <a href="https://github.com/minad/corfu"><i>corfu</i></a> to get in-buffer completion and extend it
with <a href="https://github.com/oantolin/orderless"><i>orderless</i></a> to make it even more powerful, you might have noticed that you
lose the orderless style as soon as you enter <a href="https://emacs-lsp.github.io/lsp-mode/"><i>lsp-mode</i></a>.
</p>
<p>
My setup of <i>orderless</i> looks like this
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">use-package</span> <span class="org-constant">orderless</span>
<span class="org-builtin">:custom</span>
<span class="org-rainbow-delimiters-depth-2">(</span>orderless-matching-styles '<span class="org-rainbow-delimiters-depth-3">(</span>orderless-literal orderless-regexp orderless-flex<span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-rainbow-delimiters-depth-2">(</span>completion-styles '<span class="org-rainbow-delimiters-depth-3">(</span>orderless partial-completion basic<span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-rainbow-delimiters-depth-2">(</span>completion-category-defaults nil<span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-rainbow-delimiters-depth-2">(</span>completion-category-overrides '<span class="org-rainbow-delimiters-depth-3">(</span><span class="org-rainbow-delimiters-depth-4">(</span>file <span class="org-rainbow-delimiters-depth-5">(</span>styles partial-completion<span class="org-rainbow-delimiters-depth-5">)</span><span class="org-rainbow-delimiters-depth-4">)</span><span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<p>
which basically turns on orderless style for all things except when completing
filenames.
</p>
<p>
It turns out that <i>lsp-mode</i> messes around with <code>completion-category-defaults</code>
and when entering <code>lsp-mode</code> <a href="https://github.com/emacs-lsp/lsp-mode/blob/b27d9db1e75d40ea5e1362386e9a6e66fa3b1bae/lsp-completion.el#L790">this code here</a> adds a setting for <code>'lsp-capf</code>.
Unfortunately there seems to be no way to prevent <i>lsp-mode</i> from doing this so
the only option is to fix it up afterwards. Luckily there's a hook for running
code after the completion for <i>lsp-mode</i> is set up, <code>lsp-completion-mode-hook</code>.
Adding the following function to it makes sure I now get to enjoy <i>orderless</i>
also when writing code.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span class="org-rainbow-delimiters-depth-1">(</span><span class="org-keyword">lambda</span> <span class="org-rainbow-delimiters-depth-2">()</span>
<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-keyword">setq-local</span> completion-category-defaults
<span class="org-rainbow-delimiters-depth-3">(</span>assoc-delete-all 'lsp-capf completion-category-defaults<span class="org-rainbow-delimiters-depth-3">)</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>
</pre>
</div>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-emacs.html">emacs</a> <a href="https://magnus.therning.org/tag-lsp.html">lsp</a> </div>
]]></description>
<category><![CDATA[emacs]]></category>
<category><![CDATA[lsp]]></category>
<link>https://magnus.therning.org/2024-05-04-orderless-completion-in-lsp-mode.html</link>
<guid>https://magnus.therning.org/2024-05-04-orderless-completion-in-lsp-mode.html</guid>
<pubDate>Sat, 04 May 2024 06:49:00 +0200</pubDate>
</item>
<item>
<title><![CDATA[Update to Hackage revisions in Nix]]></title>
<description><![CDATA[
<p>
A few days after I published <a href="https://magnus.therning.org/2024-03-14-hackage-revisions-in-nix.html">Hackage revisions in Nix</a> I got a comment from
Wolfgang W that the next release of Nix will have a <code>callHackageDirect</code> with
support for specifying revisions.
</p>
<p>
The code in <a href="https://github.com/NixOS/nixpkgs/pull/284490">PR #284490</a> makes <code>callHackageDirect</code> accept a <code>rev</code> argument. Like
this:
</p>
<div class="org-src-container">
<pre class="src src-nix">haskellPackages.callHackageDirect <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-nix-attribute">pkg</span> = <span class="org-string">"openapi3"</span>;
<span class="org-nix-attribute">ver</span> = <span class="org-string">"3.2.3"</span>;
<span class="org-nix-attribute">sha256</span> = <span class="org-string">"sha256-0F16o3oqOB5ri6KBdPFEFHB4dv1z+Pw6E5f1rwkqwi8="</span>;
<span class="org-nix-attribute">rev</span> = <span class="org-rainbow-delimiters-depth-2">{</span>
<span class="org-nix-attribute">revision</span> = <span class="org-string">"4"</span>;
<span class="org-nix-attribute">sha256</span> = <span class="org-string">"sha256-a5C58iYrL7eAEHCzinICiJpbNTGwiOFFAYik28et7fI="</span>;
<span class="org-rainbow-delimiters-depth-2">}</span>;
<span class="org-rainbow-delimiters-depth-1">}</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
<p>
That's a lot better than using <code>overrideCabal</code>!
</p>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-haskell.html">haskell</a> <a href="https://magnus.therning.org/tag-nix.html">nix</a> </div>
]]></description>
<category><![CDATA[haskell]]></category>
<category><![CDATA[nix]]></category>
<link>https://magnus.therning.org/2024-04-20-update-to-hackage-revisions-in-nix.html</link>
<guid>https://magnus.therning.org/2024-04-20-update-to-hackage-revisions-in-nix.html</guid>
<pubDate>Sat, 20 Apr 2024 11:04:00 +0200</pubDate>
</item>
</channel>
</rss>