- Nix 46.7%
- Rust 32.2%
- Python 21.1%
| modules/dynamicism | ||
| src | ||
| tests | ||
| .editorconfig | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| default.nix | ||
| flake.lock | ||
| flake.nix | ||
| package.nix | ||
| README.md | ||
| shell.nix | ||
Dynix — WIP modular dynamicism for NixOS systems
Dynix is a prototype for modifying an append-only NixOS configuration, and dynamically applying that configuration.
Running the tests
There are currently 3 implemented dynamicism modules: gotosocial, harmonia, and distccd.
Each test uses the NixOS test infrastructure to:
- Setup a virtual machine running NixOS
- Configure the VM's NixOS to run a given service, with certain settings
- Verify that the running service is using those settings
- Use Dynix to change a setting for that service
- Verify that the running service is now using the new setting
The tests themselves can be run with Nix. To run the test for, e.g., Gotosocial, you can run:
$ nix --experimental-features "nix-command flakes pipe-operator pipe-operators" build .#default.tests.gotosocial
The experimental piping operator is currently used in Dynix, so you must enable the experimental feature pipe-operator for Lix or pipe-operators for CppNix (you can add both to cover both Nix implementations); flakes are used for locked inputs.
To run a test with fewer experimental features, and without locked inputs, you can use the old CLI:
$ nix-build --experimental-features "pipe-operator pipe-operators" -A tests.gotosocial
All the tests at once can be run with:
$ nix build --experimental-features "nix-command flakes pipe-operator pipe-operators" .#default.allTests
Gotosocial
This example, implemented in ./modules/dynamicism/gotosocial.nix, is tested in ./tests/gotosocial.
The test sets up a VM using NixOS's services.gotosocial module with the following static configuration:
{
services.gotosocial = {
enable = true;
setupPostgresqlDB = true;
settings = {
application-name = "gotosocial-for-machine";
host = "gotosocial-machine.local";
};
};
}
The automated test script:
- Asserts that that the above static configuration is in effect (by extracting the configuration from the running Gotosocial process)
- Runs
dynix append "services.gotosocial.settings.application-name" "yay!", which modifies the append-only configuration file/etc/nixos/dynamic.nixin the VM filesystem - Runs the dynamic activation script built by
(import <nixpkgs/nixos>).config.dynamicism.applyDynamicConfiguration { }, which applies the dynamic configuration - Asserts that the dynamically configured
application-nameis in effect - Runs
nixos-rebuild switchto re-apply the static configuration - Asserts that the dynamic configuration is no longer in effect, and we are back to the static configuration
Harmonia
This example, implemented in ./modules/dynamicism/harmonia.nix, is tested in ./tests/harmonia.
The test sets up a VM using NixOS's services.harmonia module with the following static configuration
{
services.harmonia = {
enable = true;
settings = {
workers = 4;
max_connection_rate = 256;
};
};
}
The VM test script:
- Asserts that the above static configuration is in effect (by extracting the configuration from the running Harmonia process)
- Runs
dynix append "services.harmonia.settings.workers" 20, to modify the append-only configuration file/etc/nixos/dynamic.nixin the VM filesystem - Runs the dynamic activation script built by
(import <nixpkgs/nixos>).config.dynamicism.applyDynamicConfiguration { }, to apply the dynamic configuration - Asserts that the dynamically configured
workersis in effect - Runs
dynix append "services.harmonia.settings.max_connection_rate" 100 - Runs the dynamic activation script
- Asserts that both
max_connection_rateandworkersdynamic values are in effect - Runs
nixos-rebuild switchto re-apply the static configuration - Asserts that the dynamic configuration is no longer in effect, and we are back to the static configuration
Distccd
This example, implemented in ./modules/dynamicism/distccd.nix, is tested in ./tests/distccd.
The test sets up a VM using NixOS's services.distccd module with the following static configuration:
{
services.distccd = {
jobTimeout = 900;
maxJobs = 12;
logLevel = "warning";
};
}
The VM test script:
- Asserts that the above static configuration is in effect (by extracting the configuration from the running Distccd process)
- Runs
dynix append "services.distccd.maxJobs" 4, to modify the append-only configuration file/etc/nixos/dynamic.nixin the VM filesystem - Runs the dynamic activation script built by
(import <nixpkgs/nixos>).config.dynamicism.applyDynamicConfiguration { }, to apply the dynamic configuration - Asserts that the dynamically configured
maxJobsis in effect - Runs
dynix append "services.distccd.logLevel" "error" - Runs the dynamic activation script
- Asserts that both
maxJobsandlogLeveldynamic values are in effect - Runs
nixos-rebuild switchto re-apply the static configuration - Asserts that the dynamic configuration is no longer in effect, and we are back to the static configuration.