summaryrefslogtreecommitdiff
path: root/workstation.lisp
blob: 861ecaf2cd41de1632639c47bad35dc509378e3c (plain)
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
(in-package :com.silentflame.consfig)
(in-consfig "com.silentflame.consfig")
(named-readtables:in-readtable :consfigurator)

(defparameter *desktop-packages*
  '("sway"
    "swayidle"
    "swaylock"
    "i3status"
    "libjson-perl"                      ; for i3status-wrapper
    "gammastep"
    "foot"
    "wofi"
    "wtype"
    "brightnessctl"
    "mako-notifier"
    "libnotify-bin"                     ; for notify-send(1)
    "xwayland"
    "qtwayland5"
    "qml-module-qtwayland-client-texturesharing"
    "qt5ct"
    "inotify-tools"                     ; scripts/desktop/emacsclient
    "wdisplays"

    "fcitx5"
    "fcitx5-config-qt"
    "fcitx5-frontend-gtk2"
    "fcitx5-frontend-gtk3"
    "fcitx5-frontend-qt5"
    "fcitx5-hangul"
    "fcitx5-mozc"

    "task-british-desktop"
    "gtk3-nocsd"
    "fonts-hack"
    "fonts-baekmuk"                     ; Korean
    "fonts-vlgothic"                    ; Japanese
    "fonts-takao"                       ; Japanese
    "fonts-noto-cjk"                    ; Chinese characters
    "eog"
    "imagemagick"
    "thunar"
    "tumbler"                           ; thunar thumbnails
    "tumbler-plugins-extra"             ; thunar thumbnails
    "ffmpegthumbnailer"                 ; thunar thumbnails
    "libfile-libmagic-perl"             ; resizing wallpapers

    "pulseaudio"
    "alsa-utils"
    "elpa-bongo"
    "elpa-volume"

    "elpa-nov"
    "elpa-redtick"

    "webext-ublock-origin-firefox")
  "Packages for machines where I run a graphical desktop environment/compositor.")

(defparameter *emacs-packages*
  '("emacs"
    "emacs-common-non-dfsg"

    "elpa-paredit"
    "elpa-ws-butler"
    "elpa-diminish"

    "slime"
    ;; "cl-consfigurator"                  ; for consfigurator.el
                                           ; Commented out until bookworm.

    "elpa-magit"
    "elpa-git-annex"
    "elpa-magit-annex"
    "elpa-markdown-mode"
    "elpa-message-templ"

    "texinfo"                           ; texi2dvi(1) used by elpa-org
    "elpa-org"
    "elpa-org-contrib"
    "elpa-orgalist"
    "elpa-howm"

    "elpa-ggtags"
    "elpa-debian-el"
    "elpa-dpkg-dev-el"
    "elpa-rainbow-mode"))

(defparameter *workstation-packages*
  (list*
   "sbcl"
   "sbcl-source"
   "cl-consfigurator"

   "htop"
   "git-annex"
   "git-email"
   "gitk"
   "rtorrent"
   "ncdu"
   "avahi-daemon"
   "netcat"
   "mercurial"
   "cvs"
   "subversion"
   "easytag"
   "zip"
   "unzip"
   "unrar"
   "flac"
   "lame"
   "gv"
   "pdftk"
   "mosh"
   "symlinks"
   "vlc"
   "python3-boto"
   "sshuttle"
   "pandoc"
   "pandoc-citeproc"
   "pandoc-citeproc-preamble"
   "latexmk"
   "dos2unix"
   "sshfs"
   "p7zip-full"
   "apt-utils"
   "openconnect"                        ; UA VPN
   "duply"
   "duplicity"
   "ocrmypdf"
   "img2pdf"
   "evince"
   "libreoffice"
   "sm"

   "isync"
   "mutt"
   "t-prot"
   "w3m"                                ; for mutt
   "mb2md"
   "notmuch"
   "libmail-box-perl"
   "rename"
   "evolution"
   "colorized-logs"                     ; for ansi2txt
   "mailscripts"
   "elpa-mailscripts"
   "tnef"                               ; opening winmail.dat attachments

   "yapet"
   "scdaemon"
   "ssh-askpass"
   "pinentry-gnome3"

   "libpath-class-perl"                 ; ~/src/propellor post-checkout hook
   "liblist-compare-perl"
   "libdata-compare-perl"

   ;; for ifuse-photos-to-tmp
   "libimage-exiftool-perl"
   "libdatetime-format-epoch-perl"
   "libdatetime-perl"
   "libsyntax-keyword-try-perl"

   "chiark-scripts"                     ; for git-branchmove(1)

   "libu2f-host-dev"                    ; to ensure we get latest shlib
   "yubikey-personalization-gui"
   "yubikey-manager"

   "perltidy"
   "perlindex"
   "libdist-zilla-perl"
   "libdist-zilla-plugin-git-perl"
   "libdist-zilla-plugin-podweaver-perl"
   "libcpan-uploader-perl"
   "libconfig-identity-perl"
   "libpod-coverage-trustpod-perl"
   "libtest-pod-coverage-perl")
  "Packages I want installed on workstations.
Mainly covers non-devel activities.  Not everything I use needs to go here: just
things I use often enough that having to install them is an annoyance.")

(defprop %no-lightdm :posix ()
  (:apply
   (when (apt:all-installed-p "lightdm")
     (systemd:disabled "lightdm"))
   :no-change))

(defproplist tty1-autologin :posix ()
  (%no-lightdm)
  (file:directory-exists "/etc/systemd/system/getty@tty1.service.d")
  (file:has-content
      "/etc/systemd/system/getty@tty1.service.d/override.conf"
    '("[Service]"
      "ExecStart="
      "ExecStart=-/usr/sbin/agetty --autologin spwhitton --noclear %I $TERM")))

