Documentation improvements

docs: Add Wiki section for (legacy) configuration snippets in case
they are deleted from the main configuration
docs: Add more details on matrix handling
This commit is contained in:
Swarsel 2024-06-13 02:31:04 +02:00
parent d5a18a84d5
commit 1ddc3eb81d
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
4 changed files with 212 additions and 5 deletions

3
.github/README.md vendored
View file

@ -44,6 +44,7 @@ Sadly all things nix feel a bit underdocumented (even though it mostly is not).
- Also useful is the [NixOS wiki](https://nixos.wiki/wiki/Main_Page), but some pages are outdated, so use with some care
- When you are trying to setup a new configuration part, GitHub code search can really help you to find a working configuration.
- getting packages not maintained in a standard repository can be done in most cases easily with fetchFromGithub (https://ryantm.github.io/nixpkgs/builders/fetchers/)
- I have gathered some configuration snippets here: [Wiki.org](../Wiki.org). I will update this whenever I come across an interesting bit.
### Deployment
Below is a rough general guide to setup this system on a new NixOS host. **Again**, this is not recommended as this is a personal configuration. This also might not be the most efficient way to deploy a new Nix system, but it should work in the general case.
@ -51,7 +52,7 @@ Below is a rough general guide to setup this system on a new NixOS host. **Again
For a pure Home-Manager configuration, you need a few different steps. The biggest change is that you then want to call `home-manager --flake .#<your-username>@<your-hostname> switch` as the last step instead of `nixos-rebuild [...]`. A complete general guide for that case cannot really be given since you are most likely setting up the flake on a existing machine that already has a lot of configuration. If you are setting up a new system, I would recommend to use NixOS unless circumstances force you to use something else.
###### To do that:
1) adapt [Nix.org](../.dotfiles/Nix.org)
1) adapt [Nix.org](../Nix.org)
1) adapt system specific options:
- Make a copy of "System Specific Configurations/TEMPLATE".
- Adapt all references to TEMPLATE to your host- and usernames etc - pay special attention to the header lines in each nix source block, i.e. the "#+begin_src nix [...] :tangle profiles/TEMPLATE/[...]" lines.

50
Nix.org
View file

