Showing preview only (1,788K chars total). Download the full file or copy to clipboard to get everything.
Repository: ibizaman/selfhostblocks
Branch: main
Commit: bba09dc607cf
Files: 180
Total size: 1.7 MB
Directory structure:
gitextract_ff0ttxqq/
├── .github/
│ ├── dependabot.yml
│ └── workflows/
│ ├── auto-merge.yaml
│ ├── build.yaml
│ ├── demo.yml
│ ├── format.yaml
│ ├── lock-update.yaml
│ ├── pages.yml
│ └── version.yaml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── VERSION
├── demo/
│ ├── homeassistant/
│ │ ├── README.md
│ │ ├── configuration.nix
│ │ ├── flake.nix
│ │ ├── hardware-configuration.nix
│ │ ├── keys.txt
│ │ ├── secrets.yaml
│ │ ├── sops.yaml
│ │ ├── ssh_config
│ │ ├── sshkey
│ │ └── sshkey.pub
│ ├── minimal/
│ │ └── flake.nix
│ └── nextcloud/
│ ├── README.md
│ ├── configuration.nix
│ ├── flake.nix
│ ├── hardware-configuration.nix
│ ├── keys.txt
│ ├── secrets.yaml
│ ├── sops.yaml
│ ├── ssh_config
│ ├── sshkey
│ └── sshkey.pub
├── docs/
│ ├── blocks.md
│ ├── contracts.md
│ ├── contributing.md
│ ├── default.nix
│ ├── demos.md
│ ├── generate-redirects-nixos-render-docs.py
│ ├── manual.md
│ ├── options.md
│ ├── preface.md
│ ├── recipes/
│ │ ├── dnsServer.md
│ │ ├── exposeService.md
│ │ └── serveStaticPages.md
│ ├── recipes.md
│ ├── redirects.json
│ ├── service-implementation-guide.md
│ ├── services.md
│ └── usage.md
├── flake.nix
├── lib/
│ ├── default.nix
│ ├── homepage.nix
│ └── module.nix
├── modules/
│ ├── blocks/
│ │ ├── authelia/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── authelia.nix
│ │ ├── backup/
│ │ │ └── dashboard/
│ │ │ └── Backups.json
│ │ ├── borgbackup/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── borgbackup.nix
│ │ ├── davfs.nix
│ │ ├── hardcodedsecret.nix
│ │ ├── lldap/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── lldap.nix
│ │ ├── mitmdump/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── mitmdump.nix
│ │ ├── monitoring/
│ │ │ ├── dashboards/
│ │ │ │ ├── Errors.json
│ │ │ │ ├── Health.json
│ │ │ │ ├── Performance.json
│ │ │ │ └── Scraping_Jobs.json
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── rules.json
│ │ ├── monitoring.nix
│ │ ├── nginx/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── nginx.nix
│ │ ├── postgresql/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── postgresql.nix
│ │ ├── restic/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── dummyModule.nix
│ │ ├── restic.nix
│ │ ├── sops/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── sops.nix
│ │ ├── ssl/
│ │ │ ├── dashboard/
│ │ │ │ └── SSL.json
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── ssl.nix
│ │ ├── tinyproxy.nix
│ │ ├── vpn.nix
│ │ └── zfs.nix
│ ├── contracts/
│ │ ├── backup/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ ├── dummyModule.nix
│ │ │ └── test.nix
│ │ ├── backup.nix
│ │ ├── dashboard/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── dummyModule.nix
│ │ ├── dashboard.nix
│ │ ├── databasebackup/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ ├── dummyModule.nix
│ │ │ └── test.nix
│ │ ├── databasebackup.nix
│ │ ├── default.nix
│ │ ├── mount.nix
│ │ ├── secret/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ ├── dummyModule.nix
│ │ │ └── test.nix
│ │ ├── secret.nix
│ │ ├── ssl/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── dummyModule.nix
│ │ └── ssl.nix
│ └── services/
│ ├── arr/
│ │ └── docs/
│ │ └── default.md
│ ├── arr.nix
│ ├── audiobookshelf/
│ │ └── docs/
│ │ └── default.md
│ ├── audiobookshelf.nix
│ ├── deluge/
│ │ └── dashboard/
│ │ └── Torrents.json
│ ├── deluge.nix
│ ├── firefly-iii/
│ │ └── docs/
│ │ └── default.md
│ ├── firefly-iii.nix
│ ├── forgejo/
│ │ └── docs/
│ │ └── default.md
│ ├── forgejo.nix
│ ├── grocy.nix
│ ├── hledger.nix
│ ├── home-assistant/
│ │ └── docs/
│ │ └── default.md
│ ├── home-assistant.nix
│ ├── homepage/
│ │ └── docs/
│ │ └── default.md
│ ├── homepage.nix
│ ├── immich.nix
│ ├── jellyfin/
│ │ └── docs/
│ │ └── default.md
│ ├── jellyfin.nix
│ ├── karakeep/
│ │ └── docs/
│ │ └── default.md
│ ├── karakeep.nix
│ ├── mailserver/
│ │ └── docs/
│ │ └── default.md
│ ├── mailserver.nix
│ ├── nextcloud-server/
│ │ ├── dashboard/
│ │ │ └── Nextcloud.json
│ │ └── docs/
│ │ └── default.md
│ ├── nextcloud-server.nix
│ ├── open-webui/
│ │ └── docs/
│ │ └── default.md
│ ├── open-webui.nix
│ ├── paperless.nix
│ ├── pinchflat/
│ │ └── docs/
│ │ └── default.md
│ ├── pinchflat.nix
│ ├── vaultwarden/
│ │ └── docs/
│ │ └── default.md
│ └── vaultwarden.nix
├── patches/
│ ├── 0001-nixos-borgbackup-add-option-to-override-state-direct.patch
│ ├── 0001-selfhostblocks-never-onboard.patch
│ ├── lldap.patch
│ └── nextcloudexternalstorage.patch
└── test/
├── blocks/
│ ├── authelia.nix
│ ├── borgbackup.nix
│ ├── keypair.pem
│ ├── lib.nix
│ ├── lldap.nix
│ ├── mitmdump.nix
│ ├── monitoring.nix
│ ├── postgresql.nix
│ ├── restic.nix
│ └── ssl.nix
├── common.nix
├── contracts/
│ ├── backup.nix
│ ├── databasebackup.nix
│ ├── secret/
│ │ └── sops.yaml
│ └── secret.nix
├── modules/
│ ├── davfs.nix
│ ├── homepage.nix
│ └── lib.nix
└── services/
├── arr.nix
├── audiobookshelf.nix
├── deluge.nix
├── firefly-iii.nix
├── forgejo.nix
├── grocy.nix
├── hledger.nix
├── home-assistant.nix
├── homepage.nix
├── immich.nix
├── jellyfin.nix
├── karakeep.nix
├── nextcloud.nix
├── open-webui.nix
├── paperless.nix
├── pinchflat.nix
└── vaultwarden.nix
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/dependabot.yml
================================================
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- ibizaman
================================================
FILE: .github/workflows/auto-merge.yaml
================================================
name: Auto Merge
on:
# Try enabling auto-merge for a pull request when a draft is marked as “ready for review”, when
# a required label is applied or when a “do not merge” label is removed, or when a pull request
# is updated in any way (opened, synchronized, reopened, edited).
pull_request_target:
types:
- opened
- synchronize
- reopened
- edited
- labeled
- unlabeled
- ready_for_review
# Try enabling auto-merge for the specified pull request or all open pull requests if none is
# specified.
workflow_dispatch:
inputs:
pull-request:
description: Pull Request Number
required: false
jobs:
automerge:
runs-on: ubuntu-latest
steps:
- uses: reitermarkus/automerge@v2
with:
token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
merge-method: rebase
do-not-merge-labels: never-merge
required-labels: automerge
pull-request: ${{ github.event.inputs.pull-request }}
review: ${{ github.event.inputs.review }}
dry-run: false
================================================
FILE: .github/workflows/build.yaml
================================================
# name: build
# on: push
# jobs:
# checks:
# uses: nixbuild/nixbuild-action/.github/workflows/ci-workflow.yml@v19
# with:
# nix_conf: |
# allow-import-from-derivation = true
# secrets:
# nixbuild_token: ${{ secrets.nixbuild_token }}
name: "build"
on:
pull_request:
push:
branches: [ "main" ]
jobs:
path-filter:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.any_changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- uses: tj-actions/changed-files@v47
id: filter
with:
files: |
lib/**
modules/**
!modules/**/docs/**
test/**
flake.lock
flake.nix
.github/workflows/build.yaml
separator: "\n"
- env:
ALL_CHANGED_FILES: ${{ steps.filter.outputs.all_changed_files }}
run: |
echo $ALL_CHANGED_FILES
build-matrix:
needs: [ "path-filter" ]
if: needs.path-filter.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
enable_kvm: true
extra_nix_config: |
keep-outputs = true
keep-failed = true
- name: Setup Caching
uses: cachix/cachix-action@v17
with:
name: selfhostblocks
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Generate Matrix
id: generate-matrix
run: |
set -euox pipefail
nix flake show --allow-import-from-derivation --json \
| jq -c '.["checks"]["x86_64-linux"] | keys' > .output
cat .output
echo dynamic_list="$(cat .output)" >> "$GITHUB_OUTPUT"
outputs:
check: ${{ steps.generate-matrix.outputs.dynamic_list }}
manual:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
enable_kvm: true
extra_nix_config: |
keep-outputs = true
keep-failed = true
- name: Setup Caching
uses: cachix/cachix-action@v17
with:
name: selfhostblocks
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build
run: |
nix \
--print-build-logs \
--option keep-going true \
--show-trace \
build .#manualHtml
tests:
runs-on: ubuntu-latest
needs: [ "build-matrix" ]
strategy:
fail-fast: false
matrix:
check: ${{ fromJson(needs.build-matrix.outputs.check) }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
enable_kvm: true
extra_nix_config: |
keep-outputs = true
keep-failed = true
- name: Setup Caching
uses: cachix/cachix-action@v17
with:
name: selfhostblocks
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build
run: |
echo "resultPath=$(nix eval .#checks.x86_64-linux.${{ matrix.check }} --raw)" >> $GITHUB_ENV
nix build --print-build-logs --show-trace .#checks.x86_64-linux.${{ matrix.check }}
- name: Upload Build Result
uses: actions/upload-artifact@v7
if: always() && startsWith(matrix.check, 'vm_')
with:
name: ${{ matrix.check }}
path: ${{ env.resultPath }}/trace/*
overwrite: true
if-no-files-found: ignore
results:
name: Final Results
runs-on: ubuntu-latest
needs: [ manual, tests ]
if: '!cancelled()'
steps:
- run: |
result="${{ needs.manual.result }}"
if ! [[ $result == "success" || $result == "skipped" ]]; then
exit 1
fi
result="${{ needs.tests.result }}"
if ! [[ $result == "success" || $result == "skipped" ]]; then
exit 1
fi
exit 0
================================================
FILE: .github/workflows/demo.yml
================================================
name: Demo
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
jobs:
path-filter:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.filter.outputs.any_changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- uses: tj-actions/changed-files@v47
id: filter
with:
files: |
demo/**
lib/**
modules/**
!modules/**/docs/**
test/**
flake.lock
flake.nix
.github/workflows/demo.yml
separator: "\n"
- env:
ALL_CHANGED_FILES: ${{ steps.filter.outputs.all_changed_files }}
run: |
echo $ALL_CHANGED_FILES
build:
needs: [ "path-filter" ]
if: needs.path-filter.outputs.changed == 'true'
strategy:
fail-fast: false
matrix:
demo:
- name: homeassistant
flake: basic
- name: homeassistant
flake: ldap
- name: nextcloud
flake: basic
- name: nextcloud
flake: ldap
- name: nextcloud
flake: sso
- name: minimal
flake: minimal
- name: minimal
flake: lowlevel
- name: minimal
flake: sops
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
enable_kvm: true
extra_nix_config: |
keep-outputs = true
keep-failed = true
- uses: cachix/cachix-action@v17
with:
name: selfhostblocks
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build ${{ matrix.demo.name }} .#${{ matrix.demo.flake }}
run: |
cd demo/${{ matrix.demo.name }}
nix flake update --override-input selfhostblocks ../.. selfhostblocks
nix \
--print-build-logs \
--option keep-going true \
--show-trace \
build .#nixosConfigurations.${{ matrix.demo.flake }}.config.system.build.toplevel
nix \
--print-build-logs \
--option keep-going true \
--show-trace \
build .#nixosConfigurations.${{ matrix.demo.flake }}.config.system.build.vm
result:
runs-on: ubuntu-latest
needs: [ "build" ]
if: '!cancelled()'
steps:
- run: |
result="${{ needs.build.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi
================================================
FILE: .github/workflows/format.yaml
================================================
name: "format"
on:
pull_request:
push:
branches: [ "main" ]
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Caching
uses: cachix/cachix-action@v17
with:
name: selfhostblocks
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Check Formatting
run: |
find . -name '*.nix' | nix fmt -- --ci
================================================
FILE: .github/workflows/lock-update.yaml
================================================
name: Update Flake Lock
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # runs daily at 00:00
jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@main
with:
token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
pr-labels: |
automerge
================================================
FILE: .github/workflows/pages.yml
================================================
# Inspired from https://github.com/nix-community/nix-on-droid/blob/039379abeee67144d4094d80bbdaf183fb2eabe5/.github/workflows/docs.yml
name: Deploy docs
on:
push:
branches: ["main"]
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Caching
uses: cachix/cachix-action@v17
with:
name: selfhostblocks
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build docs
run: |
nix \
--print-build-logs \
--option keep-going true \
--show-trace \
build .#manualHtml
# see https://github.com/actions/deploy-pages/issues/58
cp \
--recursive \
--dereference \
--no-preserve=mode,ownership \
result/share/doc/selfhostblocks \
public
- name: Setup Pages
uses: actions/configure-pages@v6
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: ./public
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
================================================
FILE: .github/workflows/version.yaml
================================================
name: Version Bump
on:
push:
branches:
- main
paths:
- VERSION
jobs:
create-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Get version
id: vars
run: echo "version=v$(cat VERSION)" >> $GITHUB_OUTPUT
- uses: rickstaa/action-create-tag@v1.7.2
with:
tag: ${{ steps.vars.outputs.version }}
================================================
FILE: .gitignore
================================================
*.qcow2
result
result-*
docs/redirects.json.backup
.nixos-test-history
\#*#
================================================
FILE: CHANGELOG.md
================================================
<!---
Template:
## Breaking Changes
## New Features
## User Facing Backwards Compatible Changes
## Fixes
## Other Changes
-->
# Upcoming Release
## Breaking Changes
- Bump of Nextcloud version to 32 and 33 because of nixpkgs bump. All provided apps are verified compatible with Nextcloud 33 thanks to new tests.
## New Features
- Added Immich Public Proxy service
- Add homepage service with dashboard contract implemented by all services
- Add scrutiny service.
- ZFS module now supports setting permissions
- Add landing page for mailserver and dashboard contract integration
## Bug Fixes
- Use configurable dataDir in arr stack
- Forgejo ensures ldap is setup when sso is configured
- Add nixpkgs patches on aarch64-linux too
- Self-signed certs are now idempotent
- Prometheus scrapes metrics at 15s interval instead of 1m
## Other Changes
- Arr stack declares ldap groups, declare ApiKeys and bypasses auth for readarr when sso is enabled
- Forgejo declares ldap group
# v0.7.3
## New Features
- Add [mailserver module](https://shb.skarabox.com/services-mailserver.html) integrating with [Simple NixOS Mailserver](https://gitlab.com/simple-nixos-mailserver/nixos-mailserver) and allowing full backup of an email provider.
- Bump nixpkgs from https://github.com/NixOS/nixpkgs/commit/5e2a59a5b1a82f89f2c7e598302a9cacebb72a67 to https://github.com/NixOS/nixpkgs/commit/bfc1b8a4574108ceef22f02bafcf6611380c100d. [Full diff](https://github.com/nixos/nixpkgs/compare/5e2a59a5b1a82f89f2c7e598302a9cacebb72a67...bfc1b8a4574108ceef22f02bafcf6611380c100d).
On top of minor changes, the most notable one was:
- Updated Jellyfin LDAP and SSO plugins and configuration. @Codys-Wright
## Bug Fixes
- Fix Restic and Authelia modules referencing systemd services without the `.service` suffix and leading to
# v0.7.2
## New Features
- Forgejo uses secrets contract for smtp password.
- Add [Firefly-iii](https://shb.skarabox.com/services-firefly-iii.html) service.
- Jellyfin can [install plugins declaratively](https://shb.skarabox.com/services-jellyfin.html#services-jellyfin-options-shb.jellyfin.plugins).
(Support is quite crude and WIP).
- Jellyfin configures LDAP and SSO fully declaratively, including installing necessary plugins.
- Nextcloud 32 is fully supported thanks to tests for version 31 and 32.
## Fixes
- Revert Authelia to continue using dots in systemd service names.
This caused issue with nginx name resolution.
## Other Changes
- Authelia uses non deprecated `smtp.address` option.
- Add documentation for Nginx block
- Now a user which is only member of the admin LDAP group of a service can login.
Before, some services required a user to be member of both the user and admin LDAP group.
This is ensured by regression tests going forward.
# v0.7.1
## New Features
- Add a Grafana dashboard showing SSL certificate renewal jobs
## Fixes
- Fix let's encrypt certificate renewal jobs by removing duplicated domain name.
Also adds an assertion to catch these kinds of errors.
## Other Changes
- Reduce number of late SSL renewal alert by merging all metrics corresponding to one CN.
# v0.7.0
## Breaking Changes
- Fix pkgs overrides not being passed to users of SelfHostBlocks.
This will require to update your flake to follow the example in the [Usage](https://shb.skarabox.com/usage.html) section.
## New Features
- Add a Grafana dashboard showing stats on backup jobs
and also an alert if a backup job did not run in the last 24 hours or never succeeded in the last 24 hours.
- Add SSO integration in Grafana.
- Add Paperless service.
## Fixes
- Allow to upload big files in Immich.
- Only enable php-fpm Prometheus exporter if Nextcloud is enabled.
## Other Changes
- Add recipe to setup DNS server with DNSSEC.
# v0.6.1
## New Features
- Implement backup and databasebackup contracts with BorgBackup block.
## Fixes
- Add back erroneously removed Prometheus collectors.
# v0.6.0
## Breaking Changes
- Removed Nextcloud 30, update to Nextcloud 31 then after to 32.
- Removed the `sops` module in the `default` NixOS module. Removed the `all` NixOS module.
## New Features
- Meilisearch configured with production environment and master key.
## Other Changes
- Only import hardcodedsecret module in tests.
- Better usage section in manual.
- Added new demo for minimal SelfHostBlocks setup, which is tested in CI.
- Format all files in repo and make sure they are formatted in CI.
# v0.5.1
## New Features
- Added Karakeep service with SSO integration.
- Add SelfHostBlocks' `lib` into `pkgs.lib.shb`. Integrates with [Skarabox](https://github.com/ibizaman/skarabox/blob/631ff5af0b5c850bb63a3b3df451df9707c0af4e/template/flake.nix#L42-L43) too.
## Other Changes
- Moved implementation guide under contributing section.
# v0.5.0
## Breaking Changes
- Modules in the `nixosModules` output field do not anymore have the `system` in their path.
`selfhostblocks.nixosModules.x86_64-linux.home-assistant` becomes `selfhostblocks.nixosModules.home-assistant`
like it always should have been.
## Fixes
- Added test case making sure a user belonging to a not authorized LDAP group cannot login.
Fixed Open WebUI module.
- Now importing a single module, like `selfhostblocks.nixosModules.home-assistant`, will
import all needed block modules at the same time.
## Other Changes
- Nextcloud module can now setup SSO integration without setting up LDAP integration.
# v0.4.4
## New Features
- Added Pinchflat service with SSO integration. Declarative user creation only supported through SSO integration.
- Added Immich service with SSO integration.
- Added Open WebUI service with SSO integration.
# v0.4.3
## New Features
- Allow user to change their SSO password in Authelia.
- Make Audiobookshelf SSO integration respect admin users.
## Fixes
- Fix permission on Nextcloud systemd service.
- Delete Forgejo backups correctly to avoid them piling up.
## Other Changes
- Add recipes section to the documentation.
# v0.4.2
## New Features
- The LLDAP and Authelia modules gain a debug mode where a mitmdump instance is added so all traffic is printed.
## Fixes
- By default, LLDAP module only enforces groups declaratively. Users that are not defined declaratively
are not anymore deleted by inadvertence.
- SSO integration with most services got fixed. A recent incompatible change in upstream Authelia broke most of them.
- Fixed PostgreSQL and Home Assistant modules after nixpkgs updates.
- Fixed Nextcloud module SSO integration with Authelia.
- Make Nextcloud SSO integration respect admin users.
# v0.4.1
## New Features
- LLDAP now manages users, groups, user attributes and group attributes declaratively.
- Individual modules are exposed in the flake output for each block and service.
- A mitmdump block is added that can be placed between two services and print all requests and responses.
- The SSO setup for Audiobookshelf is now a bit more declarative.
## Other Changes
- Forgejo got a new playwright test to check the LDAP integration.
- Some renaming options have been added retroactively for jellyfin and forgejo.
# v0.4.0
## Breaking Changes
- Rename ldap module to lldap as well as option name `shb.ldap` to `shb.lldap`.
## New Features
- Jellyfin service now waits for Jellyfin server to be fully available before starting.
- Add debug option for Jellyfin.
- Allow to choose port for Jellyfin.
- Make Jellyfin setup including initial admin user declarative.
## Fixes
- Fix Jellyfin redirect URI scheme after update.
## Other Changes
- Add documentation for LLDAP and Authelia block and link to it from other docs.
# v0.3.1
## Breaking Changes
- Default version of Nextcloud is now 30.
- Disable memories app on Nextcloud because it is broken.
## New Features
- Add patchNixpkgs function and pre-patched patchedNixpkgs output.
## Fixes
- Fix secrets passing to Nextcloud service after update.
## Other Changes
- Bump nixpkgs to https://github.com/NixOS/nixpkgs/commit/216207b1e58325f3590277d9102b45273afe9878
# v0.3.0
## New Features
- Add option to add extra args to hledger command.
## Breaking Changes
- Default version of Nextcloud is now 29.
## Fixes
- Home Assistant config gets correctly generated with secrets
even if LDAP integration is not enabled.
- Fix Jellyfin SSO plugin which was left badly configured
after a code refactoring.
## Other Changes
- Add a lot of playwright tests for services.
- Add service implementation manual page to document
how to integrate a service in SHB.
- Add `update-redirects` command to manage the `redirect.json` page.
- Add home-assistant manual.
# v0.2.10
## New Features
- Add `shb.forgejo.users` option to create users declaratively.
## Fixes
- Make Nextcloud create the external storage if it's a local storage
and the directory does not exist yet.
- Disable flow to change password on first login for admin Forgejo user.
This is not necessary since the password comes from some secret store.
## Breaking Changes
- Fix internal link for Home Assistant
which now points to the fqdn. This fixes Voice Assistant
onboarding. This is a breaking change if one relies on
reaching Home Assistant through the IP address but I
don't recommend that. It's much better to have a DNS
server running locally which redirects the fqdn to the
server running Home Assistant.
## Other Changes
- Refactor tests and add playwright tests for services.
# v0.2.9
## New Features
- Add Memories Nextcloud app declaratively configured.
- Add Recognize Nextcloud app declaratively configured.
# v0.2.8
## New Features
- Add dashboard for SSL certificates validity
and alert they did not renew on time.
## Fixes
- Only enable php-fpm exporter when php-fpm is enabled.
## Breaking Changes
- Remove upgrade script from postgres 13 to 14 and 14 to 15.
# v0.2.7
## New Features
- Add dashboard for Nextcloud with PHP-FPM exporter.
- Add voice option to Home-Assistant.
## User Facing Backwards Compatible Changes
- Add hostname and domain labels for scraped Prometheus metrics and Loki logs.
# v0.2.6
## New Features
- Add dashboard for deluge.
# v0.2.5
## Other Changes
- Fix more modules using backup contract.
# v0.2.4
## Other Changes
- Fix modules using backup contract.
# v0.2.3
## Breaking Changes
- Options `before_backup` and `after_backup` for backup contract have been renamed to
`beforeBackup` and `afterBackup`.
- All options using the backup and databasebackup contracts now use the new style.
## Other Changes
- Show how to pin Self Host Blocks flake input to a tag.
# v0.2.2
## User Facing Backwards Compatible Changes
- Fix: add implementation for `sops.nix` module.
## Other Changes
- Use VERSION when rendering manual too.
# v0.2.1
## User Facing Backwards Compatible Changes
- Add `sops.nix` module to `nixosModules.default`.
## Other Changes
- Auto-tagging of git repo when VERSION file gets updated.
- Add VERSION file to track version.
# v0.2.0
## New Features
- Backup:
- Add feature to backup databases with the database backup contract, implemented with `shb.restic.databases`.
## Breaking Changes
- Remove dependency on `sops-nix`.
- Rename `shb.nginx.autheliaProtect` to `shb.nginx.vhosts`. Indeed, the option allows to define a vhost with _optional_ Authelia protection but the former name made it look like Authelia protection was enforced.
- Rename all `shb.arr.*.APIKey` to `shb.arr.*.ApiKey`.
- Remove `shb.vaultwarden.ldapEndpoint` option because it was not used in the implementation anyway.
- Bump Nextcloud default version from 27 to 28. Add support for version 29.
- Deluge config breaks the authFile into an attrset of user to password file. Also deluge has tests now.
- Nextcloud now configures the LDAP app to use the `user_id` from LLDAP as the user ID used in Nextcloud. This makes all source of user - internal, LDAP and SSO - agree on the user ID.
- Authelia options changed:
- `shb.authelia.oidcClients.id` -> `shb.authelia.oidcClients.client_id`
- `shb.authelia.oidcClients.description` -> `shb.authelia.oidcClients.client_name`
- `shb.authelia.oidcClients.secret` -> `shb.authelia.oidcClients.client_secret`
- `shb.authelia.ldapEndpoint` -> `shb.authelia.ldapHostname` and `shb.authelia.ldapPort`
- `shb.authelia.jwtSecretFile` -> `shb.authelia.jwtSecret.result.path`
- `shb.authelia.ldapAdminPasswordFile` -> `shb.authelia.ldapAdminPassword.result.path`
- `shb.authelia.sessionSecretFile` -> `shb.authelia.sessionSecret.result.path`
- `shb.authelia.storageEncryptionKeyFile` -> `shb.authelia.storageEncryptionKey.result.path`
- `shb.authelia.identityProvidersOIDCIssuerPrivateKeyFile` -> `shb.authelia.identityProvidersOIDCIssuerPrivateKey.result.path`
- `shb.authelia.smtp.passwordFile` -> `shb.authelia.smtp.password.result.path`
- Make Nextcloud automatically disable maintenance mode upon service restart.
- `shb.ldap.ldapUserPasswordFile` -> `shb.ldap.ldapUserPassword.result.path`
- `shb.ldap.jwtSecretFile` -> `shb.ldap.jwtSecret.result.path`
- Jellyfin changes:
- `shb.jellyfin.ldap.passwordFile` -> `shb.jellyfin.ldap.adminPassword.result.path`.
- `shb.jellyfin.sso.secretFile` -> `shb.jellyfin.ldap.sharedSecret.result.path`.
- + `shb.jellyfin.ldap.sharedSecretForAuthelia`.
- Forgejo changes:
- `shb.forgejo.ldap.adminPasswordFile` -> `shb.forgejo.ldap.adminPassword.result.path`.
- `shb.forgejo.sso.secretFile` -> `shb.forgejo.ldap.sharedSecret.result.path`.
- `shb.forgejo.sso.secretFileForAuthelia` -> `shb.forgejo.ldap.sharedSecretForAuthelia.result.path`.
- `shb.forgejo.adminPasswordFile` -> `shb.forgejo.adminPassword.result.path`.
- `shb.forgejo.databasePasswordFile` -> `shb.forgejo.databasePassword.result.path`.
- Backup:
- `shb.restic.instances` options has been split between `shb.restic.instances.request` and `shb.restic.instances.settings`, matching better with contracts.
- Use of secret contract everywhere.
## User Facing Backwards Compatible Changes
- Add mount contract.
- Export torrent metrics.
- Bump chunkSize in Nextcloud to boost performance.
- Fix home-assistant onboarding file generation. Added new VM test.
- OIDC and SMTP config are now optional in Vaultwarden. Added new VM test.
- Add default OIDC config for Authelia. This way, Authelia can start even with no config or only forward auth configs.
- Fix replaceSecrets function. It wasn't working correctly with functions from `lib.generators` and `pkgs.pkgs-lib.formats`. Also more test coverage.
- Add udev extra rules to allow smartctl Prometheus exporter to find NVMe drives.
- Revert Loki to major version 2 because upgrading to version 3 required manual intervention as Loki
refuses to start. So until this issue is tackled, reverting is the best immediate fix.
See https://github.com/NixOS/nixpkgs/commit/8f95320f39d7e4e4a29ee70b8718974295a619f4
- Add prometheus deluge exporter support. It just needs the `shb.deluge.prometheusScraperPasswordFile` option to be set.
## Other Changes
- Add pretty printing of test errors. Instead of:
```
error: testRadarr failed: expected {"services":{"bazarr":{},"jackett":{},"lidarr":{},"nginx":{"enable":true},"radarr":{"dataDir":"/var/lib/radarr","enable":true,"group":"radarr","user":"radarr"},"readarr":{},"sonarr":{}},"shb":{"backup":{"instances":{"radarr":{"excludePatterns":[".db-shm",".db-wal",".mono"],"sourceDirectories":["/var/lib/radarr"]}}},"nginx":{"autheliaProtect":[{"authEndpoint":"https://oidc.example.com","autheliaRules":[{"domain":"radarr.example.com","policy":"bypass","resources":["^/api.*"]},{"domain":"radarr.example.com","policy":"two_factor","subject":["group:arr_user"]}],"domain":"example.com","ssl":null,"subdomain":"radarr","upstream":"http://127.0.0.1:7878"}]}},"systemd":{"services":{"radarr":{"serviceConfig":{"StateDirectoryMode":"0750","UMask":"0027"}}},"tmpfiles":{"rules":["d '/var/lib/radarr' 0750 radarr radarr - -"]}},"users":{"groups":{"radarr":{"members":["backup"]}}}}, but got {"services":{"bazarr":{},"jackett":{},"lidarr":{},"nginx":{"enable":true},"radarr":{"dataDir":"/var/lib/radarr","enable":true,"group":"radarr","user":"radarr"},"readarr":{},"sonarr":{}},"shb":{"backup":{"instances":{"radarr":{"excludePatterns":[".db-shm",".db-wal",".mono"],"sourceDirectories":["/var/lib/radarr"]}}},"nginx":{"vhosts":[{"authEndpoint":"https://oidc.example.com","autheliaRules":[{"domain":"radarr.example.com","policy":"bypass","resources":["^/api.*"]},{"domain":"radarr.example.com","policy":"two_factor","subject":["group:arr_user"]}],"domain":"example.com","ssl":null,"subdomain":"radarr","upstream":"http://127.0.0.1:7878"}]}},"systemd":{"services":{"radarr":{"serviceConfig":{"StateDirectoryMode":"0750","UMask":"0027"}}},"tmpfiles":{"rules":["d '/var/lib/radarr' 0750 radarr radarr - -"]}},"users":{"groups":{"radarr":{"members":["backup"]}}}}
```
You now see:
```
error: testRadarr failed (- expected, + result)
{
"dictionary_item_added": [
"root['shb']['nginx']['vhosts']"
],
"dictionary_item_removed": [
"root['shb']['nginx']['authEndpoint']"
]
}
```
- Made Nextcloud LDAP setup use a hardcoded configID. This makes the detection of an existing config much more robust.
# 0.1.0
Creation of CHANGELOG.md
================================================
FILE: LICENSE
================================================
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
================================================
FILE: README.md
================================================







[](https://github.com/ibizaman/selfhostblocks/actions/workflows/pages.yml)
[](https://github.com/ibizaman/selfhostblocks/actions/workflows/build.yaml)
[](https://github.com/ibizaman/selfhostblocks/actions/workflows/demo.yml)

<hr />
# SelfHostBlocks
SelfHostBlocks is:
- Your escape from the cloud, for privacy and data sovereignty enthusiast. [Why?](#why-self-hosting)
- A groupware to self-host [all your data](#services): documents, pictures, calendars, contacts, etc.
- An opinionated NixOS server management OS for a [safe self-hosting experience](#features).
- A NixOS distribution making sure all services build and work correctly thanks to NixOS VM tests.
- A collection of NixOS modules standardizing options so configuring services [look the same](#unified-interfaces).
- A testing ground for [contracts](#contracts) which intents to make nixpkgs modules more modular.
- [Upstreaming][] as much as possible.
[upstreaming]: https://github.com/pulls?page=1&q=created%3A%3E2023-06-01+is%3Apr+author%3Aibizaman+archived%3Afalse+-repo%3Aibizaman%2Fselfhostblocks+-repo%3Aibizaman%2Fskarabox
## Why Self-Hosting
It is obvious by now that
a deep dependency on proprietary service providers - "the cloud" -
is a significant liability.
One aspect often talked about is privacy
which is inherently not guaranteed when using a proprietary service
and is a valid concern.
A more punishing issue is having your account closed or locked
without prior warning
When that happens,
you get an instantaneous sinking feeling in your stomach
at the realization you lost access to your data,
possibly without recourse.
Hosting services yourself is the obvious alternative
to alleviate those concerns
but it tends to require a lot of technical skills and time.
SelfHostBlocks (together with its sibling project [Skarabox][])
aims to lower the bar to self-hosting,
and provides an opinionated server management system based on NixOS modules
embedding best practices.
Contrary to other server management projects,
its main focus is ease of long term maintenance
before ease of installation.
To achieve this, it provides building blocks to setup services.
Some are already provided out of the box,
and customizing or adding additional ones is done easily.
The building blocks fit nicely together thanks to [contracts](#contracts)
which SelfHostBlocks sets out to introduce into nixpkgs.
This will increase modularity, code reuse
and empower end users to assemble components
that fit together to build their server.
## TOC
<!--toc:start-->
- [Usage](#usage)
- [At a Glance](#at-a-glance)
- [Existing Installation](#existing-installation)
- [Installation From Scratch](#installation-from-scratch)
- [Features](#features)
- [Services](#services)
- [Blocks](#blocks)
- [Unified Interfaces](#unified-interfaces)
- [Contracts](#contracts)
- [Interfacing With Other OSes](#interfacing-with-other-oses)
- [Sitting on the Shoulders of a Giant](#sitting-on-the-shoulders-of-a-giant)
- [Automatic Updates](#automatic-updates)
- [Demos](#demos)
- [Roadmap](#roadmap)
- [Community](#community)
- [Funding](#funding)
- [License](#license)
<!--toc:end-->
## Usage
> **Caution:** You should know that although I am using everything in this repo for my personal
> production server, this is really just a one person effort for now and there are most certainly
> bugs that I didn't discover yet.
To get started using SelfHostBlocks, the following snippet is enough:
```nix
{
inputs.selfhostblocks.url = "github:ibizaman/selfhostblocks";
outputs = { selfhostblocks, ... }: let
system = "x86_64-linux";
nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs;
in
nixosConfigurations = {
myserver = nixpkgs'.nixosSystem {
inherit system;
modules = [
selfhostblocks.nixosModules.default
./configuration.nix
];
};
};
}
```
SelfHostBlocks provides its own patched nixpkgs, so you are required to use it
otherwise evaluation can quickly break.
[The usage section](https://shb.skarabox.com/usage.html) of the manual has
more details and goes over how to deploy with [Colmena][], [nixos-rebuild][] and [deploy-rs][]
and also how to handle secrets management with [SOPS][].
[Colmena]: https://shb.skarabox.com/usage.html#usage-example-colmena
[nixos-rebuild]: https://shb.skarabox.com/usage.html#usage-example-nixosrebuild
[deploy-rs]: https://shb.skarabox.com/usage.html#usage-example-deployrs
[SOPS]: https://shb.skarabox.com/usage.html#usage-secrets
Then, to actually configure services, you can choose which one interests you in
the [services section](https://shb.skarabox.com/services.html) of the manual.
The [recipes section](https://shb.skarabox.com/recipes.html) of the manual shows some other common use cases.
Head over to the [matrix channel](https://matrix.to/#/#selfhostblocks:matrix.org)
for any remaining question, or just to say hi :)
### Installation From Scratch
I do recommend for this my sibling project [Skarabox][]
which bootstraps a new server and sets up a few tools:
- Create a bootable ISO, installable on an USB key.
- Handles one or two (in raid 1) SSDs for root partition.
- Handles two (in raid 1) or more hard drives for data partition.
- [nixos-anywhere](https://github.com/nix-community/nixos-anywhere) to install NixOS headlessly.
- [disko](https://github.com/nix-community/disko) to format the drives using native ZFS encryption with remote unlocking through ssh.
- [sops-nix](https://github.com/Mic92/sops-nix) to handle secrets.
- [deploy-rs](https://github.com/serokell/deploy-rs) to deploy updates.
[Skarabox]: https://github.com/ibizaman/skarabox
## Features
SelfHostBlocks provides building blocks that take care of common self-hosting needs:
- Backup for all services.
- Automatic creation of ZFS datasets per service.
- LDAP and SSO integration for most services.
- Monitoring with Grafana and Prometheus stack with provided dashboards and integration with Scrutiny.
- Automatic reverse proxy and certificate management for HTTPS.
- VPN and proxy tunneling services.
Great care is taken to make the proposed stack robust.
This translates into a test suite comprised of automated NixOS VM tests
which includes playwright tests to verify some important workflow
like logging in.
This test suite also serves as a guaranty that all services provided by SelfHostBlocks
all evaluate, build and work correctly together. It works similarly as a distribution but here it's all [automated](#automatic-updates).
Also, the stack fits together nicely thanks to [contracts](#contracts).
### Services
[Provided services](https://shb.skarabox.com/services.html) are:
- Nextcloud
- Audiobookshelf
- Deluge + *arr stack
- Simple NixOS Mailserver
- Firefly-iii
- Forgejo
- Grocy
- Hledger
- Home-Assistant
- Jellyfin
- Karakeep
- Open WebUI
- Pinchflat
- Vaultwarden
Like explained above, those services all benefit from
out of the box backup,
LDAP and SSO integration,
monitoring with Grafana,
reverse proxy and certificate management
and VPN integration for the *arr suite.
Some services do not have an entry yet in the manual.
To know options for those, the only way for now
is to go to the [All Options][] section of the manual.
[All Options]: https://shb.skarabox.com/options.html
### Blocks
The services above rely on the following [common blocks][]
which altogether provides a solid foundation for self-hosting services:
- Authelia
- BorgBackup
- Davfs
- LDAP
- Monitoring (Grafana - Prometheus - Loki stack + Scrutiny)
- Nginx
- PostgreSQL
- Restic
- Sops
- SSL
- Tinyproxy
- VPN
- ZFS
Those blocks can be used with services
not provided by SelfHostBlocks as shown [in the manual][common blocks].
[common blocks]: https://shb.skarabox.com/blocks.html
The manual also provides documentation for each individual blocks.
### Unified Interfaces
Thanks to the blocks,
SelfHostBlocks provides an unified configuration interface
for the services it provides.
Compare the configuration for Nextcloud and Forgejo.
The following snippets focus on similitudes and assume the relevant blocks - like secrets - are configured off-screen.
It also does not show specific options for each service.
These are still complete snippets that configure HTTPS,
subdomain serving the service, LDAP and SSO integration.
```nix
shb.nextcloud = {
enable = true;
subdomain = "nextcloud";
domain = "example.com";
ssl = config.shb.certs.certs.letsencrypt.${domain};
apps.ldap = {
enable = true;
host = "127.0.0.1";
port = config.shb.lldap.ldapPort;
dcdomain = config.shb.lldap.dcdomain;
adminPassword.result = config.shb.sops.secret."nextcloud/ldap/admin_password".result;
};
apps.sso = {
enable = true;
endpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
secret.result = config.shb.sops.secret."nextcloud/sso/secret".result;
secretForAuthelia.result = config.shb.sops.secret."nextcloud/sso/secretForAuthelia".result;
};
};
```
```nix
shb.forgejo = {
enable = true;
subdomain = "forgejo";
domain = "example.com";
ssl = config.shb.certs.certs.letsencrypt.${domain};
ldap = {
enable = true;
host = "127.0.0.1";
port = config.shb.lldap.ldapPort;
dcdomain = config.shb.lldap.dcdomain;
adminPassword.result = config.shb.sops.secret."nextcloud/ldap/admin_password".result;
};
sso = {
enable = true;
endpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
secret.result = config.shb.sops.secret."forgejo/sso/secret".result;
secretForAuthelia.result = config.shb.sops.secret."forgejo/sso/secretForAuthelia".result;
};
};
```
As you can see, they are pretty similar!
This makes setting up a new service pretty easy and intuitive.
SelfHostBlocks provides an ever growing list of [services](#services)
that are configured in the same way.
### Contracts
To make building blocks that fit nicely together,
SelfHostBlocks pioneers [contracts][] which allows you, the final user,
to be more in control of which piece goes where.
This lets you choose, for example,
any reverse proxy you want or any database you want,
without requiring work from maintainers of the services you want to self host.
An [RFC][] exists to upstream this concept into `nixpkgs`.
The [manual][contracts] also provides an explanation of the why and how of contracts.
Also, two videos exist of me presenting the topic,
the first at [NixCon North America in spring of 2024][NixConNA2024]
and the second at [NixCon in Berlin in fall of 2024][NixConBerlin2024].
[contracts]: https://shb.skarabox.com/contracts.html
[RFC]: https://github.com/NixOS/rfcs/pull/189
[NixConNA2024]: https://www.youtube.com/watch?v=lw7PgphB9qM
[NixConBerlin2024]: https://www.youtube.com/watch?v=CP0hR6w1csc
### Interfacing With Other OSes
Thanks to [contracts](#contracts), one can interface NixOS
with systems on other OSes.
The [RFC][] explains how that works.
### Sitting on the Shoulders of a Giant
By using SelfHostBlocks, you get all the benefits of NixOS
which are, for self hosted applications specifically:
- declarative configuration;
- atomic configuration rollbacks;
- real programming language to define configurations;
- create your own higher level abstractions on top of SelfHostBlocks;
- integration with the rest of nixpkgs;
- much fewer "works on my machine" type of issues.
### Automatic Updates
SelfHostBlocks follows nixpkgs unstable branch closely.
There is a GitHub action running every couple of days that updates
the `nixpkgs` input in the root `flakes.nix`,
runs the tests and merges the PR automatically
if the tests pass.
A release is then made every few commits,
whenever deemed sensible.
On your side, to update I recommend pinning to a release
with the following command,
replacing the RELEASE with the one you want:
```bash
RELEASE=0.2.4
nix flake update \
--override-input selfhostblocks github:ibizaman/selfhostblocks/$RELEASE \
selfhostblocks
```
### Demos
Demos that start and deploy a service
on a Virtual Machine on your computer are located
under the [demo](./demo/) folder.
These show the onboarding experience you would get
if you deployed one of the services on your own server.
## Roadmap
Currently, the Nextcloud and Vaultwarden services
and the SSL and backup blocks
are the most advanced and most documented.
Documenting all services and blocks will be done
as I make all blocks and services use the contracts.
Upstreaming changes is also on the roadmap.
Check the [issues][] and the [milestones]() to see planned work.
Feel free to add more or to contribute!
[issues]: (https://github.com/ibizaman/selfhostblocks/issues)
[milestones]: https://github.com/ibizaman/selfhostblocks/milestones
All blocks and services have NixOS tests.
Also, I am personally using all the blocks and services in this project, so they do work to some extent.
## Community
This project has been the main focus
of my (non work) life for the past 3 year now
and I intend to continue working on this for a long time.
All issues and PRs are welcome:
- Use this project. Something does not make sense? Something's not working?
- Documentation. Something is not clear?
- New services. Have one of your preferred service not integrated yet?
- Better patterns. See something weird in the code?
For PRs, if they are substantial changes, please open an issue to
discuss the details first. More details in [the contributing section](https://shb.skarabox.com/contributing.html)
of the manual.
Issues that are being worked on are labeled with the [in progress][] label.
Before starting work on those, you might want to talk about it in the issue tracker
or in the [matrix][] channel.
The prioritized issues are those belonging to the [next milestone][milestone].
Those issues are not set in stone and I'd be very happy to solve
an issue an user has before scratching my own itch.
[in progress]: https://github.com/ibizaman/selfhostblocks/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22in%20progress%22
[matrix]: https://matrix.to/#/%23selfhostblocks%3Amatrix.org
[milestone]: https://github.com/ibizaman/selfhostblocks/milestones
One aspect that's close to my heart is I intent to make SelfHostBlocks the lightest layer on top of nixpkgs as
possible. I want to upstream as much as possible. I will still take some time to experiment here but
when I'm satisfied with how things look, I'll upstream changes.
## Funding
I was lucky to [obtain a grant][nlnet] from NlNet which is an European fund,
under [NGI Zero Core][NGI0],
to work on this project.
This also funds the contracts RFC.
Go apply for a grant too!
[nlnet]: https://nlnet.nl/project/SelfHostBlocks
[NGI0]: https://nlnet.nl/core/
<p>
<img alt="NlNet logo" src="https://nlnet.nl/logo/banner.svg" width="200" />
<img alt="NGI Zero Core logo" src="https://nlnet.nl/image/logos/NGI0Core_tag.svg" width="200" />
</p>
## License
I'm following the [Nextcloud](https://github.com/nextcloud/server) license which is AGPLv3.
See [this article](https://www.fsf.org/bulletin/2021/fall/the-fundamentals-of-the-agplv3) from the FSF that explains what this license adds to the GPL one.
================================================
FILE: VERSION
================================================
0.8.0
================================================
FILE: demo/homeassistant/README.md
================================================
# Home Assistant Demo {#demo-homeassistant}
**This whole demo is highly insecure as all the private keys are available publicly. This is
only done for convenience as it is just a demo. Do not expose the VM to the internet.**
The [`flake.nix`](./flake.nix) file sets up a Home Assistant server with Self Host Blocks. There are actually 2 demos:
- The `basic` demo sets up a lone Home Assistant server accessible through http.
- The `ldap` demo builds on top of the `basic` demo integrating Home Assistant with a LDAP provider.
<!--
They were set up by following the [manual](https://shb.skarabox.com/services-homeassistant.html).
-->
This guide will show how to deploy these demos to a Virtual Machine, like showed
[here](https://nixos.wiki/wiki/NixOS_modules#Developing_modules).
## Deploy to the VM {#demo-homeassistant-deploy}
The demos are setup to either deploy to a VM through `nixos-rebuild` or through
[Colmena](https://colmena.cli.rs).
Using `nixos-rebuild` is very fast and requires less steps because it reuses your nix store.
Using `colmena` is more authentic because you are deploying to a stock VM, like you would with a
real machine but it needs to copy over all required store derivations so it takes a few minutes the
first time.
### Deploy with nixos-rebuild {#demo-homeassistant-deploy-nixosrebuild}
Assuming your current working directory is the one where this Readme file is located, the one-liner
command which builds and starts the VM configured to run Self Host Blocks' Nextcloud is:
```nix
rm nixos.qcow2; \
nixos-rebuild build-vm --flake .#basic \
&& QEMU_NET_OPTS="hostfwd=tcp::2222-:2222,hostfwd=tcp::8080-:80" \
./result/bin/run-nixos-vm
```
This will deploy the `basic` demo. If you want to deploy the `ldap` demo, use the `.#ldap` flake
uris.
You can even test the demos from any directory without cloning this repository by using the GitHub
uri like `github:ibizaman/selfhostblocks?path=demo/nextcloud`
It is very important to remove leftover `nixos.qcow2` files, if any.
You can ssh into the VM like this, but this is not required for the demo:
```bash
ssh -F ssh_config example
```
But before that works, you will need to change the permission of the ssh key like so:
```bash
chmod 600 sshkey
```
This is only needed because git mangles with the permissions. You will not even see this change in
`git status`.
### Deploy with Colmena {#demo-homeassistant-deploy-colmena}
If you deploy with Colmena, you must first build the VM and start it:
```bash
rm nixos.qcow2; \
nixos-rebuild build-vm-with-bootloader --fast -I nixos-config=./configuration.nix -I nixpkgs=. ; \
QEMU_NET_OPTS="hostfwd=tcp::2222-:2222,hostfwd=tcp::8080-:80" ./result/bin/run-nixos-vm
```
It is very important to remove leftover `nixos.qcow2` files, if any.
This last call is blocking, so I advice adding a `&` at the end of the command otherwise you will
need to run the rest of the commands in another terminal.
With the VM started, make the secrets in `secrets.yaml` decryptable in the VM. This change will
appear in `git status` but you don't need to commit this.
```bash
SOPS_AGE_KEY_FILE=keys.txt \
nix run --impure nixpkgs#sops -- --config sops.yaml -r -i \
--add-age $(nix shell nixpkgs#ssh-to-age --command sh -c 'ssh-keyscan -p 2222 -t ed25519 -4 localhost 2>/dev/null | ssh-to-age') \
secrets.yaml
```
The nested command, the one in between the parenthesis `$(...)`, is used to print the VM's public
age key, which is then added to the `secrets.yaml` file in order to make the secrets decryptable by
the VM.
If you forget this step, the deploy will seem to go fine but the secrets won't be populated and
neither LLDAP nor Home Assistant will start.
Make the ssh key private:
```bash
chmod 600 sshkey
```
This is only needed because git mangles with the permissions. You will not even see this change in
`git status`.
You can ssh into the VM with, but this is not required for the demo:
```bash
ssh -F ssh_config example
```
### Home Assistant through HTTP {#demo-homeassistant-deploy-basic}
<!--
:::: {.note}
This section corresponds to the `basic` section of the [Home Assistant
manual](services-nextcloud.html#services-homeassistant-server-usage-basic).
::::
-->
Assuming you already deployed the `basic` demo, now you must add the following entry to the
`/etc/hosts` file on the host machine (not the VM):
```nix
networking.hosts = {
"127.0.0.1" = [ "ha.example.com" ];
};
```
Which produces:
```bash
$ cat /etc/hosts
127.0.0.1 ha.example.com
```
Go to [http://ha.example.com:8080](http://ha.example.com:8080) and you will be greeted with the Home
Assistant setup wizard which will allow you to create an admin user.
And that's the end of the demo
### Home Assistant with LDAP through HTTP {#demo-homeassistant-deploy-ldap}
<!--
:::: {.note}
This section corresponds to the `ldap` section of the [Home Assistant
manual](services-nextcloud.html#services-homeassistant-server-usage-ldap).
::::
-->
Assuming you already deployed the `ldap` demo, now you must add the following entry to the
`/etc/hosts` file on the host machine (not the VM):
```nix
networking.hosts = {
"127.0.0.1" = [ "ha.example.com" "ldap.example.com" ];
};
```
Which produces:
```bash
$ cat /etc/hosts
127.0.0.1 ha.example.com ldap.example.com
```
Go first to [http://ldap.example.com:8080](http://ldap.example.com:8080) and login with:
- username: `admin`
- password: the value of the field `lldap.user_password` in the `secrets.yaml` file which is `fccb94f0f64bddfe299c81410096499a`.
Create the group `homeassistant_user` and a user assigned to that group.
Go to [http://ha.example.com:8080](http://ha.example.com:8080) and login with the
user and password you just created above.
## In More Details {#demo-homeassistant-in-more-details}
### Files {#demo-homeassistant-files}
- [`flake.nix`](./flake.nix): nix entry point, defines one target host for
[colmena](https://colmena.cli.rs) to deploy to as well as the selfhostblocks' config for
setting up the home assistant server paired with the LDAP server.
- [`configuration.nix`](./configuration.nix): defines all configuration required for colmena
to deploy to the VM. The file has comments if you're interested.
- [`hardware-configuration.nix`](./hardware-configuration.nix): defines VM specific layout.
This was generated with nixos-generate-config on the VM.
- Secrets related files:
- [`keys.txt`](./keys.txt): your private key for sops-nix, allows you to edit the `secrets.yaml`
file. This file should never be published but here I did it for convenience, to be able to
deploy to the VM in less steps.
- [`secrets.yaml`](./secrets.yaml): encrypted file containing required secrets for Home Assistant
and the LDAP server. This file can be publicly accessible.
- [`sops.yaml`](./sops.yaml): describes how to create the `secrets.yaml` file. Can be publicly
accessible.
- SSH related files:
- [`sshkey(.pub)`](./sshkey): your private and public ssh keys. Again, the private key should usually not
be published as it is here but this makes it possible to deploy to the VM in less steps.
- [`ssh_config`](./ssh_config): the ssh config allowing you to ssh into the VM by just using the
hostname `example`. Usually you would store this info in your `~/.ssh/config` file but it's
provided here to avoid making you do that.
### Virtual Machine {#demo-homeassistant-virtual-machine}
_More info about the VM._
We use `build-vm-with-bootloader` instead of just `build-vm` as that's the only way to deploy to the VM.
The VM's User and password are both `nixos`, as setup in the [`configuration.nix`](./configuration.nix) file under
`user.users.nixos.initialPassword`.
You can login with `ssh -F ssh_config example`. You just need to accept the fingerprint.
The VM's hard drive is a file name `nixos.qcow2` in this directory. It is created when you first create the VM and re-used since. You can just remove it when you're done.
That being said, the VM uses `tmpfs` to create the writable nix store so if you stumble in a disk
space issue, you must increase the
`virtualisation.vmVariantWithBootLoader.virtualisation.memorySize` setting.
### Secrets {#demo-homeassistant-secrets}
_More info about the secrets can be found in the [Usage](https://shb.skarabox.com/usage.html) manual_
To open the `secrets.yaml` file and optionnally edit it, run:
```bash
SOPS_AGE_KEY_FILE=keys.txt nix run --impure nixpkgs#sops -- \
--config sops.yaml \
secrets.yaml
```
The `secrets.yaml` file must follow the format:
```yaml
home-assistant:
country: "US"
latitude: "0.100"
longitude: "-0.100"
time_zone: "America/Los_Angeles"
lldap:
user_password: XXX...
jwt_secret: YYY...
```
You can generate random secrets with:
```bash
$ nix run nixpkgs#openssl -- rand -hex 64
```
If you choose a password too small, some services could refuse to start.
#### Why do we need the VM's public key {#demo-homeassistant-tips-public-key-necessity}
The [`sops.yaml`](./sops.yaml) file describes what private keys can decrypt and encrypt the
[`secrets.yaml`](./secrets.yaml) file containing the application secrets. Usually, you will create and add
secrets to that file and when deploying, it will be decrypted and the secrets will be copied
in the `/run/secrets` folder on the VM. We thus need one private key for you to edit the
[`secrets.yaml`](./secrets.yaml) file and one in the VM for it to decrypt the secrets.
Your private key is already pre-generated in this repo, it's the [`sshkey`](./sshkey) file. But when
creating the VM for Colmena, a new private key and its accompanying public key were automatically
generated under `/etc/ssh/ssh_host_ed25519_key` in the VM. We just need to get the public key and
add it to the `secrets.yaml` which we did in the Deploy section.
### SSH {#demo-homeassistant-tips-ssh}
The private and public ssh keys were created with:
```bash
ssh-keygen -t ed25519 -f sshkey
```
You don't need to copy over the ssh public key over to the VM as we set the `keyFiles` option which copies the public key when the VM gets created.
This allows us also to disable ssh password authentication.
For reference, if instead you didn't copy the key over on VM creating and enabled ssh
authentication, here is what you would need to do to copy over the key:
```bash
nix shell nixpkgs#openssh --command ssh-copy-id -i sshkey -F ssh_config example
```
### Deploy {#demo-homeassistant-tips-deploy}
If you get a NAR hash mismatch error like hereunder, you need to run `nix flake lock --update-input
selfhostblocks`.
```
error: NAR hash mismatch in input ...
```
### Update Demo {#demo-homeassistant-tips-update-demo}
If you update the Self Host Blocks configuration in `flake.nix` file, you can just re-deploy.
If you update the `configuration.nix` file, you will need to rebuild the VM from scratch.
If you update a module in the Self Host Blocks repository, you will need to update the lock file with:
```bash
nix flake lock --override-input selfhostblocks ../.. --update-input selfhostblocks
```
================================================
FILE: demo/homeassistant/configuration.nix
================================================
{ config, pkgs, ... }:
let
targetUser = "nixos";
targetPort = 2222;
in
{
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
];
boot.loader.grub.enable = true;
boot.kernelModules = [ "kvm-intel" ];
system.stateVersion = "22.11";
# Options above are generate by running nixos-generate-config on the VM.
# Needed otherwise deploy will say system won't be able to boot.
boot.loader.grub.device = "/dev/vdb";
# Needed to avoid getting into not available disk space in /boot.
boot.loader.grub.configurationLimit = 1;
# The NixOS /nix/.rw-store mountpoint is backed by tmpfs which uses memory. We need to increase
# the available disk space to install home-assistant.
virtualisation.vmVariantWithBootLoader.virtualisation.memorySize = 8192;
# Options above are needed to deploy in a VM.
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
# We need to create the user we will deploy with.
users.users.${targetUser} = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
initialPassword = "nixos";
# With this option, you don't need to use ssh-copy-id to copy the public ssh key to the VM.
openssh.authorizedKeys.keyFiles = [
./sshkey.pub
];
};
# The user we're deploying with must be able to run sudo without password.
security.sudo.extraRules = [
{
users = [ targetUser ];
commands = [
{
command = "ALL";
options = [ "NOPASSWD" ];
}
];
}
];
# Needed to allow the user we're deploying with to write to the nix store.
nix.settings.trusted-users = [
targetUser
];
# We need to enable the ssh daemon to be able to deploy.
services.openssh = {
enable = true;
ports = [ targetPort ];
settings = {
PermitRootLogin = "no";
PasswordAuthentication = false;
};
};
}
================================================
FILE: demo/homeassistant/flake.nix
================================================
{
description = "Home Assistant example for Self Host Blocks";
inputs = {
selfhostblocks.url = "github:ibizaman/selfhostblocks";
sops-nix.url = "github:Mic92/sops-nix";
};
outputs =
inputs@{
self,
selfhostblocks,
sops-nix,
}:
let
system = "x86_64-linux";
nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs;
basic =
{ config, ... }:
{
imports = [
./configuration.nix
selfhostblocks.nixosModules.authelia
selfhostblocks.nixosModules.home-assistant
selfhostblocks.nixosModules.sops
selfhostblocks.nixosModules.ssl
sops-nix.nixosModules.default
];
sops.defaultSopsFile = ./secrets.yaml;
shb.home-assistant = {
enable = true;
domain = "example.com";
subdomain = "ha";
config = {
name = "SHB Home Assistant";
country.source = config.shb.sops.secret."home-assistant/country".result.path;
latitude.source = config.shb.sops.secret."home-assistant/latitude".result.path;
longitude.source = config.shb.sops.secret."home-assistant/longitude".result.path;
time_zone.source = config.shb.sops.secret."home-assistant/time_zone".result.path;
unit_system = "metric";
};
};
shb.sops.secret."home-assistant/country".request = {
mode = "0440";
owner = "hass";
group = "hass";
restartUnits = [ "home-assistant.service" ];
};
shb.sops.secret."home-assistant/latitude".request = {
mode = "0440";
owner = "hass";
group = "hass";
restartUnits = [ "home-assistant.service" ];
};
shb.sops.secret."home-assistant/longitude".request = {
mode = "0440";
owner = "hass";
group = "hass";
restartUnits = [ "home-assistant.service" ];
};
shb.sops.secret."home-assistant/time_zone".request = {
mode = "0440";
owner = "hass";
group = "hass";
restartUnits = [ "home-assistant.service" ];
};
nixpkgs.config.permittedInsecurePackages = [
"openssl-1.1.1w"
];
};
ldap =
{ config, ... }:
{
shb.lldap = {
enable = true;
domain = "example.com";
subdomain = "ldap";
ldapPort = 3890;
webUIListenPort = 17170;
dcdomain = "dc=example,dc=com";
ldapUserPassword.result = config.shb.sops.secret."lldap/user_password".result;
jwtSecret.result = config.shb.sops.secret."lldap/jwt_secret".result;
};
shb.sops.secret."lldap/user_password".request = config.shb.lldap.ldapUserPassword.request;
shb.sops.secret."lldap/jwt_secret".request = config.shb.lldap.jwtSecret.request;
shb.home-assistant.ldap = {
enable = true;
host = "127.0.0.1";
port = config.shb.lldap.webUIListenPort;
userGroup = "homeassistant_user";
};
};
sopsConfig = {
sops.age.keyFile = "/etc/sops/my_key";
environment.etc."sops/my_key".source = ./keys.txt;
};
in
{
nixosConfigurations = {
basic = nixpkgs'.nixosSystem {
system = "x86_64-linux";
modules = [
basic
sopsConfig
];
};
ldap = nixpkgs'.nixosSystem {
system = "x86_64-linux";
modules = [
basic
ldap
sopsConfig
];
};
};
colmena = {
meta = {
nixpkgs = import nixpkgs' {
system = "x86_64-linux";
};
specialArgs = inputs;
};
basic =
{ config, ... }:
{
imports = [
basic
];
# Used by colmena to know which target host to deploy to.
deployment = {
targetHost = "example";
targetUser = "nixos";
targetPort = 2222;
};
};
ldap =
{ config, ... }:
{
imports = [
basic
ldap
];
# Used by colmena to know which target host to deploy to.
deployment = {
targetHost = "example";
targetUser = "nixos";
targetPort = 2222;
};
};
};
};
}
================================================
FILE: demo/homeassistant/hardware-configuration.nix
================================================
# This file was generated by running nixos-generate-config on the VM.
#
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{
config,
lib,
pkgs,
modulesPath,
...
}:
{
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
];
boot.initrd.availableKernelModules = [
"ata_piix"
"uhci_hcd"
"virtio_pci"
"floppy"
"sr_mod"
"virtio_blk"
];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
fileSystems."/" = {
device = "/dev/vda";
fsType = "ext4";
};
fileSystems."/nix/.ro-store" = {
device = "nix-store";
fsType = "9p";
};
fileSystems."/nix/.rw-store" = {
device = "tmpfs";
fsType = "tmpfs";
};
fileSystems."/tmp/shared" = {
device = "shared";
fsType = "9p";
};
fileSystems."/tmp/xchg" = {
device = "xchg";
fsType = "9p";
};
fileSystems."/nix/store" = {
device = "overlay";
fsType = "overlay";
};
fileSystems."/boot" = {
device = "/dev/vdb2";
fsType = "vfat";
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.eth0.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
================================================
FILE: demo/homeassistant/keys.txt
================================================
# created: 2023-11-17T00:05:25-08:00
# public key: age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7
AGE-SECRET-KEY-1EPLAHXWDEM5ZZAU7NFGHT5TWU08ZUCWTHYTLD8XC89350MZ0T79SA2MQAL
================================================
FILE: demo/homeassistant/secrets.yaml
================================================
home-assistant:
country: ENC[AES256_GCM,data:2Ng=,iv:/VMB6yi3e8piAx8DzLGGhLsozxWUWX2R7NcmACFng8Q=,tag:Tx0Iy1AnLmPrnYu7XtbesA==,type:str]
latitude: ENC[AES256_GCM,data:p/O1HW4=,iv:CRgL4wcM3gMNu/OAHVoQuLcRD9J3SbkxsjvobiabQ0g=,tag:uIo5Rv7geOtVcarp4Qkqww==,type:str]
longitude: ENC[AES256_GCM,data:sVyww6F7,iv:9EZYXSkv+rhD77lqmC+c8i+wf46KPYloVoK+ok3bWYY=,tag:c+lmtcGvULtMdu9ZTDewjA==,type:str]
time_zone: ENC[AES256_GCM,data:JKXdsQZrtB1B77klxuemw1tZbg==,iv:nItJfpwp2XWmBHbohrjNMWQ8TpL2Xsv22UujZRgDscw=,tag:wrHbA1yycutUUn79F9wy6Q==,type:str]
lldap:
user_password: ENC[AES256_GCM,data:JrFraqFSqAhRVjB5fagIoB864aejt24q+qqWeu8ySC0=,iv:RS7VS+9tsSknn9SwpfyYVi41m3lN4SkZ4CSwrzH/Eso=,tag:5L7fx6/KhDtjHPruwac/sw==,type:str]
jwt_secret: ENC[AES256_GCM,data:W1T/QoxuzMD+2AL7sP5KkMcC+GvFdd4kfd70rHLnQD+jWNs9G0igkC/BxxgbIfnSASwtSnBaaiU6/pxLFOcUVh0Nyd0Zmb/KTbagpUvSl//AZnTt/WKF9Q/8sqKzsGv0QdMyZKWi4cxiEILcTbxOsgwriFGgOJ1k5N8JEif15ig=,iv:rHlRt6nWMz8rVmU0aKH6VWWVXunOfJcDvZOxgWbK1FI=,tag:qC6N61rE8CfPSXrsEqFoIQ==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBWVU9TMjJlRzNKY0hFSktD
MkFMUkg2OTZ4aFZMUUJ0UEF3OVpxWFloVWtJCmtrb2UzUDI2b0poc21Cd1A1N0xW
cnBZVVNrcllVNktpS0kzRGozbHREK1UKLS0tIHZmSUhTVkRQNGUremZXQlJOOGNB
SExYU3VXNVVjMElXdlVsc1VmOFRwYlEKQYeGc8F33qs3PzxXmbwqX+c+fZeEuPpv
n0zBA46/HdoCYyuZsW828XVftVcQqiThq/XAe0i648k7E8Slo3Y5bg==
-----END AGE ENCRYPTED FILE-----
- recipient: age1slc23ln7g0ty5re2n25w3hq0sw2eyphnshe45af55vd23fgwtuhq36hpqr
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBCNlpOL3lFMVA1L3NkQlE1
bnJIRlZ4Z1lCSWdJTzdtTW5SNXRXOTZ6UDJnCndwamZnWnA5TzdsSzZ4MjlTN09K
YVZCZkFINDRjQWh2dFVuSmswbWw1dlkKLS0tIGdMalFlc1VrOGdHU2tIZzZoak1n
VlJpS1BYd2UrZU1mZTEwU1BYODhqM2sKvQnFV8xsy1tEmYZu4izBYb7XQqTPOLTL
bRkU6n17uiyXNbiXDAbX0Png/XmVG96/+Zl38BBXPQvARX8c2tzq6w==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2024-02-12T05:07:51Z"
mac: ENC[AES256_GCM,data:MOmvK0g6Wj+fND154QUhmXujsDOKMO5CRRckru+eDRPeHcJZUnI/jjolcI8y+LEdhUVf0Ln8E38GSxZT/8EW3CfCNkOUikGFdfxuQ2uzNp/1wMvNaF988lrXMBfQ7Il18AiYVK0QhGReGXJa6wBVUb2Qfrg41WC65UvQtMOByqI=,iv:Rscvq1l7YgNapC0NkabQHBzirzsPEr8ykAQqx+qGoi0=,tag:ud+K72bnUV1hnsjcewNrsw==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.8.1
================================================
FILE: demo/homeassistant/sops.yaml
================================================
keys:
- &admin age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7
creation_rules:
- path_regex: secrets.yaml$
key_groups:
- age:
- *admin
================================================
FILE: demo/homeassistant/ssh_config
================================================
Host example
Port 2222
User nixos
HostName 127.0.0.1
IdentityFile sshkey
IdentitiesOnly yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
================================================
FILE: demo/homeassistant/sshkey
================================================
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACD7ngEdcDu4UVbe2ZzBhKn2HhPW0PlEmgEpb/kkMieFIwAAAJiBL8xSgS/M
UgAAAAtzc2gtZWQyNTUxOQAAACD7ngEdcDu4UVbe2ZzBhKn2HhPW0PlEmgEpb/kkMieFIw
AAAECzMZfgJIQJUVgyKZ3IYnEVvwnYXJ8nstc4/g1H41dC/vueAR1wO7hRVt7ZnMGEqfYe
E9bQ+USaASlv+SQyJ4UjAAAAEWV4YW1wbGVAbG9jYWxob3N0AQIDBA==
-----END OPENSSH PRIVATE KEY-----
================================================
FILE: demo/homeassistant/sshkey.pub
================================================
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPueAR1wO7hRVt7ZnMGEqfYeE9bQ+USaASlv+SQyJ4Uj example@localhost
================================================
FILE: demo/minimal/flake.nix
================================================
{
description = "Minimal example to setup SelfHostBlocks";
inputs = {
selfhostblocks.url = "github:ibizaman/selfhostblocks";
sops-nix = {
url = "github:Mic92/sops-nix";
};
};
outputs =
{
self,
selfhostblocks,
sops-nix,
}:
{
nixosConfigurations =
let
system = "x86_64-linux";
nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs;
# This module makes the assertions happy and the build succeed.
# This is of course wrong and will not work on any real system.
filesystemModule = {
fileSystems."/".device = "/dev/null";
boot.loader.grub.devices = [ "/dev/null" ];
};
in
{
# Test with:
# nix build .#nixosConfigurations.minimal.config.system.build.toplevel
minimal = nixpkgs'.nixosSystem {
inherit system;
modules = [
selfhostblocks.nixosModules.default
filesystemModule
# This modules showcases the use of SHB's lib.
(
{
config,
lib,
shb,
...
}:
{
options.myOption = lib.mkOption {
# Using provided nixosSystem directly.
# SHB's lib is available under `shb` thanks to the overlay.
type = shb.secretFileType;
};
config = {
myOption.source = "/a/path";
# Use the option.
environment.etc.myOption.text = config.myOption.source;
};
}
)
];
};
# Test with:
# nix build .#nixosConfigurations.sops.config.system.build.toplevel
# nix eval .#nixosConfigurations.sops.config.myOption
sops = nixpkgs'.nixosSystem {
inherit system;
modules = [
selfhostblocks.nixosModules.default
selfhostblocks.nixosModules.sops
sops-nix.nixosModules.default
filesystemModule
# This modules showcases the use of SHB's lib.
(
{
config,
lib,
shb,
...
}:
{
options.myOption = lib.mkOption {
# Using provided nixosSystem directly.
# SHB's lib is available under `shb` thanks to the overlay.
type = shb.secretFileType;
};
config = {
myOption.source = "/a/path";
# Use the option.
environment.etc.myOption.text = config.myOption.source;
};
}
)
];
};
# This example shows how to import the nixosSystem patches to nixpkgs manually.
#
# Test with:
# nix build .#nixosConfigurations.lowlevel.config.system.build.toplevel
# nix eval .#nixosConfigurations.lowlevel.config.myOption
lowlevel =
let
# We must import nixosSystem directly from the patched nixpkgs
# otherwise we do not get the patches.
nixosSystem' = import "${nixpkgs'}/nixos/lib/eval-config.nix";
in
nixosSystem' {
inherit system;
modules = [
selfhostblocks.nixosModules.default
filesystemModule
# This modules showcases the use of SHB's lib.
(
{
config,
lib,
shb,
...
}:
{
options.myOption = lib.mkOption {
# Using provided nixosSystem directly.
# SHB's lib is available under `shb` thanks to the overlay.
type = shb.secretFileType;
};
config = {
myOption.source = "/a/path";
# Use the option.
environment.etc.myOption.text = config.myOption.source;
};
}
)
];
};
# This example shows how to apply patches to nixpkgs manually.
#
# Test with:
# nix build .#nixosConfigurations.manual.config.system.build.toplevel
# nix eval .#nixosConfigurations.manual.config.myOption
manual =
let
pkgs = import selfhostblocks.inputs.nixpkgs {
inherit system;
};
nixpkgs' = pkgs.applyPatches {
name = "nixpkgs-patched";
src = selfhostblocks.inputs.nixpkgs;
patches = selfhostblocks.lib.${system}.patches;
};
# We must import nixosSystem directly from the patched nixpkgs
# otherwise we do not get the patches.
nixosSystem' = import "${nixpkgs'}/nixos/lib/eval-config.nix";
in
nixosSystem' {
inherit system;
modules = [
selfhostblocks.nixosModules.default
filesystemModule
# This modules showcases the use of SHB's lib.
(
{
config,
lib,
shb,
...
}:
{
options.myOption = lib.mkOption {
# Using provided nixosSystem directly.
# SHB's lib is available under `shb` thanks to the overlay.
type = shb.secretFileType;
};
config = {
myOption.source = "/a/path";
# Use the option.
environment.etc.myOption.text = config.myOption.source;
};
}
)
];
};
# Test with:
# nix build .#nixosConfigurations.contractsDirect.config.system.build.toplevel
contractsDirect =
let
nixosSystem' = import "${selfhostblocks.inputs.nixpkgs}/nixos/lib/eval-config.nix";
in
nixosSystem' {
inherit system;
modules = [
filesystemModule
(import "${selfhostblocks}/lib/module.nix")
(
{
config,
lib,
shb,
...
}:
{
options.myOption = lib.mkOption {
# Using provided nixosSystem directly.
# SHB's lib is available under `shb` thanks to the overlay.
type = shb.secretFileType;
};
config = {
myOption.source = "/a/path";
# Use the option.
environment.etc.myOption.text = config.myOption.source;
};
}
)
];
};
};
};
}
================================================
FILE: demo/nextcloud/README.md
================================================
# Nextcloud Demo {#demo-nextcloud}
**This whole demo is highly insecure as all the private keys are available publicly. This is
only done for convenience as it is just a demo. Do not expose the VM to the internet.**
The [`flake.nix`](./flake.nix) file sets up a Nextcloud server with Self Host Blocks. There are
actually 3 demos:
- The `basic` demo sets up a lone Nextcloud server accessible through http with the Preview
Generator app enabled.
- The `ldap` demo builds on top of the `basic` demo integrating Nextcloud with a LDAP provider.
- The `sso` demo builds on top of the `lsap` demo integrating Nextcloud with a SSO provider.
They were set up by following the [manual](https://shb.skarabox.com/services-nextcloud.html). This
guide will show how to deploy these demos to a Virtual Machine, like showed
[here](https://nixos.wiki/wiki/NixOS_modules#Developing_modules).
## Deploy to the VM {#demo-nextcloud-deploy}
The demos are setup to either deploy to a VM through `nixos-rebuild` or through
[Colmena](https://colmena.cli.rs).
Using `nixos-rebuild` is very fast and requires less steps because it reuses your nix store.
Using `colmena` is more authentic because you are deploying to a stock VM, like you would with a
real machine but it needs to copy over all required store derivations so it takes a few minutes the
first time.
### Deploy with nixos-rebuild {#demo-nextcloud-deploy-nixosrebuild}
Assuming your current working directory is the one where this Readme file is located, the one-liner
command which builds and starts the VM configured to run Self Host Blocks' Nextcloud is:
```nix
rm nixos.qcow2; \
nixos-rebuild build-vm --flake .#basic \
&& QEMU_NET_OPTS="hostfwd=tcp::2222-:2222,hostfwd=tcp::8080-:80" \
./result/bin/run-nixos-vm
```
This will deploy the `basic` demo. If you want to deploy the `ldap` or `sso` demos, use respectively
the `.#ldap` or `.#sso` flake uris.
You can even test the demos from any directory without cloning this repository by using the GitHub
uri like `github:ibizaman/selfhostblocks?path=demo/nextcloud`
It is very important to remove leftover `nixos.qcow2` files, if any.
You can ssh into the VM like this, but this is not required for the demo:
```bash
ssh -F ssh_config example
```
But before that works, you will need to change the permission of the ssh key like so:
```bash
chmod 600 sshkey
```
This is only needed because git mangles with the permissions. You will not even see this change in
`git status`.
### Deploy with Colmena {#demo-nextcloud-deploy-colmena}
If you deploy with Colmena, you must first build the VM and start it:
```bash
rm nixos.qcow2; \
nixos-rebuild build-vm-with-bootloader --fast -I nixos-config=./configuration.nix -I nixpkgs=. ; \
QEMU_NET_OPTS="hostfwd=tcp::2222-:2222,hostfwd=tcp::8080-:80" ./result/bin/run-nixos-vm
```
It is very important to remove leftover `nixos.qcow2` files, if any.
This last call is blocking, so I advice adding a `&` at the end of the command otherwise you will
need to run the rest of the commands in another terminal.
With the VM started, make the secrets in `secrets.yaml` decryptable in the VM. This change will
appear in `git status` but you don't need to commit this.
```bash
SOPS_AGE_KEY_FILE=keys.txt \
nix run --impure nixpkgs#sops -- --config sops.yaml -r -i \
--add-age $(nix shell nixpkgs#ssh-to-age --command sh -c 'ssh-keyscan -p 2222 -t ed25519 -4 localhost 2>/dev/null | ssh-to-age') \
secrets.yaml
```
The nested command, the one in between the parenthesis `$(...)`, is used to print the VM's public
age key, which is then added to the `secrets.yaml` file in order to make the secrets decryptable by
the VM.
If you forget this step, the deploy will seem to go fine but the secrets won't be populated and
Nextcloud will not start.
Make the ssh key private:
```bash
chmod 600 sshkey
```
This is only needed because git mangles with the permissions. You will not even see this change in
`git status`.
You can ssh into the VM like this, but this is not required for the demo:
```bash
ssh -F ssh_config example
```
### Nextcloud through HTTP {#demo-nextcloud-deploy-basic}
:::: {.note}
This section corresponds to the `basic` section of the [Nextcloud
manual](services-nextcloud.html#services-nextcloudserver-usage-basic).
::::
Assuming you already deployed the `basic` demo, now you must add the following entry to the
`/etc/hosts` file on the host machine (not the VM):
```nix
networking.hosts = {
"127.0.0.1" = [ "n.example.com" ];
};
```
Which produces:
```bash
$ cat /etc/hosts
127.0.0.1 n.example.com
```
Go to [http://n.example.com:8080](http://n.example.com:8080) and login with:
- username: `root`
- password: the value of the field `nextcloud.adminpass` in the `secrets.yaml` file which is
`43bb4b8f82fc645ce3260b5db803c5a8`.
This is the admin user of Nextcloud and that's the end of the `basic` demo.
### Nextcloud with LDAP through HTTP {#demo-nextcloud-deploy-ldap}
:::: {.note}
This section corresponds to the `ldap` section of the [Nextcloud
manual](services-nextcloud.html#services-nextcloudserver-usage-ldap).
::::
Assuming you already deployed the `ldap` demo, now you must add the following entry to the
`/etc/hosts` file on the host machine (not the VM):
```nix
networking.hosts = {
"127.0.0.1" = [ "n.example.com" "ldap.example.com" ];
};
```
Which produces:
```bash
$ cat /etc/hosts
127.0.0.1 n.example.com ldap.example.com
```
Go first to [http://ldap.example.com:8080](http://ldap.example.com:8080) and login with:
- username: `admin`
- password: the value of the field `lldap.user_password` in the `secrets.yaml` file which is
`c2e32e54ea3e0053eb30841f818a3d9a`.
Create the group `nextcloud_user` and a create a user and assign them to that group.
Finally, go to [http://n.example.com/login:8080](http://n.example.com/login:8080) and login with the user and
password you just created above.
You might need to wait a minute or two until Nextcloud initialized correctly.
Until then, you'll get a 502 Bad Gateway error.
Nextcloud doesn't like being run without SSL protection, which this demo does not setup, so you
might see errors loading scripts. See the `sso` demo for SSL.
This is the end of the `ldap` demo.
### Nextcloud with LDAP and SSO through self-signed HTTPS {#demo-nextcloud-deploy-sso}
:::: {.note}
This section corresponds to the `sso` section of the [Nextcloud
manual](services-nextcloud.html#services-nextcloudserver-usage-oidc).
::::
At this point, it is assumed you already deployed the `sso` demo. This time, we cannot simply edit local
`/etc/hosts`, because Nextcloud SSO addon must be able to connect to Authelia by domain name
(`auth.example.com`). Instead, there is a `dnsmasq` server running in the VM and you must create a
SOCKS proxy to connect to it like so:
```bash
ssh -F ssh_config -D 1080 -N example
```
This is a blocking call but it is not necessary to fork this process in the background by appending
`&` because we will not need to use the terminal for the rest of the demo.
Now, configure your browser to use that SOCKS proxy. When that's done go to
[https://ldap.example.com](https://ldap.example.com) and login with:
- username: `admin`
- password: the value of the field `lldap.user_password` in the `secrets.yaml` file which is
`c2e32e54ea3e0053eb30841f818a3d9a`.
Create the group `nextcloud_user` and a create a user and assign them to that group.
Visit [https://auth.example.com](https://auth.example.com) and make your browserauthorize the certificate.
Finally, go to [https://n.example.com](https://n.example.com) and login with the user and
password you just created above. You will see that the login page is actually the one from the SSO provider.
This is the end of the `sso` demo.
## In More Details {#demo-nextcloud-tips}
### Files {#demo-nextcloud-tips-files}
- [`flake.nix`](./flake.nix): nix entry point, defines the target hosts for
[colmena](https://colmena.cli.rs) to deploy to as well as the selfhostblocks' config for setting
up Nextcloud and the auxiliary services.
- [`configuration.nix`](./configuration.nix): defines all configuration required for colmena
to deploy to the VM. The file has comments if you're interested.
- [`hardware-configuration.nix`](./hardware-configuration.nix): defines VM specific layout.
This was generated with nixos-generate-config on the VM.
- Secrets related files:
- [`keys.txt`](./keys.txt): your private key for sops-nix, allows you to edit the `secrets.yaml`
file. This file should never be published but here I did it for convenience, to be able to
deploy to the VM in less steps.
- [`secrets.yaml`](./secrets.yaml): encrypted file containing required secrets for Nextcloud. This file can be publicly accessible.
- [`sops.yaml`](./sops.yaml): describes how to create the `secrets.yaml` file. Can be publicly
accessible.
- SSH related files:
- [`sshkey(.pub)`](./sshkey): your private and public ssh keys. Again, the private key should usually not
be published as it is here but this makes it possible to deploy to the VM in less steps.
- [`ssh_config`](./ssh_config): the ssh config allowing you to ssh into the VM by just using the
hostname `example`. Usually you would store this info in your `~/.ssh/config` file but it's
provided here to avoid making you do that.
### Virtual Machine {#demo-nextcloud-tips-virtual-machine}
_More info about the VM._
We use `build-vm-with-bootloader` instead of just `build-vm` as that's the only way to deploy to the VM.
The VM's User and password are both `nixos`, as setup in the [`configuration.nix`](./configuration.nix) file under
`user.users.nixos.initialPassword`.
You can login with `ssh -F ssh_config example`. You just need to accept the fingerprint.
The VM's hard drive is a file name `nixos.qcow2` in this directory. It is created when you first create the VM and re-used since. You can just remove it when you're done.
That being said, the VM uses `tmpfs` to create the writable nix store so if you stumble in a disk
space issue, you must increase the
`virtualisation.vmVariantWithBootLoader.virtualisation.memorySize` setting.
### Secrets {#demo-nextcloud-tips-secrets}
_More info about the secrets can be found in the [Usage](https://shb.skarabox.com/usage.html) manual_
To open the `secrets.yaml` file and optionnally edit it, run:
```bash
SOPS_AGE_KEY_FILE=keys.txt nix run --impure nixpkgs#sops -- \
--config sops.yaml \
secrets.yaml
```
You can generate random secrets with:
```bash
nix run nixpkgs#openssl -- rand -hex 64
```
If you choose secrets too small, some services could refuse to start.
#### Why do we need the VM's public key {#demo-nextcloud-tips-public-key-necessity}
The [`sops.yaml`](./sops.yaml) file describes what private keys can decrypt and encrypt the
[`secrets.yaml`](./secrets.yaml) file containing the application secrets. Usually, you will create and add
secrets to that file and when deploying, it will be decrypted and the secrets will be copied
in the `/run/secrets` folder on the VM. We thus need one private key for you to edit the
[`secrets.yaml`](./secrets.yaml) file and one in the VM for it to decrypt the secrets.
Your private key is already pre-generated in this repo, it's the [`sshkey`](./sshkey) file. But when
creating the VM for Colmena, a new private key and its accompanying public key were automatically
generated under `/etc/ssh/ssh_host_ed25519_key` in the VM. We just need to get the public key and
add it to the `secrets.yaml` which we did in the Deploy section.
### SSH {#demo-nextcloud-tips-ssh}
The private and public ssh keys were created with:
```bash
ssh-keygen -t ed25519 -f sshkey
```
You don't need to copy over the ssh public key over to the VM as we set the `keyFiles` option which copies the public key when the VM gets created.
This allows us also to disable ssh password authentication.
For reference, if instead you didn't copy the key over on VM creating and enabled ssh
authentication, here is what you would need to do to copy over the key:
```bash
$ nix shell nixpkgs#openssh --command ssh-copy-id -i sshkey -F ssh_config example
```
### Deploy {#demo-nextcloud-tips-deploy}
If you get a NAR hash mismatch error like hereunder, you need to run `nix flake lock --update-input
selfhostblocks`.
```
error: NAR hash mismatch in input ...
```
### Update Demo {#demo-nextcloud-tips-update-demo}
If you update the Self Host Blocks configuration in `flake.nix` file, you can just re-deploy.
If you update the `configuration.nix` file, you will need to rebuild the VM from scratch.
If you update a module in the Self Host Blocks repository, you will need to update the lock file with:
```bash
nix flake lock --override-input selfhostblocks ../.. --update-input selfhostblocks
```
================================================
FILE: demo/nextcloud/configuration.nix
================================================
{ config, pkgs, ... }:
let
targetUser = "nixos";
targetPort = 2222;
in
{
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
];
boot.loader.grub.enable = true;
boot.kernelModules = [ "kvm-intel" ];
system.stateVersion = "22.11";
# Options above are generate by running nixos-generate-config on the VM.
# Needed otherwise deploy will say system won't be able to boot.
boot.loader.grub.device = "/dev/vdb";
# Needed to avoid getting into not available disk space in /boot.
boot.loader.grub.configurationLimit = 1;
# The NixOS /nix/.rw-store mountpoint is backed by tmpfs which uses memory. We need to increase
# the available disk space to install home-assistant.
virtualisation.vmVariant.virtualisation.memorySize = 8192;
virtualisation.vmVariantWithBootLoader.virtualisation.memorySize = 8192;
# Options above are needed to deploy in a VM.
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
# We need to create the user we will deploy with.
users.users.${targetUser} = {
isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
initialPassword = "nixos";
# With this option, you don't need to use ssh-copy-id to copy the public ssh key to the VM.
openssh.authorizedKeys.keyFiles = [
./sshkey.pub
];
};
# The user we're deploying with must be able to run sudo without password.
security.sudo.extraRules = [
{
users = [ targetUser ];
commands = [
{
command = "ALL";
options = [ "NOPASSWD" ];
}
];
}
];
# Needed to allow the user we're deploying with to write to the nix store.
nix.settings.trusted-users = [
targetUser
];
# We need to enable the ssh daemon to be able to deploy.
services.openssh = {
enable = true;
ports = [ targetPort ];
settings = {
PermitRootLogin = "no";
PasswordAuthentication = false;
};
};
}
================================================
FILE: demo/nextcloud/flake.nix
================================================
{
description = "Nextcloud example for Self Host Blocks";
inputs = {
selfhostblocks.url = "github:ibizaman/selfhostblocks";
sops-nix.url = "github:Mic92/sops-nix";
};
outputs =
inputs@{
self,
selfhostblocks,
sops-nix,
}:
let
system = "x86_64-linux";
nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs;
basic =
{ config, ... }:
{
imports = [
./configuration.nix
selfhostblocks.nixosModules.authelia
selfhostblocks.nixosModules.nextcloud-server
selfhostblocks.nixosModules.nginx
selfhostblocks.nixosModules.sops
selfhostblocks.nixosModules.ssl
sops-nix.nixosModules.default
];
sops.defaultSopsFile = ./secrets.yaml;
shb.nextcloud = {
enable = true;
domain = "example.com";
subdomain = "n";
dataDir = "/var/lib/nextcloud";
tracing = null;
defaultPhoneRegion = "US";
# This option is only needed because we do not access Nextcloud at the default port in the VM.
port = 8080;
adminPass.result = config.shb.sops.secret."nextcloud/adminpass".result;
apps = {
previewgenerator.enable = true;
};
};
shb.sops.secret."nextcloud/adminpass".request = config.shb.nextcloud.adminPass.request;
# Set to true for more debug info with `journalctl -f -u nginx`.
shb.nginx.accessLog = true;
shb.nginx.debugLog = false;
};
ldap =
{ config, ... }:
{
shb.lldap = {
enable = true;
domain = "example.com";
subdomain = "ldap";
ldapPort = 3890;
webUIListenPort = 17170;
dcdomain = "dc=example,dc=com";
ldapUserPassword.result = config.shb.sops.secret."lldap/user_password".result;
jwtSecret.result = config.shb.sops.secret."lldap/jwt_secret".result;
};
shb.sops.secret."lldap/user_password".request = config.shb.lldap.ldapUserPassword.request;
shb.sops.secret."lldap/jwt_secret".request = config.shb.lldap.jwtSecret.request;
shb.nextcloud.apps.ldap = {
enable = true;
host = "127.0.0.1";
port = config.shb.lldap.ldapPort;
dcdomain = config.shb.lldap.dcdomain;
adminName = "admin";
adminPassword.result = config.shb.sops.secret."nextcloud/ldap_admin_password".result;
userGroup = "nextcloud_user";
};
shb.sops.secret."nextcloud/ldap_admin_password" = {
request = config.shb.nextcloud.apps.ldap.adminPassword.request;
settings.key = "lldap/user_password";
};
};
sso =
{ config, lib, ... }:
{
shb.certs = {
cas.selfsigned.myca = {
name = "My CA";
};
certs.selfsigned = {
n = {
ca = config.shb.certs.cas.selfsigned.myca;
domain = "*.example.com";
group = "nginx";
};
};
};
shb.nextcloud = {
port = lib.mkForce null;
ssl = config.shb.certs.certs.selfsigned.n;
};
shb.lldap.ssl = config.shb.certs.certs.selfsigned.n;
services.dnsmasq = {
enable = true;
settings = {
domain-needed = true;
# no-resolv = true;
bogus-priv = true;
address = map (hostname: "/${hostname}/127.0.0.1") [
"example.com"
"n.example.com"
"ldap.example.com"
"auth.example.com"
];
};
};
shb.authelia = {
enable = true;
domain = "example.com";
subdomain = "auth";
ssl = config.shb.certs.certs.selfsigned.n;
ldapPort = config.shb.lldap.ldapPort;
ldapHostname = "127.0.0.1";
dcdomain = config.shb.lldap.dcdomain;
secrets = {
jwtSecret.result = config.shb.sops.secret."authelia/jwt_secret".result;
ldapAdminPassword.result = config.shb.sops.secret."authelia/ldap_admin_password".result;
sessionSecret.result = config.shb.sops.secret."authelia/session_secret".result;
storageEncryptionKey.result = config.shb.sops.secret."authelia/storage_encryption_key".result;
identityProvidersOIDCHMACSecret.result = config.shb.sops.secret."authelia/hmac_secret".result;
identityProvidersOIDCIssuerPrivateKey.result = config.shb.sops.secret."authelia/private_key".result;
};
};
shb.sops.secret."authelia/jwt_secret".request = config.shb.authelia.secrets.jwtSecret.request;
shb.sops.secret."authelia/ldap_admin_password" = {
request = config.shb.authelia.secrets.ldapAdminPassword.request;
settings.key = "lldap/user_password";
};
shb.sops.secret."authelia/session_secret".request =
config.shb.authelia.secrets.sessionSecret.request;
shb.sops.secret."authelia/storage_encryption_key".request =
config.shb.authelia.secrets.storageEncryptionKey.request;
shb.sops.secret."authelia/hmac_secret".request =
config.shb.authelia.secrets.identityProvidersOIDCHMACSecret.request;
shb.sops.secret."authelia/private_key".request =
config.shb.authelia.secrets.identityProvidersOIDCIssuerPrivateKey.request;
shb.nextcloud.apps.sso = {
enable = true;
endpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
clientID = "nextcloud";
fallbackDefaultAuth = true;
secret.result = config.shb.sops.secret."nextcloud/sso/secret".result;
secretForAuthelia.result = config.shb.sops.secret."authelia/nextcloud_sso_secret".result;
};
shb.sops.secret."nextcloud/sso/secret".request = config.shb.nextcloud.apps.sso.secret.request;
shb.sops.secret."authelia/nextcloud_sso_secret" = {
request = config.shb.nextcloud.apps.sso.secretForAuthelia.request;
settings.key = "nextcloud/sso/secret";
};
};
sopsConfig = {
sops.age.keyFile = "/etc/sops/my_key";
environment.etc."sops/my_key".source = ./keys.txt;
};
in
{
nixosConfigurations = {
basic = nixpkgs'.nixosSystem {
system = "x86_64-linux";
modules = [
sopsConfig
basic
];
};
ldap = nixpkgs'.nixosSystem {
system = "x86_64-linux";
modules = [
sopsConfig
basic
ldap
];
};
sso = nixpkgs'.nixosSystem {
system = "x86_64-linux";
modules = [
sopsConfig
basic
ldap
sso
];
};
};
colmena = {
meta = {
nixpkgs = import nixpkgs' {
system = "x86_64-linux";
};
specialArgs = inputs;
};
basic =
{ config, ... }:
{
imports = [
basic
];
deployment = {
targetHost = "example";
targetUser = "nixos";
targetPort = 2222;
};
};
ldap =
{ config, ... }:
{
imports = [
basic
ldap
];
deployment = {
targetHost = "example";
targetUser = "nixos";
targetPort = 2222;
};
};
sso =
{ config, ... }:
{
imports = [
basic
ldap
sso
];
deployment = {
targetHost = "example";
targetUser = "nixos";
targetPort = 2222;
};
};
};
};
}
================================================
FILE: demo/nextcloud/hardware-configuration.nix
================================================
# This file was generated by running nixos-generate-config on the VM.
#
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{
config,
lib,
pkgs,
modulesPath,
...
}:
{
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
];
boot.initrd.availableKernelModules = [
"ata_piix"
"uhci_hcd"
"virtio_pci"
"floppy"
"sr_mod"
"virtio_blk"
];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
fileSystems."/" = {
device = "/dev/vda";
fsType = "ext4";
};
fileSystems."/nix/.ro-store" = {
device = "nix-store";
fsType = "9p";
};
fileSystems."/nix/.rw-store" = {
device = "tmpfs";
fsType = "tmpfs";
};
fileSystems."/tmp/shared" = {
device = "shared";
fsType = "9p";
};
fileSystems."/tmp/xchg" = {
device = "xchg";
fsType = "9p";
};
fileSystems."/nix/store" = {
device = "overlay";
fsType = "overlay";
};
fileSystems."/boot" = {
device = "/dev/vdb2";
fsType = "vfat";
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.eth0.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
================================================
FILE: demo/nextcloud/keys.txt
================================================
# created: 2023-11-17T00:05:25-08:00
# public key: age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7
AGE-SECRET-KEY-1EPLAHXWDEM5ZZAU7NFGHT5TWU08ZUCWTHYTLD8XC89350MZ0T79SA2MQAL
================================================
FILE: demo/nextcloud/secrets.yaml
================================================
nextcloud:
adminpass: ENC[AES256_GCM,data:nD/4oml7mXbWF0axiqWQCZujFqeJMF0P/1vY9f4EPqg=,iv:KoxmL9tLPBoIJT7rxkEhxrQqZFicbEm8qXbZMrnHSGY=,tag:gwvrHsX22ygfUcOlxeC/5g==,type:str]
onlyoffice:
jwt_secret: ENC[AES256_GCM,data:v4BScbfRHpHAZ0MCIyb1H1vYISsR1JQRaI1mFHbZKDNhuf5Zyc6znzz+DtqXOZfVNgp9aIeWIEam0GI/O3ih0jzEN0ut/jqI3onoSghq22h2VTKdLMcT6JG2p/R1mHgD+C7KeeepcdWMbwLXswi2jBys3FyxTY3mfiNv3AcndGA=,iv:TFs+fTlMGWKTVJ3pUmXCpGskQ2h6uSLr+TlmG6OXQYg=,tag:Ixm0VtO5ySCQxiKweDop0A==,type:str]
sso:
secret: ENC[AES256_GCM,data:9uZfvBXETbP47Cf6lZNLqskqmbxcAaQ/e3jiHqW9VweqrmByyadaE3DgCcODUJNEatuFxIyP+ptBdeX9FBRPmAvVl/BaK5oKzp84i+5zb1nvxvxBx+KQhqFKZgk81jJQeMSxwLlDKguWnLx83QhYvOMphZNQOeLQ/Cx+qrvCWsk=,iv:pF87avRdm2tgwA+cQnvcYSUIxAh18jDrMA6eAHoyBZU=,tag:FaJwUr2fR9dZUdDOfq/C5Q==,type:str]
lldap:
user_password: ENC[AES256_GCM,data:4ImmaC2T1hj6L8tzrxv4d7/I4F9xEA/uuc56QOqkY08=,iv:SljGhXi3SYoMNcR9onwqthOAyFX1D8KsegmWRypbblQ=,tag:Aw+juIV2AM0J+89itNDjVA==,type:str]
jwt_secret: ENC[AES256_GCM,data:btABIOGRgioXmPe8QirhyozQzhVaAcF2sbB07hevz+Q=,iv:vBOq4Mab3RE69rOA8ZbMX72Gm3KEng6HaCveZrXsIrU=,tag:zkbJ+SeNnzQyAZxOjso8fg==,type:str]
authelia:
jwt_secret: ENC[AES256_GCM,data:xom/W92DGS2RafO+olwG8oKAbKPbkPKyZ2mYv0lWqtVAWUFwSoCGLgxe4uHAoGcLosJmDxU/srq+HNPzYORY8+mHn9wMoQgYg2oceLw2xamYdkIzvswof6LoYAV7MaZReYgYXcqMy2LZuU3PnnE4wag3liSuEx4qtJrLKB52ljE=,iv:t5PsBdZDze3/4S8utfnkmiToaorqq5BiJn99JuRirXY=,tag:ZJCszIOpaSwl9Sua8VWHoA==,type:str]
storage_encryption_key: ENC[AES256_GCM,data:wUmF+0etuhEr3FNy7x0LBJunn1vmWO+IExm/wgkh0CEDWzxblpylC/PGAGgHdlJMQOhUY6tDPD67sJgO2g+yTBB3lfOo/kql0gnGVKQjRMMHqfEEmXK56yXP+J2JePJ6DlaqzdAXko4Tmh4GnRKsswMQZVA5PDOuHHNRcVTCb0E=,iv:wz1Mry7jMwGvD9mF1/PbQsHb/jmm8WOWchLL95YADeY=,tag:AZp43iti+nxW0TYK7MlYNg==,type:str]
session_secret: ENC[AES256_GCM,data:TSe2YEyXl0Ls8wAynUYRJBQL8mbC1i/31ueuCj7d7ouO9gCX/Igz6OM9EgWigxucsMVQkiUtDCI9DD9B8jFaYGMIiB9FrKQnixigptrIUj210zJ3Aer38GyFxSI541PaBzmnauEo1MtBykjSg93xyI6ivB8FJmmauQOMYNiTYvk=,iv:OBtUCw7BevaF3VQKLJ2HiB828IzJqS27SZUOoAqoD+E=,tag:WfCGlHi6a15AYeSFXnnOVw==,type:str]
hmac_secret: ENC[AES256_GCM,data:RmPr/kJmimMmeZCluMBsYL+w5VtJ1IZNFo2VOVNGiu0ajMJoK06RQx9AAYb+GvPRrGz9wzRy38hTH7unIiq59WOZCw245StsawSCeszadh8RrjPJPNCKPt3vaBbIzlvz0xMvgX4UT2k+uK1dqR7QXiCrBDludU3nnHIpbgkcADM=,iv:z5KLaAlevgk2HsxMWggU1DL0g+Ae+DaBLZ0SnZoKYcA=,tag:2ChIOxMCI4psqIhX+GE8EQ==,type:str]
private_key: ENC[AES256_GCM,data:ogK8+ecyRhd1OrhpmjtXUK2Lyhg/D9FJwTwC2HtlmViLrAx5ovKGcZOrHQ2JFhCvRTj2n54+Me2JpOS70v0ugLTOVbZtw1eYJr7rNohhu8nBITuDYOkEVHZ7Q6xZ5Toabm2/y6yr2zJuj9N8NPCPv5uf6h3/DzBITvUkF9l79ypAgs5yP8JZYvpkG2aMv6bkRp5+9H9nNywrDdggwdEF0kRl+KS0gd4SpDLJzJ00W+hpPRd0qYukCJaKCKs/76vklN47Xk9UVnwYZP4dxh0unYJdffuBYSJXrAEP/bxOdyszZ2v0vr7HYOY7/+o/S1ZOmVqlv+1EVWpluDytuwnfpNdxY7I2HJjvM7Ua5zs8KmGKz/er0wFjWeakP7l+YKs+vi8IEG6sJJiakuI8n4neZmQrHf9MG5ynYKhA55+gaaiJYg29CTHxWpYsDyEQhoDxHeyxGhe7zQ8SeEVyADtfkHYB6hGJrds0wAJaZ9cqyKpmvqsogh0ipUBmt62ytAl0KMEZ7IgRHIq6P+q+sFXvgUyehh85+Ud13F+gQvMkITN2r6c+BS1/u8gMv9jHi/3mvLtA3nBB86w06QRFrG6fHkn1UBGjjQ5TvPlVmJBTM8pDVb3VFlsX2xRHS7lCX4AAy4JXEXJFWUSWN1zZ/3caE3ishgMnJbptGw5JS5/DQsu0s+CtUKjv8Xup0eiZ/12+0AzRTjihRAysCprnuqUvlb6OP4vDP5PNbDCAZLF/LYfGhIiOGTph8hC5Hmxql3mDmW0CN6VfdtpBgPfPp1SMEYTh07gBxxNqGVViAjOTF31NWuektF9vKtmFEeX1CqY512KtvW5Q9zIs/MBrSeONPZYrr01xEEFeqet8T/kqaiTGpI3fFHwiDmfKajlcFj9xPlhzvMbQV3eFBdC0FdxssTrWP3cEs03vexA+bLEM4E0aSagTpd0TWFeZd4AjG8GsjF80c7P/CSScg3yYYHFI3V6ljRY72oKh9361UnmdU3Y1PGcjmw2nVkVlywRAK+P6F4tRqhmKrYzNxw+AHGEgCG347pYPeRKj12acyX8lmuFa7ULCFoHng+DJITR26HrHDhzzg7/EDIc8c7orfvWS5qYlPIsfwSMBrwfm91eGgcgnEhrLE4krpgSZcrQTXOhC4cinzxqK+GhoERfFzRMNzxjVaEFCO0yQuLnydwJWdBMCV4gEUNmCwWGDNaBYqKLPdyK753LEylb/MAOmqX/YBp7rhLNt/5P6kSacZzIvqLYt9zbITrrF13nDLmP3ZOhIbGRVG1F3r2ReIW+PnmHxHnSrOV4tMel0ql2nlcLIh41WHiKCaeIiQ0zPQOBXJbXis2pCuJ0Mut68abe0bicFpEDrQ5CgIjTWOzbxFq+tVvmX2amTGRW51048mPuod0ZofYPzI9l6YwO7eO02mEYCUhcgPFZaIBnEF9cZHWtBGturXi/A6LNh/6bnFnozy4SdaUrmlK2o4uaBPr/av4zjSFOQaZ6+NQOysmdLUzupq6ysbsOZIS7cUngr5v7otxxvR/qYtC4SNOkSaU53LsfSuxvu3/5nOMAr+O9ez/N+BJV5GHbABJ6l2TkeWjbDL/RcCE0nXHkwLH1YEGBmt93KTagjCOt/n+GN0/F/7jQtxhNjI84CRHzYAdzqSXP78J1vcqctPWhQBrWfNioQkjLwy5+ndDT1Uu7yVTMPD3teQq7sjQ4g6hfHqmjWWSewxnopxkJyz/ZnwQqTXig1QXwTVcIUI/IiNp9a4D/kI5eEUbbjbXD7nScaoIb5b7oE9eK6/qmRmKv8m4ySKiFN5kNwME/y2a17K2w5HwCOi8cqPKT7LHegLoYQvJ9DrIFLHQZpKjYfKQAxTcDyFitJvSxbcD2iM2eZMXuNKcbyHOHwZr2sC4BicF+0InfsOZE8R1+v4/98elbisnV1rSO38/1vxQZzV8x5JHbZpMegD/cdxxC3fsgwsoyBt3wynrt1S8xqqIxuwbEX8uN2J8qR1YYK7Qn1mDhlyl8dTvI7W65HLpF5HWC1Hn+nDB/arjL9jEeMWVimxkMIpGt69337uyugfJsu54uiIm70zpzsh+otYDvvZUrvG/KoDejP40ZbmtsLknbpmzr1ezgrxYV9W4NJcjZtZ4x64pXKvSrbYt+yMorXujmVFg0og/TxnkJ3kJdB6a3sg4bymPnJiAAl9ya3DYHHPQrHXQa2LnV02ps6Y6jq0LdKy3cu7DxOYtmpI6KRz0k1fRVBNBnSX7aUEsZ8aZ9XYTB1FuvT,iv:WYnE50BRK5Q7TA/24LDDkSq+wu9+S6ckb3+NR/eHkUs=,tag:X9s50TdOPEjDV+7Kv6prOQ==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBqRjg2SWR0SjhpWExqbi9E
a3pJbXJyMmMyY1F5NFNVNWY0TXRicFdycEhJCkdWL1dmNjdCRVhKNmllcGpmNkNV
U1lTUjI3elBoOStNZVhoL1o3WGZLWjgKLS0tIE1XRTVPUE91d2k2dFpMbVJ1a0ZB
dTNrOUhzOSsvRnNSMC9VOTJaY1orWUEK8IcLk/4X7O+ZRosM7KNQNSEgyGkFklRw
YSutsre5OOEUx1X+hxzu2GF9I4DGcSAbQtzPYBq7qcwxUR+oIXiJyQ==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2025-03-17T00:29:32Z"
mac: ENC[AES256_GCM,data:eE3F1K/brgKMnixJQo/A/VYjafNLAGKuSq1n8857yjsiNnro/hwDy9jNKLH3a6/5DX/aOjMfZJzgH3ycb7f4771IohrWoDLjymaVdgJXsTITXZaLQyN+QHoOTRbXAJwG1f4Mr2kEAdwK7JLtu9TqX82o2DmBWNRxkkn1Kv5NjiA=,iv:OSAI0b4H40xbzKQbD6F2B5Xu/8enUIclfds8uYH/q3o=,tag:fYTnxx8IQYMyXAeVTUiQ+A==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.9.2
================================================
FILE: demo/nextcloud/sops.yaml
================================================
keys:
- &admin age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7
creation_rules:
- path_regex: secrets.yaml$
key_groups:
- age:
- *admin
================================================
FILE: demo/nextcloud/ssh_config
================================================
Host example
Port 2222
User nixos
HostName 127.0.0.1
IdentityFile sshkey
IdentitiesOnly yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
================================================
FILE: demo/nextcloud/sshkey
================================================
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACD7ngEdcDu4UVbe2ZzBhKn2HhPW0PlEmgEpb/kkMieFIwAAAJiBL8xSgS/M
UgAAAAtzc2gtZWQyNTUxOQAAACD7ngEdcDu4UVbe2ZzBhKn2HhPW0PlEmgEpb/kkMieFIw
AAAECzMZfgJIQJUVgyKZ3IYnEVvwnYXJ8nstc4/g1H41dC/vueAR1wO7hRVt7ZnMGEqfYe
E9bQ+USaASlv+SQyJ4UjAAAAEWV4YW1wbGVAbG9jYWxob3N0AQIDBA==
-----END OPENSSH PRIVATE KEY-----
================================================
FILE: demo/nextcloud/sshkey.pub
================================================
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPueAR1wO7hRVt7ZnMGEqfYeE9bQ+USaASlv+SQyJ4Uj example@localhost
================================================
FILE: docs/blocks.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# Blocks {#blocks}
Blocks help you self-host apps or services. They implement a specific function like backup or secure
access through a subdomain. Each block is designed to be usable on its own and to fit nicely with
others.
All blocks are implemented under the blocks folder [in the repository](@REPO@/modules/blocks).
All services in SHB document how to setup the various blocks provided here.
For custom services or those not provided by SHB,
the [Expose a service Recipe](recipes-exposeService.html) explains how to use the blocks here.
## Authentication {#blocks-category-authentication}
```{=include=} chapters html:into-file=//blocks-authelia.html
modules/blocks/authelia/docs/default.md
```
```{=include=} chapters html:into-file=//blocks-lldap.html
modules/blocks/lldap/docs/default.md
```
## Backup {#blocks-category-backup}
```{=include=} chapters html:into-file=//blocks-borgbackup.html
modules/blocks/borgbackup/docs/default.md
```
```{=include=} chapters html:into-file=//blocks-restic.html
modules/blocks/restic/docs/default.md
```
## Database {#blocks-category-database}
```{=include=} chapters html:into-file=//blocks-postgresql.html
modules/blocks/postgresql/docs/default.md
```
## Secrets {#blocks-category-secrets}
```{=include=} chapters html:into-file=//blocks-sops.html
modules/blocks/sops/docs/default.md
```
## Network {#blocks-category-network}
```{=include=} chapters html:into-file=//blocks-ssl.html
modules/blocks/ssl/docs/default.md
```
```{=include=} chapters html:into-file=//blocks-nginx.html
modules/blocks/nginx/docs/default.md
```
## Introspection {#blocks-category-introspection}
```{=include=} chapters html:into-file=//blocks-monitoring.html
modules/blocks/monitoring/docs/default.md
```
```{=include=} chapters html:into-file=//blocks-mitmdump.html
modules/blocks/mitmdump/docs/default.md
```
================================================
FILE: docs/contracts.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# Contracts {#contracts}
::: {.note}
An [RFC][] has been created which is the most up-to-date version of contracts.
The text here is still relevant although the implementation itself has changed a little bit.
[RFC]: https://github.com/NixOS/rfcs/pull/189
:::
A contract decouples modules that use a functionality from modules that provide it. A first
intuition for contracts is they are generally related to accessing a shared resource.
A few examples of contracts are generating SSL certificates, creating a user or knowing which files
and folders to backup.
Indeed, when generating certificates, the service using those do not care how they were created.
They just need to know where the certificate files are located.
A contract is made between a `requester` module and a `provider` module.
For example, a `backup` contract can be made between the [Nextcloud service][] and the [Restic service][].
The former is the `requester` - the one wanted to be backed up -
and the latter is the `provider` of the contract - the one backing up files.
The `backup contract` would then say which set of options the `requester` and `provider` modules
must use to talk to each other.
[Nextcloud service]: ./services-nextcloud.html
[Restic service]: ./blocks-restic.html
## Provided contracts {#contracts-provided}
Self Host Blocks is a proving ground of contracts. This repository adds a layer on top of services
available in nixpkgs to make them work using contracts. In time, we hope to upstream as much of this
as possible, reducing the quite thick layer that it is now.
Provided contracts are:
- [SSL generator contract](contracts-ssl.html) to generate SSL certificates.
Two providers are implemented: self-signed and Let's Encrypt.
- [Backup contract][] to backup directories.
Two providers are implemented: [BorgBackup][] and [Restic][].
- [Database Backup contract](contracts-databasebackup.html) to backup database dumps.
One provider is implemented: [BorgBackup][] and [Restic][].
- [Contract for Secrets](contracts-secret.html) to provide secrets that are deployed outside of the Nix store.
One provider is implemented: [SOPS][].
- [Dashboard contract](contracts-dashboard.html) to show services in a nice user-facing dashboard.
One provider is implemented: [Homepage][].
[backup contract]: contracts-backup.html
[borgbackup]: blocks-borgbackup.html
[homepage]: services-homepage.html
[restic]: blocks-restic.html
[sops]: blocks-sops.html
```{=include=} chapters html:into-file=//contracts-ssl.html
modules/contracts/ssl/docs/default.md
```
```{=include=} chapters html:into-file=//contracts-backup.html
modules/contracts/backup/docs/default.md
```
```{=include=} chapters html:into-file=//contracts-databasebackup.html
modules/contracts/databasebackup/docs/default.md
```
```{=include=} chapters html:into-file=//contracts-secret.html
modules/contracts/secret/docs/default.md
```
```{=include=} chapters html:into-file=//contracts-dashboard.html
modules/contracts/dashboard/docs/default.md
```
## Problem Statement {#contracts-why}
Currently in nixpkgs, every module accessing a shared resource
must either implement the logic needed to setup that resource themselves
or either instruct the user how to set it up themselves.
For example, this is what the Nextcloud module looks like.
It sets up the `nginx module` and a database,
letting you choose between multiple databases.

This has a few disadvantages:
_I'm using the Nextcloud module to make the following examples more concrete
but this applies to all other modules._
- This leads to a lot of **duplicated code**.
If the Nextcloud module wants to support a new type of database,
the maintainer of the Nextcloud module must do the work.
And if another module wants to support it too,
the maintainers of that module cannot re-use easily the work
of the Nextcloud maintainer,
apart from copy-pasting and adapting the code.
- This also leads to **tight coupling**.
The code written to integrate Nextcloud with the Nginx reverse proxy
is hard to decouple and make generic.
Letting the user choose between Nginx and another reverse proxy
will require a lot of work.
- There is also a **lack of separation of concerns**.
The maintainers of a service must be experts
in all implementations they let the users choose from.
- This is **not extendable**.
If you, the user of the module, want to use another
implementation that is not supported, you are out of luck.
You can always dive into the module's code and extend it with a lot of `mkForce`,
but that is not an optimal experience.
- Finally, there is **no interoperability**.
It is not currently possible to integrate the Nextcloud module
with an existing database or reverse proxy or other type of shared resource
that already exists on a non-NixOS machine.
We do believe that the decoupling contracts provides helps alleviate all the issues outlined above
which makes it an essential step towards better interoperability.

Indeed, contracts allow:
- **Reuse of code**.
Since the implementation of a contract lives outside of modules using it,
using the same implementation and code elsewhere without copy-pasting is trivial.
- **Loose coupling**.
Modules that use a contract do not care how they are implemented
as long as the implementation follows the behavior outlined by the contract.
- Full **separation of concerns** (see diagram below).
Now, each party's concern is separated with a clear boundary.
The maintainer of a module using a contract can be different from the maintainers
of the implementation, allowing them to be experts in their own respective fields.
But more importantly, the contracts themselves can be created and maintained by the community.
- Full **extensibility**.
The final user themselves can choose an implementation,
even new custom implementations not available in nixpkgs, without changing existing code.
- **Incremental adoption**.
Contracts can help bridge a NixOS system with any non-NixOS one.
For that, one can hardcode a requester or provider module to match
how the non-NixOS system is configured.
The responsibility falls of course on the user to make sure both system agree on the configuration.
- Last but not least, **Testability**.
Thanks to NixOS VM test, we can even go one step further
by ensuring each implementation of a contract, even custom ones,
provides required options and behaves as the contract requires
thanks to generic NixOS tests.
For an example, see the [generic backup contract test][generic backup test]
and the [instantiated NixOS tests][instantiated backup test]
ensuring the providers do implement the contract correctly.

## Concept {#contracts-concept}
Conceptually, a contract is an attrset of options with a defined behavior.
Let's take a reduced `secret` contract as example.
This contract allows a `requester` module to ask for a secret
and a `provider` module to generate that secret outside of the nix store
and provide it back to the `requester`.
In this case, the options for the contract could look like so:
_The full secret contract can be found [here][secret contract]._
[secret contract]: ./contracts-secret.html
```nix
{ lib, ... }:
let
inherit (lib) mkOption;
inherit (lib.types) submodule str;
in
{
# Filled out by the requester module.
request = mkOption {
type = submodule {
options = {
owner = mkOption {
description = "Linux user owning the secret file.";
type = str;
};
};
};
};
# Filled out by the provider module.
result = mkOption {
type = submodule {
options = {
path = mkOption {
description = "Linux user owning the secret file.";
type = str;
};
};
};
};
# Options specific for each provider.
settings = mkOption {
type = submodule {
options = {
encryptedFile = mkOption {
description = "Encrypted file containing the secret.";
type = path;
};
};
};
};
}
```
Unfortunately, the contract needs to be more complicated to handle several constraints.
1. First, to fill out the contract,
the `requester` must set the defaults for the `request.*` options
and the `provider` for the `result.*` options.
Since one cannot do that after calling the `mkOption` function,
the `request` and `result` attributes must be functions
taking in the defaults as arguments.
2. Another constraint is a `provider` module of a contract
will need to work for several `requester` modules.
This means that the option to provide the contract will be an
`attrsOf` of something, not just plainly the contract.
Think of a provider for the secret contract,
if it didn't use `attrsOf`, one could only create an unique secret
for all the modules, which is not useful.
3. Also, one usually want the defaults
for the contract to be computed from some other option.
For a `provider` module, the options in the `result` could be computed
from the `name` provided in the `attrsOf`
or from a value given in the `request` or `setting` attrset.
For example, a `provider` module for the `secret` contract would want
something like the following in pseudo code:
```nix
services.provier = {
secret = mkOption {
type = attrsOf (submodule ({ name, ... }: {
result = {
path = mkOption {
type = str;
default = "/run/secrets/${name}";
};
};
}))
};
};
```
Another example is for a `provider` module for the `backup` contract
which would want the name of the restore script to depend on the path
to the repository it is backing up to.
This is necessary to differentiate which source to restore from
in case one wants to backup a same `requester` service
to multiple different repositories.
One could be local and another remote, for example.
```nix
services.provider = {
backup = mkOption {
type = attrsOf (submodule ({ name, config, ... }: {
settings = {
};
result = {
restoreScript = {
type = str;
default = "provider-restore-${name}-${config.settings.repository.path}";
};
};
}));
};
};
```
4. Finally, the last constraint, which is also the more demanding,
is we want to generate the documentation
for the options with `nixos-generate-config`.
For that, the complicated `default` we give to options
that depend on other options break the documentation generation.
So instead of using only `default`,
we must also define `defaultText` attributes.
This means the actual `mkRequest` and `mkResult` functions
must take twice as many arguments as there are option.
One for the `default` and the other for the `defaultText`.
This will not be shown in the following snippets as it is
already complicated enough.
These are all the justifications to why the final contract structure
is as presented in the next section.
It makes it harder to write, but much easier to use,
which is nice property.
## Schema {#contracts-schema}
A contract for a version of the [backup contract][] with less options
would look like so:
```nix
{ lib, ... }:
let
inherit (lib) mkOption;
inherit (lib.types) submodule str;
in
{
mkRequest =
{ owner ? "root",
}: mkOption {
default = {
inherit owner;
};
type = submodule {
options = {
owner = mkOption {
description = "Linux user owning the secret file.";
type = str;
default = owner;
};
};
};
};
mkResult =
{ path ? "/run/secrets/secret",
}: mkOption {
type = submodule {
options = {
path = mkOption {
description = "Linux user owning the secret file.";
type = str;
default = path;
};
};
};
};
}
```
Assuming the `services.requester` module needs to receive a password from the user
and wants to use the `secret contract` for that,
it would then setup the option like so:
```nix
{ pkgs, lib, ... }:
let
inherit (lib) mkOption;
inherit (lib.types) submodule;
contracts = pkgs.callPackage ./modules/contracts {};
mkRequester = requestCfg: {
request = contracts.secret.mkRequest requestCfg;
result = contracts.secret.mkResult {};
};
in
{
options.services.requester = {
password = mkOption {
description = "Password for the service.";
type = submodule {
options = mkRequester {
owner = "requester";
};
};
};
};
config = {
// Use config.services.requester.password.result.path
};
}
```
A provider that can create multiple secrets would have an `attrsOf` option
and use the contract in it like so:
```nix
let
inherit (lib) mkOption;
inherit (lib.types) attrsOf submodule;
contracts = pkgs.callPackage ./modules/contracts {};
mkProvider =
module:
{ resultCfg,
settings ? {},
}: {
request = contracts.secret.mkRequest {};
result = contracts.secret.mkResult resultCfg;
} // optionalAttrs (settings != {}) { inherit settings; };
in
{
options.services.provider = {
secrets = mkOption {
type = attrsOf (submodule ({ name, options, ... }: {
options = mkProvider {
resultCfg = {
path = "/run/secrets/${name}";
};
settings = mkOption {
description = "Settings specific to the Sops provider.";
type = attrsOf (submodule {
options = {
repository = mkOption {
};
};
});
default = {};
};
};
}));
};
};
}
```
The `mkRequester` and `mkProvider` are provided by Self Host Blocks
as they are generic, so the actual syntax is a little bit different.
They were copied here that way so the snippets were self-contained.
To see a full contract in action, the secret contract is a good example.
It is composed of:
- [the contract][secret contract ref],
- [the mkRequester and mkProvider][contract lib] functions,
- [a requester][],
- [a provider][].
[secret contract ref]: ./contracts-secret.html#contract-secret-options
[contract lib]: @REPO@/modules/contracts/default.nix
[a requester]: ./blocks-sops.html#blocks-sops-options-shb.sops.secret
[a provider]: ./services-nextcloud.html#services-nextcloudserver-options-shb.nextcloud.adminPass
## Contract Tests {#contracts-test}
To make sure all providers module of a contract have the same behavior,
generic NixOS VM tests exist per contract.
They are generic because they work on any module,
as long as the module implements the contract of course.
A simplified test for a secret contract would look like the following.
First, there is the generic test:
```nix
{ pkgs, lib, shb, ... }:
let
inherit (lib) getAttrFromPath setAttrByPath;
in
{ name,
configRoot,
settingsCfg,
modules ? [],
owner ? "root",
content ? "secretPasswordA",
}: shb.test.runNixOSTest {
inherit name;
nodes.machine = { config, ... }: {
imports = modules;
config = setAttrByPath configRoot {
secretA = {
request = {
inherit owner;
};
settings = settingsCfg content;
};
};
};
testScript = { nodes, ... }:
let
result = (getAttrFromPath configRoot nodes.machine)."A".result;
in
''
owner = machine.succeed("stat -c '%U' ${result.path}").strip()
if owner != "${owner}":
raise Exception(f"Owner should be '${owner}' but got '{owner}'")
content = machine.succeed("cat ${result.path}").strip()
if content != "${content}":
raise Exception(f"Content should be '${content}' but got '{content}'")
'';
}
```
This test is generic because it sets the `request` on an option
whose path is not yet known.
It achieves this by calling `setAttrByPath configRoot` where `configRoot`
is a path to a module, for example `[ "services" "provider" ]` for a module
whose root option is under `services.provider`.
This test validates multiple aspects of the contract:
- The provider must understand the options of the `request`.
Here `request.owner`.
- The provider correctly provides the expected result.
Here the location of the secret in the `result.path` option.
- The provider must behave as expected.
Here, the secret located at `result.path` must have the correct `owner`
and the correct `content`.
Instantiating the test for a given provider looks like so:
```nix
{
hardcoded_root = contracts.test.secret {
name = "hardcoded_root";
modules = [ ./modules/blocks/hardcodedsecret.nix ];
configRoot = [ "shb" "hardcodedsecret" ];
settingsCfg = secret: {
content = secret;
};
};
hardcoded_user = contracts.test.secret {
name = "hardcoded_user";
owner = "user";
modules = [ ./modules/blocks/hardcodedsecret.nix ];
configRoot = [ "shb" "hardcodedsecret" ];
settingsCfg = secret: {
content = secret;
};
};
}
```
Validating a new provider is then just a matter of extending the above snippet.
To see a full contract test in action, the test for backup contract is a good example.
It is composed of:
- the [generic test][generic backup test]
- and [instantiated tests][instantiated backup test] for some providers.
[generic backup test]: @REPO@/modules/contracts/backup/test.nix
[instantiated backup test]: @REPO@/test/contracts/backup.nix
## Videos {#contracts-videos}
Two videos exist of me presenting the topic,
the first at [NixCon North America in spring of 2024][NixConNA2024]
and the second at [NixCon in Berlin in fall of 2024][NixConBerlin2024].
[NixConNA2024]: https://www.youtube.com/watch?v=lw7PgphB9qM
[NixConBerlin2024]: https://www.youtube.com/watch?v=CP0hR6w1csc
## Are there contracts in nixpkgs already? {#contracts-nixpkgs}
Actually not quite, but close. There are some ubiquitous options in nixpkgs. Those I found are:
- `services.<name>.enable`
- `services.<name>.package`
- `services.<name>.openFirewall`
- `services.<name>.user`
- `services.<name>.group`
What makes those nearly contracts are:
- Pretty much every service provides them.
- Users of a service expects them to exist and expects a consistent type and behavior from them.
Indeed, everyone knows what happens if you set `enable = true`.
- Maintainers of a service knows that users expects those options. They also know what behavior the
user expects when setting those options.
- The name of the options is the same everywhere.
The only thing missing to make these explicit contracts is, well, the contracts themselves.
Currently, they are conventions and not contracts.
================================================
FILE: docs/contributing.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# Contributing {#contributing}
All issues and Pull Requests are welcome!
- Use this project. Something does not make sense? Something's not working?
- Documentation. Something is not clear?
- New services. Have one of your preferred service not integrated yet?
- Better patterns. See something weird in the code?
For PRs, if they are substantial changes, please open an issue to
discuss the details first. More details in [the contributing section](https://shb.skarabox.com/contributing.html)
of the manual.
Issues that are being worked on are labeled with the [in progress][] label.
Before starting work on those, you might want to talk about it in the issue tracker
or in the [matrix][] channel.
The prioritized issues are those belonging to the [next milestone][milestone].
Those issues are not set in stone and I'd be very happy to solve
an issue an user has before scratching my own itch.
[in progress]: https://github.com/ibizaman/selfhostblocks/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22in%20progress%22
[matrix]: https://matrix.to/#/%23selfhostblocks%3Amatrix.org
[milestone]: https://github.com/ibizaman/selfhostblocks/milestones
first.
## Chat Support {#contributing-chat}
Come hang out in the [Matrix channel](https://matrix.to/#/%23selfhostblocks%3Amatrix.org). :)
## Upstream Changes {#contributing-upstream}
One important goal of SHB is to be the smallest amount of code above what is available in
[nixpkgs](https://github.com/NixOS/nixpkgs). It should be the minimum necessary to make packages
available there conform with the contracts. This way, there are less chance of breakage when nixpkgs
gets updated. I intend to upstream to nixpkgs as much of those as makes sense.
## Run tests {#contributing-runtests}
Run all tests:
```bash
$ nix flake check
# or
$ nix run github:Mic92/nix-fast-build -- --skip-cached --flake ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem)"
```
Run one group of tests:
```bash
$ nix build .#checks.${system}.modules
$ nix build .#checks.${system}.vm_postgresql_peerAuth
```
### Playwright Tests {#contributing-playwright-tests}
If the test includes playwright tests, you can see the playwright trace with:
```bash
$ nix run .#playwright -- show-trace $(nix eval .#checks.x86_64-linux.vm_grocy_basic --raw)/trace/0.zip
```
### Debug Tests {#contributing-debug-tests}
Run the test in driver interactive mode:
```bash
$ nix run .#checks.${system}.vm_postgresql_peerAuth.driverInteractive
```
When you get to the shell, start the server and/or client with one of the following commands:
```bash
server.start()
client.start()
start_all()
```
To run the test from the shell, use `test_script()`.
Note that if the test script ends in error,
the shell will exit and you will need to restart the VMs.
After the shell started, you will see lines like so:
```
SSH backdoor enabled, the machines can be accessed like this:
Note: this requires systemd-ssh-proxy(1) to be enabled (default on NixOS 25.05 and newer).
client: ssh -o User=root vsock/3
server: ssh -o User=root vsock/4
```
With the following command, you can directly access the server's nginx instance with your browser at `http://localhost:8000`:
```bash
ssh-keygen -R vsock/4; ssh -o User=root -L 8000:localhost:80 vsock/4
```
## Upload test results to CI {#contributing-upload}
Github actions do now have hardware acceleration, so running them there is not slow anymore. If
needed, the tests results can still be pushed to cachix so they can be reused in CI.
After running the `nix-fast-build` command from the previous section, run:
```bash
$ find . -type l -name "result-vm_*" | xargs readlink | nix run nixpkgs#cachix -- push selfhostblocks
```
## Upload package to CI {#contributing-upload-package}
In the rare case where a package must be built but cannot in CI,
for example because of not enough memory,
you can push the package directly to the cache with:
```bash
nix build .#checks.x86_64-linux.vm_karakeep_backup.nodes.server.services.karakeep.package
readlink result | nix run nixpkgs#cachix -- push selfhostblocks
```
## Deploy using colmena {#contributing-deploy-colmena}
```bash
$ nix run nixpkgs#colmena -- apply
```
## Use a local version of selfhostblocks {#contributing-localversion}
This works with any flake input you have. Either, change the `.url` field directly in you `flake.nix`:
```nix
selfhostblocks.url = "/home/me/projects/selfhostblocks";
```
Or override on the command line:
```bash
$ nix flake lock --override-input selfhostblocks ../selfhostblocks
```
I usually combine the override snippet above with deploying:
```bash
$ nix flake lock --override-input selfhostblocks ../selfhostblocks && nix run nixpkgs#colmena -- apply
```
## Diff changes {#contributing-diff}
First, you must know what to compare. You need to know the path to the nix store of what is already deployed and to what you will deploy.
### What is deployed {#contributing-diff-deployed}
To know what is deployed, either just stash the changes you made and run `build`:
```bash
$ nix run nixpkgs#colmena -- build
...
Built "/nix/store/yyw9rgn8v5jrn4657vwpg01ydq0hazgx-nixos-system-baryum-23.11pre-git"
```
Or ask the target machine:
```bash
$ nix run nixpkgs#colmena -- exec -v readlink -f /run/current-system
baryum | /nix/store/77n1hwhgmr9z0x3gs8z2g6cfx8gkr4nm-nixos-system-baryum-23.11pre-git
```
### What will get deployed {#contributing-diff-todeploy}
Assuming you made some changes, then instead of deploying with `apply`, just `build`:
```bash
$ nix run nixpkgs#colmena -- build
...
Built "/nix/store/16n1klx5cxkjpqhrdf0k12npx3vn5042-nixos-system-baryum-23.11pre-git"
```
### Get the full diff {#contributing-diff-full}
With `nix-diff`:
```
$ nix run nixpkgs#nix-diff -- \
/nix/store/yyw9rgn8v5jrn4657vwpg01ydq0hazgx-nixos-system-baryum-23.11pre-git \
/nix/store/16n1klx5cxkjpqhrdf0k12npx3vn5042-nixos-system-baryum-23.11pre-git \
--color always | less
```
### Get version bumps {#contributing-diff-version}
A nice summary of version changes can be produced with:
```bash
$ nix run nixpkgs#nvd -- diff \
/nix/store/yyw9rgn8v5jrn4657vwpg01ydq0hazgx-nixos-system-baryum-23.11pre-git \
/nix/store/16n1klx5cxkjpqhrdf0k12npx3vn5042-nixos-system-baryum-23.11pre-git \
```
## Generate random secret {#contributing-gensecret}
```bash
$ nix run nixpkgs#openssl -- rand -hex 64
```
## Write code {#contributing-code}
```{=include=} chapters html:into-file=//service-implementation-guide.html
service-implementation-guide.md
```
## Links that helped {#contributing-links}
While creating NixOS tests:
- https://www.haskellforall.com/2020/11/how-to-use-nixos-for-lightweight.html
- https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests
While creating an XML config generator for Radarr:
- https://stackoverflow.com/questions/4906977/how-can-i-access-environment-variables-in-python
- https://stackoverflow.com/questions/7771011/how-can-i-parse-read-and-use-json-in-python
- https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/writers/scripts.nix
- https://stackoverflow.com/questions/43837691/how-to-package-a-single-python-script-with-nix
- https://ryantm.github.io/nixpkgs/languages-frameworks/python/#python
- https://ryantm.github.io/nixpkgs/hooks/python/#setup-hook-python
- https://ryantm.github.io/nixpkgs/builders/trivial-builders/
- https://discourse.nixos.org/t/basic-flake-run-existing-python-bash-script/19886
- https://docs.python.org/3/tutorial/inputoutput.html
- https://pypi.org/project/json2xml/
- https://www.geeksforgeeks.org/serialize-python-dictionary-to-xml/
- https://nixos.org/manual/nix/stable/language/builtins.html#builtins-toXML
- https://github.com/NixOS/nixpkgs/blob/master/pkgs/pkgs-lib/formats.nix
================================================
FILE: docs/default.nix
================================================
# Taken nearly verbatim from https://github.com/nix-community/home-manager/pull/4673
# Read these docs online at https://shb.skarabox.com.
{
pkgs,
buildPackages,
lib,
nmdsrc,
stdenv,
documentation-highlighter,
nixos-render-docs,
release,
allModules,
version ? builtins.readFile ../VERSION,
substituteVersionIn,
modules,
}:
let
shbPath = toString ./..;
gitHubDeclaration =
user: repo: subpath:
let
urlRef = "main";
end = if subpath == "" then "" else "/" + subpath;
in
{
url = "https://github.com/${user}/${repo}/blob/${urlRef}${end}";
name = "<${repo}${end}>";
};
ghRoot = (gitHubDeclaration "ibizaman" "selfhostblocks" "").url;
buildOptionsDocs =
{
modules,
filterOptionPath ? null,
}:
args:
let
config = {
_module.check = false;
_module.args = { };
system.stateVersion = "22.11";
};
utils = import "${pkgs.path}/nixos/lib/utils.nix" {
inherit config lib;
pkgs = null;
};
eval = lib.evalModules {
inherit modules;
specialArgs = {
inherit utils;
};
};
options = lib.setAttrByPath filterOptionPath (lib.getAttrFromPath filterOptionPath eval.options);
in
buildPackages.nixosOptionsDoc (
{
inherit options;
transformOptions =
opt:
opt
// {
# Clean up declaration sites to not refer to the Home Manager
# source tree.
declarations = map (
decl:
gitHubDeclaration "ibizaman" "selfhostblocks" (
lib.removePrefix "/" (lib.removePrefix shbPath (toString decl))
)
) opt.declarations;
};
}
// builtins.removeAttrs args [ "includeModuleSystemOptions" ]
);
scrubbedModule = {
_module.args.pkgs = lib.mkForce (nmd.scrubDerivations "pkgs" pkgs);
_module.check = false;
};
allOptionsDocs =
paths:
(buildOptionsDocs
{
modules = paths ++ allModules ++ [ scrubbedModule ];
filterOptionPath = [ "shb" ];
}
{
variablelistId = "selfhostblocks-options";
}
).optionsJSON;
individualModuleOptionsDocs =
filterOptionPath: paths:
(buildOptionsDocs
{
modules = paths ++ [ scrubbedModule ];
inherit filterOptionPath;
}
{
variablelistId = "selfhostblocks-options";
}
).optionsJSON;
nmd = import nmdsrc {
inherit lib;
# The DocBook output of `nixos-render-docs` doesn't have the change
# `nmd` uses to work around the broken stylesheets in
# `docbook-xsl-ns`, so we restore the patched version here.
pkgs = pkgs // {
docbook-xsl-ns = pkgs.docbook-xsl-ns.override { withManOptDedupPatch = true; };
};
};
outputPath = "share/doc/selfhostblocks";
manpage-urls = pkgs.writeText "manpage-urls.json" "{}";
in
stdenv.mkDerivation {
name = "self-host-blocks-manual";
nativeBuildInputs = [ nixos-render-docs ];
# We include the parent so we get the documentation inside the root
# modules/ and demo/ folders.
src = ./..;
buildPhase = ''
cd docs
mkdir -p demo
cp -t . -r ../demo
cp -t . -r ../modules
mkdir -p out/media
mkdir -p out/highlightjs
mkdir -p out/static
cp -t out/highlightjs \
${documentation-highlighter}/highlight.pack.js \
${documentation-highlighter}/LICENSE \
${documentation-highlighter}/mono-blue.css \
${documentation-highlighter}/loader.js
cp -t out/static \
${nmdsrc}/static/style.css \
${nmdsrc}/static/highlightjs/tomorrow-night.min.css \
${nmdsrc}/static/highlightjs/highlight.min.js \
${nmdsrc}/static/highlightjs/highlight.load.js
''
+ lib.concatStringsSep "\n" (
map (m: ''
substituteInPlace ${m} --replace '@VERSION@' ${version}
'') substituteVersionIn
)
+ ''
substituteInPlace ./options.md \
--replace \
'@OPTIONS_JSON@' \
${
allOptionsDocs [
(pkgs.path + "/nixos/modules/services/misc/forgejo.nix")
]
}/share/doc/nixos/options.json
''
+ lib.concatStringsSep "\n" (
lib.mapAttrsToList (
name: cfg':
let
cfg = if builtins.isAttrs cfg' then cfg' else { module = cfg'; };
module = if builtins.isList cfg.module then cfg.module else [ cfg.module ];
optionRoot =
cfg.optionRoot or [
"shb"
(lib.last (lib.splitString "/" name))
];
in
''
substituteInPlace ./modules/${name}/docs/default.md \
--replace-fail \
'@OPTIONS_JSON@' \
${individualModuleOptionsDocs optionRoot module}/share/doc/nixos/options.json
''
) modules
)
+ ''
find . -name "*.md" -print0 | \
while IFS= read -r -d ''' f; do
substituteInPlace "''${f}" \
--replace-quiet \
'@REPO@' \
"${ghRoot}" 2>/dev/null
done
nixos-render-docs manual html \
--manpage-urls ${manpage-urls} \
--redirects ./redirects.json \
--media-dir media \
--revision ${lib.trivial.revisionWithDefault release} \
--stylesheet static/style.css \
--stylesheet static/tomorrow-night.min.css \
--script static/highlight.min.js \
--script static/highlight.load.js \
--toc-depth 1 \
--section-toc-depth 1 \
manual.md \
out/index.html
'';
installPhase = ''
dest="$out/${outputPath}"
mkdir -p "$(dirname "$dest")"
mv out "$dest"
mkdir -p $out/nix-support/
echo "doc manual $dest index.html" >> $out/nix-support/hydra-build-products
'';
}
================================================
FILE: docs/demos.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# Demos {#demos}
These demos are showcasing what Self Host Blocks can do. They deploy a block or a service on a VM on
your local machine with minimal manual steps.
```{=include=} chapters html:into-file=//demo-homeassistant.html
demo/homeassistant/README.md
```
```{=include=} chapters html:into-file=//demo-nextcloud.html
demo/nextcloud/README.md
```
================================================
FILE: docs/generate-redirects-nixos-render-docs.py
================================================
#!/usr/bin/env python3
"""
Generate redirects.json by scanning actual HTML files produced by nixos-render-docs.
This script implements a runtime patching mechanism to automatically generate a
complete redirects.json file by scanning generated HTML files for real anchor
locations, eliminating manual maintenance and ensuring accuracy.
ARCHITECTURE OVERVIEW:
The script works by monkey-patching nixos-render-docs at runtime to:
1. Disable redirect validation during HTML generation
2. Generate HTML documentation normally
3. Scan all generated HTML files to extract anchor IDs and their file locations
4. Apply filtering logic to exclude system-generated anchors
5. Generate and write redirects.json with accurate mappings
KEY COMPONENTS:
- Runtime patching: Modifies nixos-render-docs behavior without source changes
- HTML scanning: Extracts anchor IDs using regex pattern matching
- Filtering: Excludes NixOS options (opt-*) and extra options (selfhostblock*)
- Output generation: Creates both debug information and production redirects.json
IMPORTANT NOTES:
- Uses atexit handler to ensure output is generated even if process is interrupted
- Patches are applied on module import, making this a side-effect import
- Error handling preserves original validation behavior in case of failure
"""
import sys
import json
import atexit
import os
import re
# Global storage for anchor-to-file mappings discovered during HTML scanning
# Structure: {anchor_id: html_filename}
file_target_mapping = {}
def scan_html_files(output_dir, html_files):
"""
Scan HTML files to extract anchor IDs and build anchor-to-file mappings.
Discovers all HTML files in output_dir and extracts id attributes to populate
the global file_target_mapping. Filters out NixOS system options during scanning.
Args:
output_dir: Directory containing generated HTML files
html_files: Unused parameter (always discovers files from filesystem)
"""
# Always discover HTML files from the output directory
if not os.path.exists(output_dir):
print(f"DEBUG: Output directory {output_dir} does not exist", file=sys.stderr)
return
html_files = [f for f in os.listdir(output_dir) if f.endswith('.html')]
print(f"DEBUG: Discovered {len(html_files)} HTML files in {output_dir}", file=sys.stderr)
# Process each HTML file to extract anchor IDs
for html_file in html_files:
html_path = os.path.join(output_dir, html_file)
try:
with open(html_path, 'r', encoding='utf-8') as f:
html_content = f.read()
# Extract all id attributes using regex pattern matching
# Matches: id="anchor-name" and captures anchor-name
anchor_matches = re.findall(r'id="([^"]+)"', html_content)
# Filter and record anchor mappings
non_opt_count = 0
for anchor_id in anchor_matches:
# Skip NixOS system option anchors (opt-* prefix)
if not anchor_id.startswith('opt-'):
file_target_mapping[anchor_id] = html_file
non_opt_count += 1
if non_opt_count > 0:
print(f"Found {non_opt_count} anchors in {html_file}", file=sys.stderr)
except Exception as e:
# Log errors but continue processing other files
print(f"Failed to scan {html_path}: {e}", file=sys.stderr)
def output_collected_refs():
"""
Generate and write the final redirects.json file from collected anchor mappings.
This function is registered as an atexit handler to ensure output is generated
even if the process is interrupted. It processes the global file_target_mapping
to create the final redirects file with appropriate filtering.
Output files:
- out/redirects.json: Production redirects mapping
"""
import os
# Generate redirects from discovered HTML anchor mappings
if file_target_mapping:
print(f"Creating redirects from {len(file_target_mapping)} HTML mappings", file=sys.stderr)
redirects = {}
filtered_count = 0
# Apply filtering logic to exclude system-generated anchors
for anchor_id, html_file in file_target_mapping.items():
# Filter out:
# - opt-*: NixOS system options
# - selfhostblock*: Extra options from this project
if not anchor_id.startswith('opt-') and not anchor_id.startswith('selfhostblock'):
redirects[anchor_id] = [f"{html_file}#{anchor_id}"]
else:
filtered_count += 1
print(f"Generated {len(redirects)} redirects (filtered out {filtered_count} system options)", file=sys.stderr)
else:
# Fallback case - should not occur during normal operation
print("Warning: No HTML mappings available", file=sys.stderr)
redirects = {}
# Ensure output directory exists
os.makedirs('out', exist_ok=True)
# Write production redirects file
try:
redirects_file = 'out/redirects.json'
with open(redirects_file, 'w') as f:
json.dump(redirects, f, indent=2, sort_keys=True)
print(f"Generated redirects.json with {len(redirects)} redirects", file=sys.stderr)
except Exception as e:
print(f"Failed to write redirects.json: {e}", file=sys.stderr)
# Register output generation to run on process exit
atexit.register(output_collected_refs)
def apply_patches():
"""
Apply runtime monkey patches to nixos-render-docs modules.
This function modifies the behavior of nixos-render-docs by:
1. Hooking into the HTML generation CLI command
2. Temporarily disabling redirect validation during HTML generation
3. Scanning generated HTML files to extract anchor mappings
4. Restoring original validation behavior
The patching approach allows us to extract anchor information without
modifying the nixos-render-docs source code directly.
Raises:
ImportError: If nixos-render-docs modules cannot be imported
"""
try:
# Import required nixos-render-docs modules
import nixos_render_docs.html as html_module
import nixos_render_docs.redirects as redirects_module
import nixos_render_docs.manual as manual_module
# Store reference to original HTML CLI function
original_run_cli_html = manual_module._run_cli_html
def patched_run_cli_html(args):
"""
Patched version of _run_cli_html that disables validation and scans output.
This wrapper function:
1. Temporarily disables redirect validation to prevent errors
2. Runs normal HTML generation
3. Scans generated HTML files for anchor mappings
4. Restores original validation behavior
"""
print("Generating HTML documentation...", file=sys.stderr)
# Temporarily disable redirect validation
original_validate = redirects_module.Redirects.validate
redirects_module.Redirects.validate = lambda self, targets: None
try:
# Run original HTML generation
result = original_run_cli_html(args)
# Determine output directory from CLI arguments
if hasattr(args, 'outfile') and args.outfile:
output_dir = os.path.dirname(args.outfile)
else:
output_dir = '.'
# Scan generated HTML files for anchor mappings
scan_html_files(output_dir, None)
print(f"Scanned {len(file_target_mapping)} anchor mappings", file=sys.stderr)
finally:
# Always restore original validation function
redirects_module.Redirects.validate = original_validate
return result
# Replace the original function with our patched version
manual_module._run_cli_html = patched_run_cli_html
print("Applied patches to nixos-render-docs", file=sys.stderr)
except ImportError as e:
print(f"Failed to apply patches: {e}", file=sys.stderr)
# Apply patches immediately when this module is imported
# This ensures the patches are active before nixos-render-docs CLI runs
apply_patches()
================================================
FILE: docs/manual.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# Self Host Blocks Manual {#self-host-blocks-manual}
## Version @VERSION@
```{=include=} preface
preface.md
```
```{=include=} chapters html:into-file=//usage.html
usage.md
```
```{=include=} chapters html:into-file=//services.html
services.md
```
```{=include=} chapters html:into-file=//contracts.html
contracts.md
```
```{=include=} chapters html:into-file=//blocks.html
blocks.md
```
```{=include=} chapters html:into-file=//recipes.html
recipes.md
```
```{=include=} chapters html:into-file=//demos.html
demos.md
```
```{=include=} chapters html:into-file=//contributing.html
contributing.md
```
```{=include=} appendix html:into-file=//options.html
options.md
```
================================================
FILE: docs/options.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# All Options {#all-options}
```{=include=} options
id-prefix: opt-
list-id: selfhostblocks-options
source: @OPTIONS_JSON@
```
================================================
FILE: docs/preface.md
================================================
<!-- Read these docs at https://shb.skarabox.com -->
# Preface {#preface}
::: {.note}
Self Host Blocks is hosted on [GitHub](https://github.com/ibizaman/selfhostblocks).
If you encounter problems or bugs then please report them on the [issue
tracker](https://github.com/ibizaman/selfhostblocks/issues).
Feel free to join the dedicated Matrix room
[matrix.org#selfhostblocks](https://matrix.to/#/#selfhostblocks:matrix.org).
:::
SelfHostBlocks is:
- Your escape from the cloud, for privacy and data sovereignty enthusiast. [Why?](#preface-why-self-hosting)
- A groupware to self-host [all your data](#preface-services): documents, pictures, calendars, contacts, etc.
- An opinionated NixOS server management OS for a [safe self-hosting experience](#preface-features).
- A NixOS distribution making sure all services build and work correctly thanks to NixOS VM tests.
- A collection of NixOS modules standardizing options so configuring services [look the same](#preface-unified-interfaces).
- A testing ground for [contracts](#preface-contracts) which intents to make nixpkgs modules more modular.
- [Upstreaming][] as much as possible.
[upstreaming]: https://github.com/pulls?page=1&q=created%3A%3E2023-06-01+is%3Apr+author%3Aibizaman+archived%3Afalse+-repo%3Aibizaman%2Fselfhostblocks+-repo%3Aibizaman%2Fskarabox
## Why Self-Hosting {#preface-why-self-hosting}
It is obvious by now that
a deep dependency on proprietary service providers - "the cloud" -
is a significant liability.
One aspect often talked about is privacy
which is inherently not guaranteed when using a proprietary service
and is a valid concern.
A more punishing issue is having your account closed or locked
without prior warning
When that happens,
you get an instantaneous sinking feeling in your stomach
at the realization you lost access to your data,
possibly without recourse.
Hosting services yourself is the obvious alternative
to alleviate those concerns
but it tends to require a lot of technical skills and time.
SelfHostBlocks (together with its sibling project [Skarabox][])
aims to lower the bar to self-hosting,
and provides an opinionated server management system based on NixOS modules
embedding best practices.
Contrary to other server management projects,
its main focus is ease of long term maintenance
before ease of installation.
To achieve this, it provides building blocks to setup services.
Some are already provided out of the box,
and customizing or adding additional ones is done easily.
The building blocks fit nicely together thanks to [contracts](#contracts)
which SelfHostBlocks sets out to introduce into nixpkgs.
This will increase modularity, code reuse
and empower end users to assemble components
that fit together to build their server.
## Usage {#preface-usage}
> **Caution:** You should know that although I am using everything in this repo for my personal
> production server, this is really just a one person effort for now and there are most certainly
> bugs that I didn't discover yet.
To get started using SelfHostBlocks, the following snippet is enough:
```nix
{
inputs.selfhostblocks.url = "github:ibizaman/selfhostblocks";
outputs = { selfhostblocks, ... }: let
system = "x86_64-linux";
nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs;
in
nixosConfigurations = {
myserver = nixpkgs'.nixosSystem {
inherit system;
modules = [
selfhostblocks.nixosModules.default
./configuration.nix
];
};
};
}
```
SelfHostBlocks provides its own patched nixpkgs, so you are required to use it
otherwise evaluation can quickly break.
[The usage section](https://shb.skarabox.com/usage.html) of the manual has
more details and goes over how to deploy with [Colmena][], [nixos-rebuild][] and [deploy-rs][]
and also how to handle secrets management with [SOPS][].
[Colmena]: https://shb.skarabox.com/usage.html#usage-example-colmena
[nixos-rebuild]: https://shb.skarabox.com/usage.html#usage-example-nixosrebuild
[deploy-rs]: https://shb.skarabox.com/usage.html#usage-example-deployrs
[SOPS]: https://shb.skarabox.com/usage.html#usage-secrets
Then, to actually configure services, you can choose which one interests you in
the [services section](https://shb.skarabox.com/services.html) of the manual.
The [recipes section](https://shb.skarabox.com/recipes.html) of the manual shows some other common use cases.
Head over to the [matrix channel](https://matrix.to/#/#selfhostblocks:matrix.org)
for any remaining question, or just to say hi :)
### Installation From Scratch {#preface-usage-installation-from-scratch}
I do recommend for this my sibling project [Skarabox][]
which bootstraps a new server and sets up a few tools:
- Create a bootable ISO, installable on an USB key.
- Handles one or two (in raid 1) SSDs for root partition.
- Handles two (in raid 1) or more hard drives for data partition.
- [nixos-anywhere](https://github.com/nix-community/nixos-anywhere) to install NixOS headlessly.
- [disko](https://github.com/nix-community/disko) to format the drives using native ZFS encryption with remote unlocking through ssh.
- [sops-nix](https://github.com/Mic92/sops-nix) to handle secrets.
- [deploy-rs](https://github.com/serokell/deploy-rs) to deploy updates.
[Skarabox]: https://github.com/ibizaman/skarabox
## Features {#preface-features}
SelfHostBlocks provides building blocks that take care of common self-hosting needs:
- Backup for all services.
- Automatic creation of ZFS datasets per service.
- LDAP and SSO integration for most services.
- Monitoring with Grafana and Prometheus stack with provided dashboards.
- Automatic reverse proxy and certificate management for HTTPS.
- VPN and proxy tunneling services.
Great care is taken to make the proposed stack robust.
This translates into a test suite comprised of automated NixOS VM tests
which includes playwright tests to verify some important workflow
like logging in.
This test suite also serves as a guaranty that all services provided by SelfHostBlocks
all evaluate, build and work correctly together. It works similarly as a distribution but here it's all [automated](#preface-updates).
Also, the stack fits together nicely thanks to [contracts](#preface-contracts).
### Services {#preface-services}
[Provided services](https://shb.skarabox.com/services.html) are:
- Nextcloud
- Audiobookshelf
- Deluge + *arr stack
- Forgejo
- Grocy
- Hledger
- Home-Assistant
- Jellyfin
- Karakeep
- Open WebUI
- Pinchflat
- Vaultwarden
Like explained above, those services all benefit from
out of the box backup,
LDAP and SSO integration,
monitoring with Grafana,
reverse proxy and certificate management
and VPN integration for the *arr suite.
Some services do not have an entry yet in the manual.
To know options for those, the only way for now
is to go to the [All Options][] section of the manual.
[All Options]: http
gitextract_ff0ttxqq/
├── .github/
│ ├── dependabot.yml
│ └── workflows/
│ ├── auto-merge.yaml
│ ├── build.yaml
│ ├── demo.yml
│ ├── format.yaml
│ ├── lock-update.yaml
│ ├── pages.yml
│ └── version.yaml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── VERSION
├── demo/
│ ├── homeassistant/
│ │ ├── README.md
│ │ ├── configuration.nix
│ │ ├── flake.nix
│ │ ├── hardware-configuration.nix
│ │ ├── keys.txt
│ │ ├── secrets.yaml
│ │ ├── sops.yaml
│ │ ├── ssh_config
│ │ ├── sshkey
│ │ └── sshkey.pub
│ ├── minimal/
│ │ └── flake.nix
│ └── nextcloud/
│ ├── README.md
│ ├── configuration.nix
│ ├── flake.nix
│ ├── hardware-configuration.nix
│ ├── keys.txt
│ ├── secrets.yaml
│ ├── sops.yaml
│ ├── ssh_config
│ ├── sshkey
│ └── sshkey.pub
├── docs/
│ ├── blocks.md
│ ├── contracts.md
│ ├── contributing.md
│ ├── default.nix
│ ├── demos.md
│ ├── generate-redirects-nixos-render-docs.py
│ ├── manual.md
│ ├── options.md
│ ├── preface.md
│ ├── recipes/
│ │ ├── dnsServer.md
│ │ ├── exposeService.md
│ │ └── serveStaticPages.md
│ ├── recipes.md
│ ├── redirects.json
│ ├── service-implementation-guide.md
│ ├── services.md
│ └── usage.md
├── flake.nix
├── lib/
│ ├── default.nix
│ ├── homepage.nix
│ └── module.nix
├── modules/
│ ├── blocks/
│ │ ├── authelia/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── authelia.nix
│ │ ├── backup/
│ │ │ └── dashboard/
│ │ │ └── Backups.json
│ │ ├── borgbackup/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── borgbackup.nix
│ │ ├── davfs.nix
│ │ ├── hardcodedsecret.nix
│ │ ├── lldap/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── lldap.nix
│ │ ├── mitmdump/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── mitmdump.nix
│ │ ├── monitoring/
│ │ │ ├── dashboards/
│ │ │ │ ├── Errors.json
│ │ │ │ ├── Health.json
│ │ │ │ ├── Performance.json
│ │ │ │ └── Scraping_Jobs.json
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── rules.json
│ │ ├── monitoring.nix
│ │ ├── nginx/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── nginx.nix
│ │ ├── postgresql/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── postgresql.nix
│ │ ├── restic/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── dummyModule.nix
│ │ ├── restic.nix
│ │ ├── sops/
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── sops.nix
│ │ ├── ssl/
│ │ │ ├── dashboard/
│ │ │ │ └── SSL.json
│ │ │ └── docs/
│ │ │ └── default.md
│ │ ├── ssl.nix
│ │ ├── tinyproxy.nix
│ │ ├── vpn.nix
│ │ └── zfs.nix
│ ├── contracts/
│ │ ├── backup/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ ├── dummyModule.nix
│ │ │ └── test.nix
│ │ ├── backup.nix
│ │ ├── dashboard/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── dummyModule.nix
│ │ ├── dashboard.nix
│ │ ├── databasebackup/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ ├── dummyModule.nix
│ │ │ └── test.nix
│ │ ├── databasebackup.nix
│ │ ├── default.nix
│ │ ├── mount.nix
│ │ ├── secret/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ ├── dummyModule.nix
│ │ │ └── test.nix
│ │ ├── secret.nix
│ │ ├── ssl/
│ │ │ ├── docs/
│ │ │ │ └── default.md
│ │ │ └── dummyModule.nix
│ │ └── ssl.nix
│ └── services/
│ ├── arr/
│ │ └── docs/
│ │ └── default.md
│ ├── arr.nix
│ ├── audiobookshelf/
│ │ └── docs/
│ │ └── default.md
│ ├── audiobookshelf.nix
│ ├── deluge/
│ │ └── dashboard/
│ │ └── Torrents.json
│ ├── deluge.nix
│ ├── firefly-iii/
│ │ └── docs/
│ │ └── default.md
│ ├── firefly-iii.nix
│ ├── forgejo/
│ │ └── docs/
│ │ └── default.md
│ ├── forgejo.nix
│ ├── grocy.nix
│ ├── hledger.nix
│ ├── home-assistant/
│ │ └── docs/
│ │ └── default.md
│ ├── home-assistant.nix
│ ├── homepage/
│ │ └── docs/
│ │ └── default.md
│ ├── homepage.nix
│ ├── immich.nix
│ ├── jellyfin/
│ │ └── docs/
│ │ └── default.md
│ ├── jellyfin.nix
│ ├── karakeep/
│ │ └── docs/
│ │ └── default.md
│ ├── karakeep.nix
│ ├── mailserver/
│ │ └── docs/
│ │ └── default.md
│ ├── mailserver.nix
│ ├── nextcloud-server/
│ │ ├── dashboard/
│ │ │ └── Nextcloud.json
│ │ └── docs/
│ │ └── default.md
│ ├── nextcloud-server.nix
│ ├── open-webui/
│ │ └── docs/
│ │ └── default.md
│ ├── open-webui.nix
│ ├── paperless.nix
│ ├── pinchflat/
│ │ └── docs/
│ │ └── default.md
│ ├── pinchflat.nix
│ ├── vaultwarden/
│ │ └── docs/
│ │ └── default.md
│ └── vaultwarden.nix
├── patches/
│ ├── 0001-nixos-borgbackup-add-option-to-override-state-direct.patch
│ ├── 0001-selfhostblocks-never-onboard.patch
│ ├── lldap.patch
│ └── nextcloudexternalstorage.patch
└── test/
├── blocks/
│ ├── authelia.nix
│ ├── borgbackup.nix
│ ├── keypair.pem
│ ├── lib.nix
│ ├── lldap.nix
│ ├── mitmdump.nix
│ ├── monitoring.nix
│ ├── postgresql.nix
│ ├── restic.nix
│ └── ssl.nix
├── common.nix
├── contracts/
│ ├── backup.nix
│ ├── databasebackup.nix
│ ├── secret/
│ │ └── sops.yaml
│ └── secret.nix
├── modules/
│ ├── davfs.nix
│ ├── homepage.nix
│ └── lib.nix
└── services/
├── arr.nix
├── audiobookshelf.nix
├── deluge.nix
├── firefly-iii.nix
├── forgejo.nix
├── grocy.nix
├── hledger.nix
├── home-assistant.nix
├── homepage.nix
├── immich.nix
├── jellyfin.nix
├── karakeep.nix
├── nextcloud.nix
├── open-webui.nix
├── paperless.nix
├── pinchflat.nix
└── vaultwarden.nix
SYMBOL INDEX (3 symbols across 1 files) FILE: docs/generate-redirects-nixos-render-docs.py function scan_html_files (line 39) | def scan_html_files(output_dir, html_files): function output_collected_refs (line 84) | def output_collected_refs(): function apply_patches (line 137) | def apply_patches():
Condensed preview — 180 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,860K chars).
[
{
"path": ".github/dependabot.yml",
"chars": 278,
"preview": "# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.y"
},
{
"path": ".github/workflows/auto-merge.yaml",
"chars": 1093,
"preview": "name: Auto Merge\n\non:\n # Try enabling auto-merge for a pull request when a draft is marked as “ready for review”, when\n"
},
{
"path": ".github/workflows/build.yaml",
"chars": 4411,
"preview": "# name: build\n# on: push\n# jobs:\n# checks:\n# uses: nixbuild/nixbuild-action/.github/workflows/ci-workflow.yml@v19\n"
},
{
"path": ".github/workflows/demo.yml",
"chars": 2760,
"preview": "name: Demo\n\non:\n workflow_dispatch:\n pull_request:\n push:\n branches:\n - main\n\njobs:\n path-filter:\n runs-o"
},
{
"path": ".github/workflows/format.yaml",
"chars": 597,
"preview": "name: \"format\"\non:\n pull_request:\n push:\n branches: [ \"main\" ]\n\njobs:\n format:\n runs-on: ubuntu-latest\n step"
},
{
"path": ".github/workflows/lock-update.yaml",
"chars": 576,
"preview": "name: Update Flake Lock\n\non:\n workflow_dispatch:\n schedule:\n - cron: '0 0 * * *' # runs daily at 00:00\n\njobs:\n loc"
},
{
"path": ".github/workflows/pages.yml",
"chars": 1916,
"preview": "# Inspired from https://github.com/nix-community/nix-on-droid/blob/039379abeee67144d4094d80bbdaf183fb2eabe5/.github/work"
},
{
"path": ".github/workflows/version.yaml",
"chars": 434,
"preview": "name: Version Bump\n\non:\n push:\n branches:\n - main\n paths:\n - VERSION\n\njobs:\n create-tag:\n runs-on: "
},
{
"path": ".gitignore",
"chars": 75,
"preview": "*.qcow2\nresult\nresult-*\ndocs/redirects.json.backup\n.nixos-test-history\n\\#*#"
},
{
"path": "CHANGELOG.md",
"chars": 17302,
"preview": "<!---\n\nTemplate:\n\n## Breaking Changes\n\n## New Features\n\n## User Facing Backwards Compatible Changes\n\n## Fixes\n\n## Other "
},
{
"path": "LICENSE",
"chars": 34523,
"preview": " GNU AFFERO GENERAL PUBLIC LICENSE\n Version 3, 19 November 2007\n\n Copyright (C)"
},
{
"path": "README.md",
"chars": 16316,
"preview": "\n![GitHub commits since latest release"
},
{
"path": "VERSION",
"chars": 5,
"preview": "0.8.0"
},
{
"path": "demo/homeassistant/README.md",
"chars": 11092,
"preview": "# Home Assistant Demo {#demo-homeassistant}\n\n**This whole demo is highly insecure as all the private keys are available "
},
{
"path": "demo/homeassistant/configuration.nix",
"chars": 1933,
"preview": "{ config, pkgs, ... }:\n\nlet\n targetUser = \"nixos\";\n targetPort = 2222;\nin\n{\n imports = [\n # Include the results of"
},
{
"path": "demo/homeassistant/flake.nix",
"chars": 4691,
"preview": "{\n description = \"Home Assistant example for Self Host Blocks\";\n\n inputs = {\n selfhostblocks.url = \"github:ibizaman"
},
{
"path": "demo/homeassistant/hardware-configuration.nix",
"chars": 1826,
"preview": "# This file was generated by running nixos-generate-config on the VM.\n#\n# Do not modify this file! It was generated by "
},
{
"path": "demo/homeassistant/keys.txt",
"chars": 189,
"preview": "# created: 2023-11-17T00:05:25-08:00\n# public key: age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7\nAGE-SE"
},
{
"path": "demo/homeassistant/secrets.yaml",
"chars": 2642,
"preview": "home-assistant:\n country: ENC[AES256_GCM,data:2Ng=,iv:/VMB6yi3e8piAx8DzLGGhLsozxWUWX2R7NcmACFng8Q=,tag:Tx0Iy1AnLmPrnY"
},
{
"path": "demo/homeassistant/sops.yaml",
"chars": 168,
"preview": "keys:\n - &admin age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7\ncreation_rules:\n - path_regex: secrets."
},
{
"path": "demo/homeassistant/ssh_config",
"chars": 159,
"preview": "Host example\n Port 2222\n User nixos\n HostName 127.0.0.1\n IdentityFile sshkey\n IdentitiesOnly yes\n StrictHostKeyChe"
},
{
"path": "demo/homeassistant/sshkey",
"chars": 411,
"preview": "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACD"
},
{
"path": "demo/homeassistant/sshkey.pub",
"chars": 99,
"preview": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPueAR1wO7hRVt7ZnMGEqfYeE9bQ+USaASlv+SQyJ4Uj example@localhost\n"
},
{
"path": "demo/minimal/flake.nix",
"chars": 7524,
"preview": "{\n description = \"Minimal example to setup SelfHostBlocks\";\n\n inputs = {\n selfhostblocks.url = \"github:ibizaman/sel"
},
{
"path": "demo/nextcloud/README.md",
"chars": 12815,
"preview": "# Nextcloud Demo {#demo-nextcloud}\n\n**This whole demo is highly insecure as all the private keys are available publicly."
},
{
"path": "demo/nextcloud/configuration.nix",
"chars": 1994,
"preview": "{ config, pkgs, ... }:\n\nlet\n targetUser = \"nixos\";\n targetPort = 2222;\nin\n{\n imports = [\n # Include the results of"
},
{
"path": "demo/nextcloud/flake.nix",
"chars": 8279,
"preview": "{\n description = \"Nextcloud example for Self Host Blocks\";\n\n inputs = {\n selfhostblocks.url = \"github:ibizaman/self"
},
{
"path": "demo/nextcloud/hardware-configuration.nix",
"chars": 1826,
"preview": "# This file was generated by running nixos-generate-config on the VM.\n#\n# Do not modify this file! It was generated by "
},
{
"path": "demo/nextcloud/keys.txt",
"chars": 189,
"preview": "# created: 2023-11-17T00:05:25-08:00\n# public key: age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7\nAGE-SE"
},
{
"path": "demo/nextcloud/secrets.yaml",
"chars": 5798,
"preview": "nextcloud:\n adminpass: ENC[AES256_GCM,data:nD/4oml7mXbWF0axiqWQCZujFqeJMF0P/1vY9f4EPqg=,iv:KoxmL9tLPBoIJT7rxkEhxrQqZF"
},
{
"path": "demo/nextcloud/sops.yaml",
"chars": 168,
"preview": "keys:\n - &admin age1algdv9xwjre3tm7969eyremfw2ftx4h8qehmmjzksrv7f2qve9dqg8pug7\ncreation_rules:\n - path_regex: secrets."
},
{
"path": "demo/nextcloud/ssh_config",
"chars": 159,
"preview": "Host example\n Port 2222\n User nixos\n HostName 127.0.0.1\n IdentityFile sshkey\n IdentitiesOnly yes\n StrictHostKeyChe"
},
{
"path": "demo/nextcloud/sshkey",
"chars": 411,
"preview": "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACD"
},
{
"path": "demo/nextcloud/sshkey.pub",
"chars": 99,
"preview": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPueAR1wO7hRVt7ZnMGEqfYeE9bQ+USaASlv+SQyJ4Uj example@localhost\n"
},
{
"path": "docs/blocks.md",
"chars": 1906,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Blocks {#blocks}\n\nBlocks help you self-host apps or services. The"
},
{
"path": "docs/contracts.md",
"chars": 19294,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Contracts {#contracts}\n\n::: {.note}\nAn [RFC][] has been created w"
},
{
"path": "docs/contributing.md",
"chars": 7810,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Contributing {#contributing}\n\nAll issues and Pull Requests are we"
},
{
"path": "docs/default.nix",
"chars": 5763,
"preview": "# Taken nearly verbatim from https://github.com/nix-community/home-manager/pull/4673\n# Read these docs online at https:/"
},
{
"path": "docs/demos.md",
"chars": 408,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Demos {#demos}\n\nThese demos are showcasing what Self Host Blocks "
},
{
"path": "docs/generate-redirects-nixos-render-docs.py",
"chars": 8608,
"preview": "#!/usr/bin/env python3\n\"\"\"\nGenerate redirects.json by scanning actual HTML files produced by nixos-render-docs.\n\nThis sc"
},
{
"path": "docs/manual.md",
"chars": 734,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Self Host Blocks Manual {#self-host-blocks-manual}\n\n## Version @V"
},
{
"path": "docs/options.md",
"chars": 181,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# All Options {#all-options}\n\n```{=include=} options\nid-prefix: opt"
},
{
"path": "docs/preface.md",
"chars": 14868,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Preface {#preface}\n\n::: {.note}\nSelf Host Blocks is hosted on [Gi"
},
{
"path": "docs/recipes/dnsServer.md",
"chars": 5878,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Self-Host a DNS server {#recipes-dnsServer}\n\nThis recipe will sho"
},
{
"path": "docs/recipes/exposeService.md",
"chars": 4309,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Expose a service {#recipes-exposeService}\n\nLet's see how one can "
},
{
"path": "docs/recipes/serveStaticPages.md",
"chars": 2128,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Serve Static Pages {#recipes-serveStaticPages}\n\nThis recipe shows"
},
{
"path": "docs/recipes.md",
"chars": 450,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Recipes {#recipes}\n\nThis section of the manual gives you easy to "
},
{
"path": "docs/redirects.json",
"chars": 292220,
"preview": "{\n \"adding-new-service-documentation\": [\n \"service-implementation-guide.html#adding-new-service-documentation\"\n ],\n"
},
{
"path": "docs/service-implementation-guide.md",
"chars": 20974,
"preview": "# SelfHostBlocks Service Implementation Guide {#service-implementation-guide}\n\nThis guide documents the complete process"
},
{
"path": "docs/services.md",
"chars": 4554,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n# Services {#services}\n\nServices are usually web applications that "
},
{
"path": "docs/usage.md",
"chars": 18403,
"preview": "<!-- Read these docs at https://shb.skarabox.com -->\n\n# Usage {#usage}\n\n## Flake {#usage-flake}\n\nSelf Host Blocks (SHB) "
},
{
"path": "flake.nix",
"chars": 18047,
"preview": "{\n description = \"SelfHostBlocks module\";\n\n inputs = {\n nixpkgs.url = \"github:nixos/nixpkgs/nixos-unstable\";\n ni"
},
{
"path": "lib/default.nix",
"chars": 12540,
"preview": "{ pkgs, lib }:\nlet\n inherit (builtins) isAttrs hasAttr;\n inherit (lib) any concatMapStringsSep concatStringsSep;\n shb"
},
{
"path": "lib/homepage.nix",
"chars": 2391,
"preview": "{ lib, shb }:\nlet\n sort =\n attr: vs:\n map (v: { ${v.name} = v.${attr}; }) (\n lib.sortOn (v: v.sortOrder) (li"
},
{
"path": "lib/module.nix",
"chars": 244,
"preview": "{ pkgs, lib, ... }:\nlet\n shb = (import ./default.nix { inherit pkgs lib; });\nin\n{\n _module.args.shb = shb // {\n tes"
},
{
"path": "modules/blocks/authelia/docs/default.md",
"chars": 9229,
"preview": "# Authelia Block {#blocks-authelia}\n\nDefined in [`/modules/blocks/authelia.nix`](@REPO@/modules/blocks/authelia.nix).\n\nT"
},
{
"path": "modules/blocks/authelia.nix",
"chars": 23332,
"preview": "{\n config,\n options,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.authelia;\n opt = options.shb.authelia;\n\n "
},
{
"path": "modules/blocks/backup/dashboard/Backups.json",
"chars": 32255,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/blocks/borgbackup/docs/default.md",
"chars": 7917,
"preview": "# Borgbackup Block {#blocks-borgbackup}\n\nDefined in [`/modules/blocks/borgbackup.nix`](@REPO@/modules/blocks/borgbackup."
},
{
"path": "modules/blocks/borgbackup.nix",
"chars": 18168,
"preview": "{\n config,\n pkgs,\n lib,\n utils,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.borgbackup;\n\n inherit (lib)\n concatStrin"
},
{
"path": "modules/blocks/davfs.nix",
"chars": 2991,
"preview": "{ config, lib, ... }:\n\nlet\n cfg = config.shb.davfs;\nin\n{\n options.shb.davfs = {\n mounts = lib.mkOption {\n desc"
},
{
"path": "modules/blocks/hardcodedsecret.nix",
"chars": 2576,
"preview": "{\n config,\n lib,\n pkgs,\n shb,\n ...\n}:\nlet\n cfg = config.shb.hardcodedsecret;\n\n inherit (lib) mapAttrs' mkOption n"
},
{
"path": "modules/blocks/lldap/docs/default.md",
"chars": 6219,
"preview": "# LLDAP Block {#blocks-lldap}\n\nDefined in [`/modules/blocks/lldap.nix`](@REPO@/modules/blocks/lldap.nix).\n\nThis block se"
},
{
"path": "modules/blocks/lldap.nix",
"chars": 11593,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.lldap;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\n\n "
},
{
"path": "modules/blocks/mitmdump/docs/default.md",
"chars": 5521,
"preview": "# Mitmdump Block {#blocks-mitmdump}\n\nDefined in [`/modules/blocks/mitmdump.nix`](@REPO@/modules/blocks/mitmdump.nix).\n\nT"
},
{
"path": "modules/blocks/mitmdump.nix",
"chars": 9081,
"preview": "{\n config,\n lib,\n pkgs,\n ...\n}:\nlet\n inherit (lib)\n mapAttrs'\n mkOption\n nameValuePair\n types\n ;\n i"
},
{
"path": "modules/blocks/monitoring/dashboards/Errors.json",
"chars": 24410,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/blocks/monitoring/dashboards/Health.json",
"chars": 21142,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/blocks/monitoring/dashboards/Performance.json",
"chars": 42852,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/blocks/monitoring/dashboards/Scraping_Jobs.json",
"chars": 8134,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/blocks/monitoring/docs/default.md",
"chars": 11239,
"preview": "# Monitoring Block {#blocks-monitoring}\n\nDefined in [`/modules/blocks/monitoring.nix`](@REPO@/modules/blocks/monitoring."
},
{
"path": "modules/blocks/monitoring/rules.json",
"chars": 10379,
"preview": "[\n {\n \"uid\": \"f5246fa3-163f-4eae-9e1d-5b0fe2af0509\",\n \"title\": \"5XX Requests Error Budgets Under 99%\",\n \"condi"
},
{
"path": "modules/blocks/monitoring.nix",
"chars": 29502,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.monitoring;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}"
},
{
"path": "modules/blocks/nginx/docs/default.md",
"chars": 6147,
"preview": "# Nginx Block {#blocks-nginx}\n\nDefined in [`/modules/blocks/nginx.nix`](@REPO@/modules/blocks/nginx.nix).\n\nThis block se"
},
{
"path": "modules/blocks/nginx.nix",
"chars": 8603,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.nginx;\n\n fqdn = c: \"${c.subdomain}.${c.domain}\";\n\n vhostCon"
},
{
"path": "modules/blocks/postgresql/docs/default.md",
"chars": 2158,
"preview": "# PostgreSQL Block {#blocks-postgresql}\n\nDefined in [`/modules/blocks/postgresql.nix`](@REPO@/modules/blocks/postgresql."
},
{
"path": "modules/blocks/postgresql.nix",
"chars": 5539,
"preview": "{\n config,\n lib,\n pkgs,\n shb,\n ...\n}:\nlet\n cfg = config.shb.postgresql;\n\n upgrade-script =\n old: new:\n let\n"
},
{
"path": "modules/blocks/restic/docs/default.md",
"chars": 7795,
"preview": "# Restic Block {#blocks-restic}\n\nDefined in [`/modules/blocks/restic.nix`](@REPO@/modules/blocks/restic.nix).\n\nThis bloc"
},
{
"path": "modules/blocks/restic/dummyModule.nix",
"chars": 18,
"preview": "{ lib, ... }:\n{\n}\n"
},
{
"path": "modules/blocks/restic.nix",
"chars": 17408,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n utils,\n ...\n}:\n\nlet\n cfg = config.shb.restic;\n\n inherit (lib)\n concatStringsSe"
},
{
"path": "modules/blocks/sops/docs/default.md",
"chars": 2039,
"preview": "# SOPS Block {#blocks-sops}\n\nDefined in [`/modules/blocks/sops.nix`](@REPO@/modules/blocks/sops.nix).\n\nThis block sets u"
},
{
"path": "modules/blocks/sops.nix",
"chars": 1471,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\nlet\n inherit (lib) mapAttrs mkOption;\n inherit (lib.types) attrsOf anything submodu"
},
{
"path": "modules/blocks/ssl/dashboard/SSL.json",
"chars": 18290,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/blocks/ssl/docs/default.md",
"chars": 5177,
"preview": "# SSL Generator Block {#block-ssl}\n\nThis NixOS module is a block that implements the [SSL certificate generator](contrac"
},
{
"path": "modules/blocks/ssl.nix",
"chars": 24272,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.certs;\n\n inherit (builtins) dirOf;\n inherit (lib)\n "
},
{
"path": "modules/blocks/tinyproxy.nix",
"chars": 5303,
"preview": "# Inspired from https://github.com/NixOS/nixpkgs/pull/231152 but made it so we can have multiple instances.\n{\n config,\n"
},
{
"path": "modules/blocks/vpn.nix",
"chars": 10214,
"preview": "{\n config,\n pkgs,\n lib,\n ...\n}:\n\nlet\n cfg = config.shb.vpn;\n\n quoteEach = lib.concatMapStrings (x: ''\"${x}\"'');\n\n "
},
{
"path": "modules/blocks/zfs.nix",
"chars": 4094,
"preview": "{\n config,\n pkgs,\n lib,\n ...\n}:\n\nlet\n cfg = config.shb.zfs;\nin\n{\n options.shb.zfs = {\n defaultPoolName = lib.mk"
},
{
"path": "modules/contracts/backup/docs/default.md",
"chars": 3303,
"preview": "# Backup Contract {#contract-backup}\n\nThis NixOS contract represents a backup job\nthat will backup one or more files or "
},
{
"path": "modules/contracts/backup/dummyModule.nix",
"chars": 725,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib) mkOption;\n inherit (lib.types) submodule;\nin\n{\n imports = [\n ../../../lib/mo"
},
{
"path": "modules/contracts/backup/test.nix",
"chars": 3643,
"preview": "{\n pkgs,\n lib,\n shb,\n}:\nlet\n inherit (lib)\n concatMapStringsSep\n getAttrFromPath\n mkIf\n optionalAttrs\n "
},
{
"path": "modules/contracts/backup.nix",
"chars": 6538,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib)\n concatStringsSep\n literalMD\n mkOption\n optionalAttrs\n optionalStr"
},
{
"path": "modules/contracts/dashboard/docs/default.md",
"chars": 1822,
"preview": "# Dashboard Contract {#contract-dashboard}\n\nThis NixOS contract is used for user-facing services\nthat want to be display"
},
{
"path": "modules/contracts/dashboard/dummyModule.nix",
"chars": 718,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib) mkOption;\n inherit (lib.types) submodule;\nin\n{\n imports = [\n ../../../lib/mo"
},
{
"path": "modules/contracts/dashboard.nix",
"chars": 1814,
"preview": "{ lib, ... }:\nlet\n inherit (lib) mkOption;\n inherit (lib.types)\n nullOr\n submodule\n str\n ;\nin\n{\n mkReques"
},
{
"path": "modules/contracts/databasebackup/docs/default.md",
"chars": 2924,
"preview": "# Database Backup Contract {#contract-databasebackup}\n\nThis NixOS contract represents a backup job\nthat will backup ever"
},
{
"path": "modules/contracts/databasebackup/dummyModule.nix",
"chars": 755,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib) mkOption;\n inherit (lib.types) submodule;\nin\n{\n imports = [\n ../../../lib/mo"
},
{
"path": "modules/contracts/databasebackup/test.nix",
"chars": 2925,
"preview": "{\n pkgs,\n lib,\n shb,\n}:\nlet\n inherit (lib)\n getAttrFromPath\n mkIf\n optionalAttrs\n setAttrByPath\n ;\nin"
},
{
"path": "modules/contracts/databasebackup.nix",
"chars": 5474,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib)\n mkOption\n literalExpression\n literalMD\n optionalAttrs\n optionalSt"
},
{
"path": "modules/contracts/default.nix",
"chars": 1634,
"preview": "{\n pkgs,\n lib,\n shb,\n}:\nlet\n inherit (lib) mkOption optionalAttrs;\n inherit (lib.types) anything;\n\n mkContractFunc"
},
{
"path": "modules/contracts/mount.nix",
"chars": 199,
"preview": "{ lib, ... }:\nlib.types.submodule {\n freeformType = lib.types.anything;\n\n options = {\n path = lib.mkOption {\n "
},
{
"path": "modules/contracts/secret/docs/default.md",
"chars": 6300,
"preview": "# Secret Contract {#contract-secret}\n\nThis NixOS contract represents a secret file\nthat must be created out of band - fr"
},
{
"path": "modules/contracts/secret/dummyModule.nix",
"chars": 719,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib) mkOption;\n inherit (lib.types) submodule;\nin\n{\n imports = [\n ../../../lib/mo"
},
{
"path": "modules/contracts/secret/test.nix",
"chars": 1989,
"preview": "{\n pkgs,\n lib,\n shb,\n}:\nlet\n inherit (lib) getAttrFromPath setAttrByPath;\n inherit (lib) mkIf;\nin\n{\n name,\n confi"
},
{
"path": "modules/contracts/secret.nix",
"chars": 3930,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib)\n concatStringsSep\n literalMD\n mkOption\n optionalAttrs\n optionalStr"
},
{
"path": "modules/contracts/ssl/docs/default.md",
"chars": 2706,
"preview": "# SSL Generator Contract {#contract-ssl}\n\nThis NixOS contract represents an SSL certificate generator. This contract is "
},
{
"path": "modules/contracts/ssl/dummyModule.nix",
"chars": 218,
"preview": "{ lib, shb, ... }:\n{\n imports = [\n ../../../lib/module.nix\n ];\n\n options.shb.contracts.ssl = lib.mkOption {\n de"
},
{
"path": "modules/contracts/ssl.nix",
"chars": 1796,
"preview": "{ lib, ... }:\nrec {\n certs-paths = lib.types.submodule {\n freeformType = lib.types.anything;\n\n options = {\n "
},
{
"path": "modules/services/arr/docs/default.md",
"chars": 7597,
"preview": "# *Arr Service {#services-arr}\n\nDefined in [`/modules/services/arr.nix`](@REPO@/modules/services/arr.nix).\n\nThis NixOS m"
},
{
"path": "modules/services/arr.nix",
"chars": 19080,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.arr;\n\n apps = {\n radarr = {\n settingsFormat "
},
{
"path": "modules/services/audiobookshelf/docs/default.md",
"chars": 3402,
"preview": "# Audiobookshelf Service {#services-audiobookshelf}\n\nDefined in [`/modules/services/audiobookshelf.nix`](@REPO@/modules/"
},
{
"path": "modules/services/audiobookshelf.nix",
"chars": 7501,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.audiobookshelf;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\n\n"
},
{
"path": "modules/services/deluge/dashboard/Torrents.json",
"chars": 29130,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"datasource\","
},
{
"path": "modules/services/deluge.nix",
"chars": 14215,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.deluge;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\n\n"
},
{
"path": "modules/services/firefly-iii/docs/default.md",
"chars": 6367,
"preview": "# Firefly-iii Service {#services-firefly-iii}\n\nDefined in [`/modules/services/firefly-iii.nix`](@REPO@/modules/services/"
},
{
"path": "modules/services/firefly-iii.nix",
"chars": 13884,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.firefly-iii;\nin\n{\n imports = [\n ../blocks/nginx.nix\n ."
},
{
"path": "modules/services/forgejo/docs/default.md",
"chars": 8248,
"preview": "# Forgejo Service {#services-forgejo}\n\nDefined in [`/modules/services/forgejo.nix`](@REPO@/modules/services/forgejo.nix)"
},
{
"path": "modules/services/forgejo.nix",
"chars": 22216,
"preview": "{\n config,\n options,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.forgejo;\n\n inherit (lib)\n all\n attr"
},
{
"path": "modules/services/grocy.nix",
"chars": 3756,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.grocy;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\nin\n{\n opt"
},
{
"path": "modules/services/hledger.nix",
"chars": 3751,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.hledger;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\nin\n{\n i"
},
{
"path": "modules/services/home-assistant/docs/default.md",
"chars": 14249,
"preview": "# Home-Assistant Service {#services-home-assistant}\n\nDefined in [`/modules/services/home-assistant.nix`](@REPO@/modules/"
},
{
"path": "modules/services/home-assistant.nix",
"chars": 13453,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.home-assistant;\n\n fqdn = \"${cfg.subdomain}.${cfg.dom"
},
{
"path": "modules/services/homepage/docs/default.md",
"chars": 5951,
"preview": "# Homepage Service {#services-homepage}\n\nDefined in [`/modules/services/homepage.nix`](@REPO@/modules/services/homepage."
},
{
"path": "modules/services/homepage.nix",
"chars": 9139,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\nlet\n cfg = config.shb.homepage;\n\n inherit (lib) types;\nin\n{\n imports = [\n ../.."
},
{
"path": "modules/services/immich.nix",
"chars": 18764,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.immich;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\n "
},
{
"path": "modules/services/jellyfin/docs/default.md",
"chars": 6127,
"preview": "# Jellyfin Service {#services-jellyfin}\n\nDefined in [`/modules/services/jellyfin.nix`](@REPO@/modules/services/jellyfin."
},
{
"path": "modules/services/jellyfin.nix",
"chars": 32438,
"preview": "{\n config,\n lib,\n pkgs,\n shb,\n ...\n}:\n\nlet\n inherit (lib) types;\n\n cfg = config.shb.jellyfin;\n\n fqdn = \"${cfg.su"
},
{
"path": "modules/services/karakeep/docs/default.md",
"chars": 4824,
"preview": "# Karakeep {#services-karakeep}\n\nDefined in [`/modules/blocks/karakeep.nix`](@REPO@/modules/blocks/karakeep.nix),\nfound "
},
{
"path": "modules/services/karakeep.nix",
"chars": 8821,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\nlet\n cfg = config.shb.karakeep;\nin\n{\n imports = [\n ../../lib/module.nix\n ../b"
},
{
"path": "modules/services/mailserver/docs/default.md",
"chars": 11067,
"preview": "# Mailserver Service {#services-mailserver}\n\nDefined in [`/modules/services/mailserver.nix`](@REPO@/modules/services/mai"
},
{
"path": "modules/services/mailserver.nix",
"chars": 25627,
"preview": "{\n config,\n lib,\n shb,\n pkgs,\n ...\n}:\nlet\n cfg = config.shb.mailserver;\nin\n{\n imports = [\n (\n builtins.fe"
},
{
"path": "modules/services/nextcloud-server/dashboard/Nextcloud.json",
"chars": 56988,
"preview": "{\n \"annotations\": {\n \"list\": [\n {\n \"builtIn\": 1,\n \"datasource\": {\n \"type\": \"grafana\",\n "
},
{
"path": "modules/services/nextcloud-server/docs/default.md",
"chars": 27051,
"preview": "# Nextcloud Server Service {#services-nextcloudserver}\n\nDefined in [`/modules/services/nextcloud-server.nix`](@REPO@/mod"
},
{
"path": "modules/services/nextcloud-server.nix",
"chars": 51930,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.nextcloud;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\""
},
{
"path": "modules/services/open-webui/docs/default.md",
"chars": 4891,
"preview": "# Open-WebUI Service {#services-open-webui}\n\nDefined in [`/modules/blocks/open-webui.nix`](@REPO@/modules/blocks/open-we"
},
{
"path": "modules/services/open-webui.nix",
"chars": 8928,
"preview": "{\n config,\n lib,\n pkgs,\n shb,\n ...\n}:\nlet\n cfg = config.shb.open-webui;\n\n roleClaim = \"openwebui_groups\";\n oauth"
},
{
"path": "modules/services/paperless.nix",
"chars": 12679,
"preview": "{\n config,\n pkgs,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.paperless;\n dataFolder = cfg.dataDir;\n fqdn = \"${cf"
},
{
"path": "modules/services/pinchflat/docs/default.md",
"chars": 2949,
"preview": "# Pinchflat Service {#services-pinchflat}\n\nDefined in [`/modules/services/pinchflat.nix`](@REPO@/modules/services/pinchf"
},
{
"path": "modules/services/pinchflat.nix",
"chars": 5898,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\nlet\n cfg = config.shb.pinchflat;\n\n inherit (lib) types;\nin\n{\n imports = [\n ../."
},
{
"path": "modules/services/vaultwarden/docs/default.md",
"chars": 5187,
"preview": "# Vaultwarden Service {#services-vaultwarden}\n\nDefined in [`/modules/services/vaultwarden.nix`](@REPO@/modules/services/"
},
{
"path": "modules/services/vaultwarden.nix",
"chars": 8266,
"preview": "{\n config,\n lib,\n shb,\n ...\n}:\n\nlet\n cfg = config.shb.vaultwarden;\n\n fqdn = \"${cfg.subdomain}.${cfg.domain}\";\n\n d"
},
{
"path": "patches/0001-nixos-borgbackup-add-option-to-override-state-direct.patch",
"chars": 2978,
"preview": "From dda895b551c7cf56476ac8892904e289a4d8b920 Mon Sep 17 00:00:00 2001\nFrom: ibizaman <ibizaman@tiserbox.com>\nDate: Sat,"
},
{
"path": "patches/0001-selfhostblocks-never-onboard.patch",
"chars": 834,
"preview": "From 6897dd86a41b336c7c03a466990f7e981c5c649c Mon Sep 17 00:00:00 2001\nFrom: ibizaman <ibizaman@tiserbox.com>\nDate: Tue,"
},
{
"path": "patches/lldap.patch",
"chars": 25060,
"preview": "From e5a1bf4cb019933621eb059cc6cdd1f8af8df71d Mon Sep 17 00:00:00 2001\nFrom: ibizaman <ibizaman@tiserbox.com>\nDate: Wed,"
},
{
"path": "patches/nextcloudexternalstorage.patch",
"chars": 1268,
"preview": "diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php\nindex 260f9218a88..26e5a4172f7 10"
},
{
"path": "test/blocks/authelia.nix",
"chars": 7157,
"preview": "{ pkgs, shb, ... }:\nlet\n pkgs' = pkgs;\n\n ldapAdminPassword = \"ldapAdminPassword\";\nin\n{\n basic = shb.test.runNixOSTest"
},
{
"path": "test/blocks/borgbackup.nix",
"chars": 5912,
"preview": "{ shb, ... }:\nlet\n commonTest =\n user:\n shb.test.runNixOSTest {\n name = \"borgbackup_backupAndRestore_${user}"
},
{
"path": "test/blocks/keypair.pem",
"chars": 1708,
"preview": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC2x1rFx98p6djQ\nX0mJ8nUMnS3LU7ih8UU5soW/TVh"
},
{
"path": "test/blocks/lib.nix",
"chars": 5168,
"preview": "{\n pkgs,\n lib,\n shb,\n ...\n}:\nlet\n pkgs' = pkgs;\nin\n{\n template =\n let\n aSecret = pkgs.writeText \"a-secret."
},
{
"path": "test/blocks/lldap.nix",
"chars": 5630,
"preview": "{\n pkgs,\n lib,\n shb,\n ...\n}:\nlet\n pkgs' = pkgs;\n\n password = \"securepassword\";\n charliePassword = \"CharliePasswor"
},
{
"path": "test/blocks/mitmdump.nix",
"chars": 4624,
"preview": "{\n pkgs,\n lib,\n shb,\n ...\n}:\nlet\n serve =\n port: text:\n lib.getExe (\n pkgs.writers.writePython3Bin \"serv"
},
{
"path": "test/blocks/monitoring.nix",
"chars": 9592,
"preview": "{ shb, ... }:\nlet\n password = \"securepw\";\n oidcSecret = \"oidcSecret\";\n\n commonTestScript = shb.test.accessScript {\n "
},
{
"path": "test/blocks/postgresql.nix",
"chars": 6292,
"preview": "{\n pkgs,\n lib,\n shb,\n ...\n}:\nlet\n pkgs' = pkgs;\nin\n{\n peerWithoutUser = shb.test.runNixOSTest {\n name = \"postgr"
},
{
"path": "test/blocks/restic.nix",
"chars": 5882,
"preview": "{ lib, shb, ... }:\nlet\n commonTest =\n user:\n shb.test.runNixOSTest {\n name = \"restic_backupAndRestore_${user"
},
{
"path": "test/blocks/ssl.nix",
"chars": 12122,
"preview": "{ pkgs, shb, ... }:\nlet\n pkgs' = pkgs;\nin\n{\n test = shb.test.runNixOSTest {\n name = \"ssl-test\";\n\n nodes.server ="
},
{
"path": "test/common.nix",
"chars": 20051,
"preview": "{ pkgs, lib }:\nlet\n inherit (lib) hasAttr mkOption optionalString;\n inherit (lib.types)\n bool\n enum\n listOf\n "
},
{
"path": "test/contracts/backup.nix",
"chars": 3461,
"preview": "{ shb, ... }:\n{\n restic_root = shb.contracts.test.backup {\n name = \"restic_root\";\n username = \"root\";\n provide"
},
{
"path": "test/contracts/databasebackup.nix",
"chars": 2300,
"preview": "{ shb, ... }:\n{\n restic_postgres = shb.contracts.test.databasebackup {\n name = \"restic_postgres\";\n requesterRoot "
},
{
"path": "test/contracts/secret/sops.yaml",
"chars": 0,
"preview": ""
},
{
"path": "test/contracts/secret.nix",
"chars": 834,
"preview": "{ shb, ... }:\n{\n hardcoded_root_root = shb.contracts.test.secret {\n name = \"hardcoded\";\n modules = [ ../../module"
},
{
"path": "test/modules/davfs.nix",
"chars": 714,
"preview": "{ pkgs, lib, ... }:\nlet\n anyOpt =\n default:\n lib.mkOption {\n type = lib.types.anything;\n inherit defaul"
},
{
"path": "test/modules/homepage.nix",
"chars": 6030,
"preview": "{ shb }:\n{\n testHomepageAsServiceGroup = {\n expected = [\n {\n \"Media\" = [\n {\n \"Jellyf"
},
{
"path": "test/modules/lib.nix",
"chars": 2899,
"preview": "{ lib, shb, ... }:\nlet\n inherit (lib) nameValuePair;\nin\n{\n # Tests that withReplacements can:\n # - recurse in attrs a"
},
{
"path": "test/services/arr.nix",
"chars": 6318,
"preview": "{\n pkgs,\n lib,\n shb,\n ...\n}:\nlet\n healthUrl = \"/health\";\n loginUrl = \"/UI/Login\";\n\n # TODO: Test login\n commonTe"
},
{
"path": "test/services/audiobookshelf.nix",
"chars": 3786,
"preview": "{ shb, ... }:\nlet\n commonTestScript = shb.test.accessScript {\n hasSSL = { node, ... }: !(isNull node.config.shb.audi"
},
{
"path": "test/services/deluge.nix",
"chars": 6627,
"preview": "{\n pkgs,\n lib,\n shb,\n ...\n}:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node"
},
{
"path": "test/services/firefly-iii.nix",
"chars": 10220,
"preview": "{ pkgs, shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.f"
},
{
"path": "test/services/forgejo.nix",
"chars": 9600,
"preview": "{ shb, ... }:\nlet\n adminPassword = \"AdminPassword\";\n\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ..."
},
{
"path": "test/services/grocy.nix",
"chars": 2382,
"preview": "{ shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.grocy.s"
},
{
"path": "test/services/hledger.nix",
"chars": 2513,
"preview": "{ shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.hledger"
},
{
"path": "test/services/home-assistant.nix",
"chars": 5929,
"preview": "{ pkgs, shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.h"
},
{
"path": "test/services/homepage.nix",
"chars": 4553,
"preview": "{ shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.homepag"
},
{
"path": "test/services/immich.nix",
"chars": 4054,
"preview": "{\n pkgs,\n lib,\n shb,\n}:\nlet\n subdomain = \"i\";\n domain = \"example.com\";\n\n commonTestScript = shb.test.accessScript "
},
{
"path": "test/services/jellyfin.nix",
"chars": 15492,
"preview": "{ pkgs, shb, ... }:\nlet\n port = 9096;\n\n adminUser = \"jellyfin2\";\n adminPassword = \"admin\";\n\n commonTestScript = shb."
},
{
"path": "test/services/karakeep.nix",
"chars": 5818,
"preview": "{ shb, ... }:\nlet\n nextauthSecret = \"nextauthSecret\";\n oidcSecret = \"oidcSecret\";\n\n commonTestScript = shb.test.mkScr"
},
{
"path": "test/services/nextcloud.nix",
"chars": 20236,
"preview": "{ lib, shb, ... }:\nlet\n supportedVersion = [\n 32\n 33\n ];\n\n adminUser = \"root\";\n adminPass = \"rootpw\";\n oidcSe"
},
{
"path": "test/services/open-webui.nix",
"chars": 6008,
"preview": "{ shb, ... }:\nlet\n oidcSecret = \"oidcSecret\";\n\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !("
},
{
"path": "test/services/paperless.nix",
"chars": 4208,
"preview": "{\n pkgs,\n lib,\n shb,\n}:\nlet\n subdomain = \"p\";\n domain = \"example.com\";\n\n commonTestScript = shb.test.accessScript "
},
{
"path": "test/services/pinchflat.nix",
"chars": 5422,
"preview": "{ pkgs, shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.p"
},
{
"path": "test/services/vaultwarden.nix",
"chars": 5711,
"preview": "{ shb, ... }:\nlet\n commonTestScript = shb.test.mkScripts {\n hasSSL = { node, ... }: !(isNull node.config.shb.vaultwa"
}
]
About this extraction
This page contains the full source code of the ibizaman/selfhostblocks GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 180 files (1.7 MB), approximately 433.3k tokens, and a symbol index with 3 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.