(defproplist startsway-available :posix ()
  (apt:removed "redshift" "redshift-gtk")
  (file:has-content "/usr/local/bin/startsway"
#>EOF>#!/bin/sh

. $HOME/.shenv

export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

export QT_QPA_PLATFORM=wayland
export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
export CLUTTER_BACKEND=wayland
export SDL_VIDEODRIVER=wayland
export MOZ_ENABLE_WAYLAND=1
export MOZ_WEBRENDER=1
export _JAVA_AWT_WM_NONREPARENTING=1
export XDG_SESSION_TYPE=wayland
export XDG_CURRENT_DESKTOP=sway

[ -f "$HOME/.swayerr" ] && mv "$HOME/.swayerr" "$HOME/.swayerr.old"
exec "$SHELL" -lc 'sway 2>"$HOME/.swayerr"'
EOF :mode #o755))

(defproplist tty1-execs-sway :posix ()
  "Set up login(1) to call a wrapper which execs sway when logging in on tty1.

The more common way to do this is to add roughly the contents of the fakeshell
script, below, to the end of /etc/profile (additionally we'd probably check that
DISPLAY is not already set).  But then for robustness we will want to set the
whole contents of /etc/profile here, which means that other properties can't
modify that file.  So use a mechanism more tightly coupled to the vttys, in
particular, as that is what we actually want to affect here.

(/etc/profile.d is not a good option for a snippet which execs another program,
as that has the potential to cause other entries in /etc/profile.d to be ignored
if it gets executed too early; unlike other .d dirs, the files in /etc/profile.d
do not have names beginning with numbers, and hacks like zzz_ are not nice.)"
  (:desc "tty1 execs Sway")
  (tty1-autologin)
  (startsway-available)
  (file:contains-conf-space "/etc/login.defs"
                            "FAKE_SHELL" "/usr/local/bin/fakeshell")
  (file:has-content "/usr/local/bin/fakeshell"
#>EOF>#!/bin/bash

if [ "$(logname)" = "spwhitton" ] && [ "$(tty)" = "/dev/tty1" ]; then
    exec /usr/local/bin/startsway
else
    exec -l "$SHELL"
fi
EOF :mode #o755))

(defproplist has-sway-config :posix
    (name contents
          &aux (file (strcat ".config/sway/" (get-short-hostname) "/" name)))
  (file:containing-directory-exists file)
  (file:has-content file contents))

;; Under X, to test modifications to this without rebooting, should be able to:
;;     % setxkbmap us+spw(emacs)
(defproplist xkb-variants-available :posix ()
  (file:has-content "/usr/share/X11/xkb/symbols/spw"
#>EOF>partial modifier_keys
xkb_symbols "emacs" {
    // alt/meta are left and right win and menu
    replace key <LWIN> { [ Alt_L, Meta_L ] };
    replace key <MENU> { [ Alt_R, Meta_R ] };
    replace key <RWIN> { [ Alt_R, Meta_R ] };
    modifier_map Mod1  { <LWIN>, <RWIN>, <MENU> };

    // ctrl is left and right alt/altgr
    replace key <LALT>   { [ Control_L, Control_L ] };
    replace key <RALT>   { type[Group1] = "TWO_LEVEL",
                           symbols[Group1] = [ Control_R, Control_R ] };
    replace key <ALGR>   { type[Group1] = "TWO_LEVEL",
                           symbols[Group1] = [ Control_R, Control_R ] };
    modifier_map Control { <LALT>, <RALT>, <ALGR> };

    // caps lock is (left) super
    replace key <CAPS> { [ Super_L ] };
    modifier_map Mod4 { <CAPS> };

    // left control is caps lock
    replace key <LCTL> { [ Caps_Lock ] };
    modifier_map Lock { <LCTL> };

    // Shift+RCtrl and release (taking care to hit shift first) is compose key
    // RCtrl+something accesses third level
    // RCtrl+Shift+something (taking care to hit RCtrl first) accesses 4th level
    // (this is the only part that is GNU/Linux-specific; everything above is
    // implementable using the Windows Registry or the macOS user preferences)
    replace key <RCTL> {
      type[Group1]="TWO_LEVEL",
      symbols[Group1] = [ ISO_Level3_Shift, Multi_key ]
    };
    include "level3(modifier_mapping)"
};

// for keyboards with only two keys immediately to the right of the spacebar;
// in this case there is no compose key available
xkb_symbols "emacs_2rhs" {
    // alt/meta are left win and and right ctrl
    replace key <LWIN> { [ Alt_L, Meta_L ] };
    replace key <RCTL> { [ Alt_R, Meta_R ] };
    modifier_map Mod1  { <LWIN>, <RCTL> };

    // ctrl is left and right alt/altgr
    replace key <LALT>   { [ Control_L, Control_L ] };
    replace key <RALT>   { type[Group1] = "TWO_LEVEL",
                           symbols[Group1] = [ Control_R, Control_R ] };
    replace key <ALGR>   { type[Group1] = "TWO_LEVEL",
                           symbols[Group1] = [ Control_R, Control_R ] };
    modifier_map Control { <LALT>, <RALT>, <ALGR> };

    // caps lock is (left) super
    replace key <CAPS> { [ Super_L ] };
    modifier_map Mod4 { <CAPS> };

    // left control is caps lock
    replace key <LCTL> { [ Caps_Lock ] };
    modifier_map Lock { <LCTL> };
};

// melete's version; see docstring of MELETE-XKB-SETUP Consfigurator property
xkb_symbols "emacs_melete" {
    replace key <LWIN> { [ Alt_L, Meta_L ] };
    replace key <MENU> { [ Alt_R, Meta_R ] };
    replace key <RWIN> { [ Alt_R, Meta_R ] };
    replace key <RCTL> { [ Alt_R, Meta_R ] };
    modifier_map Mod1  { <LWIN>, <MENU>, <RWIN>, <RCTL> };

    replace key <LALT>   { [ Control_L, Control_L ] };
    replace key <RALT>   { [ Control_R, Control_R ] };
    modifier_map Control { <LALT>, <RALT> };

    // caps lock is (left) super
    replace key <CAPS> { [ Super_L ] };
    modifier_map Mod4 { <CAPS> };

    // left control is caps lock
    replace key <LCTL> { [ Caps_Lock ] };
    modifier_map Lock { <LCTL> };
};
EOF))

(defproplist xkb-variant-selected :posix
    (layout &optional (variant "emacs")
            &aux (layout* (format nil "~A+spw(~A)" layout variant)))
  (:hostattrs (os:required 'os:debianlike))
  (xkb-variants-available)
  (apt:installed "keyboard-configuration" "initramfs-tools")
  (on-change (etc-default:contains
              "keyboard" "XKBMODEL" "pc105" "XKBLAYOUT" layout*)
    (cmd:single "update-initramfs" "-u"))
  (as (spwhitton)
    ;; work around Debian bug #989707
    (has-sway-config "layout"
                     `("input type:keyboard xkb_model \"pc105\""
                       ,#?'input type:keyboard xkb_layout "${layout*}"'))))

(defproplist melete-xkb-setup :posix ()
  "The PrtSc to the right of the right Alt key on this machine is strange: if the
right Alt key and PrtSc are held together then the kernel cannot register
presses of the 'b' and 'n' keys.  And while holding PrtSc and after a moment
also holding right Alt sends both keys, holding the Alt first and then holding
PrtSc sends a different scancode, 0x54, altogether.

With my usual rebindings, the upshot is that using C-M- for letters on the left
hand of QWERTY is either unreliable or doesn't work at all.  In particular,
C-M-b; C-M-n is pressed with the left hand holding down keys to the left of the
spacebar.

If the firmware gets fixed so presses of 'b' get registered when both right Alt
and PrtSc are held down, it might be worth figuring out turning scancode 0x54
into a key which activates both the Ctrl and Mod1 modifiers, and then I could
type as normal.

In the meantime, rather than having to use two different pairs of keys for
C-M-b and C-M-d, I'll train myself to use (physical) right Alt and
(physical) right Ctrl to send C-M- for all letters on the left side of the
keyboard, and otherwise type normally.  (An alternative would be to try using
PrtSc and right Ctrl for C-M-)

This is a modified (xkb-variant-selected \"us\") to achieve that: it just sets
up the physical right Ctrl key as an additional meta key, and makes the key on
its own send Menu rather than SysRq to avoid interacting with kernel magic
SysRq."
  (:desc "melete's Xkb setup")
  (:hostattrs (os:required 'os:debianlike))
  (file:has-content "/etc/udev/hwdb.d/90-spw-thinkpad.hwdb"
    ;; Source: https://blog.zhanghai.me/remapping-keys-with-udev-hwdb/
    '("evdev:atkbd:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*:pvrThinkPad*"
      ;; Send Menu not the SysRq key when PrSc is pressed on its own.
      " KEYBOARD_KEY_b7=compose"
      ;; Since we're not going to use it until the firmware bug is fixed, just
      ;; turn off the single scancode we get for pressing both keys.  If want to
      ;; try to make this to a key which does two modifiers, probably want to
      ;; use 'prog4' here as I think using one of the 'progN' codes is right
      ;; here because I think those are intended as user programmable so we
      ;; shouldn't ever end up with an app that wants to bind it
      " KEYBOARD_KEY_54=reserved"))
  (xkb-variant-selected "us" "emacs_melete"))

(defproplist buildd-source :posix (suite)
  (apt:additional-sources #?"buildd-${suite}"
     (list
      #?"deb http://incoming.debian.org/debian-buildd/ buildd-${suite} main contrib")))

(defprop libvirt-group-if-virt-manager :posix ()
  (:desc "Sean in libvirt group if virt-manager installed")
  (:apply
   (if (apt:all-installed-p "virt-manager")
       (user:has-groups (spwhitton) "libvirt")
       :no-change)))

(defproplist firefox-preferences :posix ()
  (:desc "Some Firefox preferences locked")
  (file:directory-exists #P"/etc/firefox/")
  (file:directory-exists #P"/etc/firefox-esr/")
  (file:exists-with-content "/etc/firefox/all-spw.js"
    '("pref(\"browser.urlbar.formatting.enabled\", false, locked);"
      "pref(\"browser.urlbar.trimURLs\", false, locked);"
      "pref(\"browser.newtabpage.enabled\", false, locked);"
      "pref(\"browser.tabs.onTop\", false, locked);"
      "pref(\"media.mediasource.enabled\", true, locked);"
      "pref(\"browser.tabs.closeWindowWithLastTab\", true, locked);"
      "pref(\"places.frecency.unvisitedBookmarkBonus\", 1000, locked);"
      "pref(\"places.frecency.bookmarkVisitBonus\", 1000, locked);"
      "pref(\"keyword.enabled\", false, locked);"
      "pref(\"geo.enabled\", false, locked);"
      "pref(\"extensions.pocket.enabled\", false, locked);"
      "pref(\"network.trr.mode\", 5, locked);"))
  (file:symlinked :from "/etc/firefox-esr/all-spw.js"
                  :to "/etc/firefox/all-spw.js"))

(defproplist login-sessions-host :posix ()
  "Basic setup for MACHINE/CONTAINERs where I log in and run at least Emacs."
  (basic-spwhitton)
  (stdsudo (spwhitton))

  (os:etypecase
    (debian-stable
     (apt:suites-available-pinned '(os:debian-unstable) -10
                                  '(os:debian-experimental) -10)
     (unapplied (apt:suites-available-pinned (get-hostattrs-car :os) 900))
     (proposed-updates)
     (demeter-apt :include-unstable t :include-experimental t)

     ;; permit installation of lib*-perl from sid if no version available from
     ;; another suite and not already installed
     (apt:pinned '("lib*-perl") '(os:debian-unstable) 50)

     (for-bullseye
      (apt:pinned '("elpa-magit" "elpa-magit-section" "elpa-transient"
                    "elpa-dash" "elpa-git-commit" "elpa-with-editor"
                    "elpa-bongo" "elpa-org" "elpa-org-contrib" "howm")
                  '(os:debian-unstable) 900))
     ;; For simplicity, just add to all LOGIN-SESSIONS-HOST hosts, though maybe
     ;; a pin would be better.  elpa-notmuch is solely for notmuch-address.el.
     (for-bullseye (apt:backports-installed "notmuch" "elpa-notmuch")))
    (debian-testing
     (apt:suites-available-pinned '(os:debian-testing) 900
                                  '(os:debian-unstable) 50
                                  '(os:debian-experimental) 1)
     (demeter-apt))
    (debian-unstable
     (apt:suites-available-pinned '(os:debian-unstable) 900
                                  '(os:debian-experimental) 1)
     (demeter-apt)))

  (apt:installed *emacs-packages*
                 "mailscripts" "elpa-mailscripts"

                 ;; for locmaint, git-push-all etc.
                 "aptitude"
                 "libarray-iterator-perl"
                 "libarray-utils-perl"
                 "libcapture-tiny-perl"
                 "libconfig-gitlike-perl"
                 "libconfig-gitlike-perl"
                 "libdate-manip-perl"
                 "libdpkg-perl"
                 "libfile-chdir-perl"
                 "libfile-grep-perl"
                 "libfile-slurp-perl"
                 "libfile-which-perl"
                 "libgit-annex-perl"
                 "libgit-wrapper-perl"
                 "liblist-moreutils-perl"
                 "libmail-box-perl"
                 "libnet-github-perl"
                 "libswitch-perl"
                 "libterm-ui-perl"))

(defproplist desktop :posix ()
  (:desc "Standard graphical desktop")
  (machine) (login-sessions-host)
  (desc "apt installed graphical desktop packages"
        (apt:installed *desktop-packages*))
  (file:has-content "/etc/apparmor.d/local/fr.emersion.Mako"
    "owner @{HOME}/src/dotfiles/.config/mako/config r,"))

(defproplist workstation :posix ()
  "Standard Debian setup for workstations.
Replaces MACHINE on my laptops and desktops."
  (:desc "Standard workstation")
  (desktop)
  (fstab:has-entries "tmpfs /tmp tmpfs defaults,nodev,nosuid 0 2")

  ;; Create the flag file for OS:CLEANLY-INSTALLED-ONCE to prevent any
  ;; accidents, and because workstations are indeed always cleanly installed, if
  ;; not by that property.
  (file:directory-exists "/etc/consfigurator")
  (file:exists-with-content "/etc/consfigurator/os-cleanly-installed" "")

  ;; Set /etc/mailname to the FQDN.  postconf(5) (under "myorigin" and
  ;; "myhostname") says this is appropriate for my personal machines whose
  ;; hostnames do not have publically advertised MX records.
  ;;
  ;; In at least the following two places I assume that </etc/mailname> contains
  ;; the FQDN on my personal machines:
  ;;  - I want Emacs to generate Message-Ids with the FQDN (though not
  ;;    completely clear I should)
  ;;  - 'SPW.Services.personalPostfix' assumes it when writing
  ;;    /etc/postfix/canonical (if /etc/mailname is silentflame.com, and
  ;;    sendmail is called without -f, will end up with mail From:
  ;;    spwhitton@silentflame.com which is never right and can cause mail to be
  ;;    filtered as spam)
  ;;
  ;; Also see: https://wiki.debian.org/EtcMailName
  ;;           https://propellor.branchable.com/forum/mailname_set_by_Propellor.Property.Hostname.sane/
  (hostname:mailname-configured)

  ;; Set up apt sources, pinning and some packages based on whether this
  ;; workstation is running stable, testing or unstable.
  (os:etypecase
    ;; Thanks to DEVELACC-PROVISIONED, workstations where I do work that can't
    ;; be held up by broken testing/sid can run Debian stable.
    (debian-stable
     ;; Clean up after switching from tracking testing to tracking a new stable
     ;; release.
     (unapplied (apt:pinned '("firefox") '(os:debian-unstable) 900))
     (apt:installed "firefox-esr")
     (apt:removed "firefox" "apt-listbugs")
     (desc "testing suite not available"
           (unapplied (apt:suites-available-pinned '(os:debian-testing) 900)))

     ;; Need demeter backports of these for sway-ftp-master.
     (for-bullseye (apt:backports-installed "foot" "libfcft3")))
    ;; Setup for Debian testing workstations is for upgrading to the next stable
    ;; release once we're frozen, but assumptions made by properties on
    ;; OS:DEBIAN-STABLE hosts are violated, such as the backports suite not
    ;; being available, or unattended-upgrades being likely to pull in large
    ;; changes.  Otherwise, best to avoid testing due to poorer security
    ;; support.  If have to use it, might want to consider pabs' application of
    ;; debsecan: https://bugs.debian.org/725934#20 plus symlink
    ;; /var/lib/debsecan/apt_preferences into /etc/apt/preferences.d.
    (debian-testing
     ;; Might possibly be useful to have testing-proposed-updates from
     ;; incoming.debian.org here.

     ;; Clean up after upgrading a workstation from stable to testing.
     (unapplied (apt:unattended-upgrades))
     (unapplied (proposed-updates))

     (apt:pinned '("firefox") '(os:debian-unstable) 900)
     (apt:installed "firefox" "apt-listbugs")
     (apt:removed "firefox-esr"))
    ;; Setup for sid workstations is for machines where I do work that is not
    ;; time-sensitive, i.e., it's okay for the work to be held up by broken
    ;; testing/sid.  Debian development is more convenient on such machines than
    ;; it is on stable machines using develacc.
    ;;
    ;; Note that might still want develacc on sid machines for isolating tools
    ;; like pip, stack and lein.
    (debian-unstable
     (buildd-source "unstable")
     (buildd-source "experimental")

     ;; Clean up after upgrading a workstation to unstable.
     (unapplied (apt:unattended-upgrades))
     (unapplied (apt:suites-available-pinned '(os:debian-testing) 900
                                             '(os:debian-stable "stretch") 900
                                             '(os:debian-stable "buster")  900))
     (unapplied (proposed-updates))

     (apt:pinned '("firefox") '(os:debian-unstable) 900)
     (apt:installed "firefox" "apt-listbugs")
     (apt:removed "firefox-esr")))

  ;; hardening
  (apt:service-installed-running "firewalld")
  (firewalld:has-default-zone "public")
  (firewalld:zone-has-service "public" "dhcpv6-client")
  (unapplied (firewalld:zone-has-service "public" "ssh"))
  (firewalld:zone-has-target "public" "DROP")

  ;; Always install the latest versions of Debian infrastructure and
  ;; documentation packages.
  (apt:pinned '("debian-keyring"
                "developers-reference"
                "debian-policy"
                "lintian"
                "doc-debian"
                "maint-guide"

                "dh-make-perl"
                "dh-make-elpa"
                "pkg-perl-tools")
              '(os:debian-unstable) 900)

  (desc "apt installed workstation packages"
        (apt:installed *workstation-packages*))

  (desc "texlive-*-doc pinned not to install"
        (file:exists-with-content "/etc/apt/preferences.d/10texlive-doc"
                                  '("Package: texlive-*-doc"
                                    "Pin: release"
                                    "Pin-Priority: -10")))
  (apt:installed "texlive"
                 "texlive-plain-generic"
                 "ttf-bitstream-vera"   ; sans-serif font in dissertation
                 "texlive-xetex")
  (apt:installed-minimally "texlive-latex-extra" ; for enumitem.sty
                           "texlive-fonts-extra" ; for newtxmath.sty
                           )
  ;; These doc packages are huge, causing very slow apt upgrades.
  (apt:removed "texlive-fonts-extra-doc"
	       "texlive-fonts-recommended-doc"
	       "texlive-latex-base-doc"
	       "texlive-latex-extra-doc"
	       "texlive-latex-recommended-doc"
	       "texlive-metapost-doc"
	       "texlive-pictures-doc"
	       "texlive-pstricks-doc")

  (libvirt-group-if-virt-manager)
  (user:has-desktop-groups (spwhitton))
  (firefox-preferences)

  ;; Limit my memory and CPU usage in the hope that if a process locks up the
  ;; graphical session we will be able to switch to another getty and kill it.
  (file:directory-exists "/etc/systemd/system/user-.slice.d")
  (file:exists-with-content "/etc/systemd/system/user-.slice.d/limits.conf"
    '("[Slice]"
      ;; See systemd.resource-control(5).
      "CPUWeight=90"
      "MemoryHigh=95%")))

(defparameter *debian-development-packages*
  '("piuparts"
    "autopkgtest"
    "git-buildpackage"
    "dgit"
    "dose-extra"                        ; for build-rdeps(1)
    "quilt"
    "devscripts"
    "apt-file"
    "libyaml-syck-perl"                 ; for grep-excuses(1)
    "equivs"                            ; for mk-build-deps(1)

    "pkg-haskell-tools"
    "libtext-patch-perl"                ; for package-plan
    "alex"
    "happy"
    "reprepro"

    "pkg-perl-tools"
    "dh-make-perl"))

(defpropspec debian-development-setup :lisp (&key additional-schroots)
  "Sean's setup for doing Debian packaging work.

Needed on all workstations where I do packaging work, whether or not we have
develacc VM."
  (:desc "Debian development setup in place")
  (let ((arch (os:debian-architecture (get-hostattrs-car :os))))
    `(eseqprops
      (apt:uses-local-cacher)
      (apt:installed ,*debian-development-packages*)
      (sbuild:usable-by ,(spwhitton))

      ;; Have to avoid the libjs-sphinx Recommends: entrys on stable systems, at
      ;; least for now.
      (apt:installed-minimally "debian-policy" "developers-reference")

      ;; config in ~ is for dput-ng; ensure /etc/dput.cf doesn't override
      (apt:installed "dput-ng")
      (apt:removed "dput")
      (file:does-not-exist "/etc/dput.cf")

      ;; Always build a schroot for sid.  Although a schroot for current Debian
      ;; stable is usually wanted, require that it be in ADDITIONAL-SCHROOTS,
      ;; because when there is a new stable some hosts will want to keep
      ;; oldstable's schroot and others won't, so we need to keep track of
      ;; exactly which stable schroots each host has.
      ,(propapp (periodic:at-most
                 :monthly "sbuild sid schroot rebuilt"
                 (unapplied (sbuild:built. nil (os:debian-unstable arch)))))
      ,@(loop for os in (cons `(os:debian-unstable ,arch) additional-schroots)
              for base-propspec = (make-propspec :propspec `(eseqprops ,os))
              for host = (preprocess-host (make-child-host :propspec base-propspec))
              for host-os = (get-hostattrs-car :os host)
              for type = (type-of host-os)
              for suite = (and (subtypep type 'os:debian)
                               (os:debian-suite host-os))
              and arch = (os:debian-architecture-string host-os)
              collect `(sbuild:built
                        nil ,(append-propspecs
                              base-propspec
                              (make-propspec
                               :propspec
                               `(eseqprops
                                 (apt:uses-parent-proxy)
                                 ,@(and (subtypep type 'os:debian)
                                        '((sbuild:standard-debian-schroot)))
                                 (apt:uses-parent-mirrors)
                                 ,@(and (subtypep type 'os:debian-unstable)
                                        '((buildd-source "unstable")))))))
              when (subtypep type 'os:debian-stable)
                collect `(file:contains-ini-settings
                          ,#?"/etc/schroot/chroot.d/${suite}-${arch}-sbuild-consfigurator"
                          (,#?"${suite}-${arch}-sbuild"
                           "aliases"
                           ,(if (string= arch (os:debian-architecture-string
                                               (get-hostattrs-car :os)))
                                #?"${suite}-backports,${suite}-backports-${arch}-sbuild"
                                #?"${suite}-backports-${arch}-sbuild")))))))

(defproplist workstation-nm-unmanaged :posix ()
  "Mark interfaces athenet and virbr* as unmanaged by Network Manager.

This is a separate property as on some hosts a more complex NetworkManager.conf
might be required."
  (:desc "Workstation NM unmanaged interfaces")
  (file:contains-ini-settings "/etc/NetworkManager/NetworkManager.conf"
                              '("main" "plugins" "ifupdown,keyfile")
                              '("keyfile" "unmanaged-devices"
                                "interface-name:athenet,interface-name:virbr*")))