@ -1900,7 +1900,7 @@ In the long run, I am thinking about a transition to kubernetes or using just a
*** [Manual steps required] Calibre
This machine requires manual setup:
1) Set up calibre-web:
1) (obsolete for now) Set up calibre-web:
- Create metadata.db with 664 permissions, make sure parent directory is writeable
- Login @ books.swarsel.win using initial creds:
- user: admin
@ -3093,9 +3093,52 @@ Make sure to also do this for doublepuppet.yaml
#+end_src
*** Swatrix
*** [Manual steps required] Swatrix
**** NixOS
The files mentioned by
#+begin_src nix
settings.app_service_config_files = [
"/var/lib/matrix-synapse/telegram-registration.yaml"
"/var/lib/matrix-synapse/whatsapp-registration.yaml"
"/var/lib/matrix-synapse/signal-registration.yaml"
"/var/lib/matrix-synapse/doublepuppet.yaml"
]
#+end_src
need to be moved to the corresponding location. The below files are created as soon as the appservice is run once. This means that matrix will crash on the first startup; afterwards run these commands and restart the service.
#+begin_src shell
cp /var/lib/mautrix-telegram/telegram-registration.yaml /var/lib/matrix-synapse/
chown matrix-synapse:matrix-synapse /var/lib/matrix-synapse/telegram-registration.yaml
cp /var/lib/mautrix-signal/signal-registration.yaml /var/lib/matrix-synapse/
chown matrix-synapse:matrix-synapse /var/lib/matrix-synapse/signal-registration.yaml
cp /var/lib/mautrix-whatsapp/whatsapp-registration.yaml /var/lib/matrix-synapse/
chown matrix-synapse:matrix-synapse /var/lib/matrix-synapse/whatsapp-registration.yaml
#+end_src
as for the contents of doublepuppet.yaml:
#+begin_src yaml doublepuppet.yaml
id: doublepuppet
url:
as_token: doublepuppet
hs_token: notused
sender_localpart: notused
rate_limited: false
namespaces:
users:
- regex: '@.*:matrix2\.swarsel\.win'
exclusive: false
#+end_src
Lastly, the machine that runs matrix needs to regularly update, as otherwise you will lose connectivity to the bridges.
#+begin_src nix :tangle profiles/remote/oracle/matrix/nixos.nix
{ config, pkgs, modulesPath, unstable, sops, ... }: let
@ -3104,7 +3147,7 @@ Make sure to also do this for doublepuppet.yaml
imports = [
./hardware-configuration.nix
(unstable + "/nixos/modules/services/matrix/mautrix-signal.nix")
# (unstable + "/nixos/modules/services/matrix/mautrix-signal.nix") # no longer needed; mautrix-signal was added to nixpkgs
];
environment.systemPackages = with pkgs; [
@ -3383,6 +3426,7 @@ Make sure to also do this for doublepuppet.yaml
services.mautrix-signal = {
enable = true;
registerToSynapse = false; # this has the same effect as registering to app_service_config_file above
# environmentFile = config.sops.templates.mautrixwhatsapp.path;
settings = {
homeserver = {

161
Wiki.org Normal file
View file

@ -0,0 +1,161 @@
#+title: Useful Nix bits
This pages houses a few configuration snippets that might be useful if you are new to the nix ecosystem. It will be infrequently updated as I come across things that I deem to be interesting to such a reader.
* Importing a NixOS module that is not in nixpkgs
This requires changes in multiple locations. As an example we will use an early version of the mautrix-signal module by Niklas Korz.
1) Add the module source to flake.nix:
#+begin_src nix flake.nix
{
inputs = {
[...]
# provides expressions for mautrix-signal
nixpkgs-mautrix-signal ={
url = github:niklaskorz/nixpkgs/nixos-23.11-mautrix-signal;
};
[...]
};
outputs = inputs@{
self,
[...]
nixpkgs-mautrix-signal,
[...]
}: let
[...]
pkgsmautrix = import nixpkgs-mautrix-signal { inherit system;
config.allowUnfree = true;
};
[...]
in {
nixosConfigurations = {
matrix = nixpkgs.lib.nixosSystem {
pkgs = pkgsmautrix;
# this is to import a service module that is not on nixpkgs
# this way avoids infinite recursion errors
specialArgs.unstable = nixpkgs-mautrix-signal;
modules = [
[...]
];
};
};
}
}
#+end_src
2) Import the module in the configuration:
#+begin_src nix configuration.nix
[...]
imports = [
[...]
(unstable + "/nixos/modules/services/matrix/mautrix-signal.nix")
];
[...]
#+end_src
* Build a firefox addon
#+begin_src nix configuration.nix
programs.firefox = {
[...]
profiles.default = {
[...]
extensions = with pkgs.nur.repos.rycee.firefox-addons; [
[...]
(buildFirefoxXpiAddon {
pname = ":emoji:";
version = "0.1.3";
addonId = "gonelf@gmail.com";
url = "https://addons.mozilla.org/firefox/downloads/file/3365324/emojidots-0.1.3.xpi";
sha256 = "4f7cc25c478fe52eb82f37c9ff4978dcaa3f95020398c5b184e517f6efa2c201";
meta = with lib;
{
description = "emoji autocomplete anywhere on the internet";
mozPermissions = [ "https://gist.githubusercontent.com/gonelf/d8ae3ccb7902b501c4a5dd625d4089da/raw/5eeda197ba92f8c8139e846a1225d5640077e06f/emoji_pretty.json" "tabs" "storage"];
platforms = platforms.all;
};
})
[...]
#+end_src
* Define shell utility as package
#+begin_src nix configuration.nix
home.packages = with pkgs; [ # or for NixOS environment.systemPackages = with pkgs; [
[...]
(pkgs.writeShellApplication {
name = "pass-fuzzel";
runtimeInputs = [ pkgs.pass pkgs.fuzzel ];
text = ''
shopt -s nullglob globstar
typeit=0
if [[ $# -ge 1 && $1 == "--type" ]]; then
typeit=1
shift
fi
export PASSWORD_STORE_DIR=~/.local/share/password-store
prefix=''${PASSWORD_STORE_DIR-~/.local/share/password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "''${password_files[@]#"$prefix"/}" )
password_files=( "''${password_files[@]%.gpg}" )
password=$(printf '%s\n' "''${password_files[@]}" | fuzzel --dmenu "$@")
[[ -n $password ]] || exit
if [[ $typeit -eq 0 ]]; then
pass show -c "$password" &>/tmp/pass-fuzzel
else
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
fi
notify-send -u critical -a pass -t 1000 "Copied/Typed Password"
'';
})
[...]
#+end_src
* Add program with prebuild binaries to nix store
#+begin_src nix configuration.nix
home.packages = with pkgs; [ # or for NixOS environment.systemPackages = with pkgs; [
[...]
(stdenv.mkDerivation {
name = "oama";
src = pkgs.fetchurl {
name = "oama";
url = "https://github.com/pdobsan/oama/releases/download/0.13.1/oama-0.13.1-Linux-x86_64-static.tgz";
sha256 = "sha256-OTdCObVfnMPhgZxVtZqehgUXtKT1iyqozdkPIV+i3Gc=";
};
phases = [
"unpackPhase"
];
unpackPhase = ''
mkdir -p $out/bin
tar xvf $src -C $out/
mv $out/oama-0.13.1-Linux-x86_64-static/oama $out/bin/
'';
})
[...]
#+end_src
* Patch a utilty for nix paths:
See https://drakerossman.com/blog/how-to-patch-a-package-source-on-nixos

View file

@ -4,7 +4,7 @@ in {
imports = [
./hardware-configuration.nix
(unstable + "/nixos/modules/services/matrix/mautrix-signal.nix")
# (unstable + "/nixos/modules/services/matrix/mautrix-signal.nix") # no longer needed; mautrix-signal was added to nixpkgs
];
environment.systemPackages = with pkgs; [
@ -283,6 +283,7 @@ in {
services.mautrix-signal = {
enable = true;
registerToSynapse = false; # this has the same effect as registering to app_service_config_file above
# environmentFile = config.sops.templates.mautrixwhatsapp.path;
settings = {
homeserver = {