Compare commits
69 Commits
ke-docs-te
...
6a6a371256
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a6a371256 | |||
|
|
0f847b4799 | ||
|
|
40a8a823b8 | ||
|
|
e3adb3fc71 | ||
|
|
a569a1d147 | ||
|
|
64718b77ca | ||
|
|
7b34c39736 | ||
|
|
4d6ab60793 | ||
|
|
35bffee544 | ||
|
|
16917fd79b | ||
|
|
895c116c01 | ||
|
|
e67151f7b9 | ||
|
|
8d26ec1760 | ||
|
|
7a9062b629 | ||
|
|
de07454a0a | ||
|
|
6fe60f61cf | ||
|
|
3fa74847e4 | ||
|
|
fc37140b52 | ||
|
|
83406c61f3 | ||
|
|
6d736e7e80 | ||
|
|
7b6cec4100 | ||
|
|
e21a6516b5 | ||
|
|
6ffe8ea5f6 | ||
|
|
0a2fefd141 | ||
|
|
0c885d05b6 | ||
|
|
58d85b117a | ||
|
|
ad58d7b6e9 | ||
|
|
7a63cb9642 | ||
|
|
196b98da36 | ||
|
|
42acbe95b8 | ||
|
|
b6b065e365 | ||
|
|
4b1955b189 | ||
|
|
ef7ef8b843 | ||
|
|
38c1367322 | ||
|
|
8e72c086fd | ||
|
|
c454b1339d | ||
|
|
d1b2d43e5b | ||
|
|
da98ca0f1c | ||
|
|
1953540d08 | ||
|
|
be31b9ce21 | ||
|
|
169b4016e6 | ||
|
|
2e55028a1b | ||
|
|
1d228231f2 | ||
|
|
affb926450 | ||
|
|
c7f65e929f | ||
|
|
ba4ff493e8 | ||
|
|
eb08803e2a | ||
|
|
bbc9486f0e | ||
|
|
999d709350 | ||
|
|
0b1a330cc2 | ||
|
|
995b7cf50d | ||
|
|
5477b13233 | ||
|
|
d6170e5efb | ||
|
|
18fe117363 | ||
|
|
33a868acc2 | ||
|
|
11372d35e1 | ||
|
|
b7508b2b43 | ||
|
|
183817b769 | ||
|
|
591e53e9be | ||
|
|
a6a6415e31 | ||
|
|
0060ead876 | ||
|
|
224e41d3ad | ||
|
|
b3323007b2 | ||
|
|
3e950bc66f | ||
|
|
9503b46b21 | ||
|
|
a2cec323a2 | ||
|
|
4239f4d27f | ||
|
|
8ac8264997 | ||
|
|
544a53ae9c |
@@ -58,20 +58,22 @@
|
|||||||
pkgs.buildPackages.xorg.lndir
|
pkgs.buildPackages.xorg.lndir
|
||||||
pkgs.glibcLocales
|
pkgs.glibcLocales
|
||||||
pkgs.kbd.out
|
pkgs.kbd.out
|
||||||
self.nixosConfigurations."test-flash-machine-${pkgs.hostPlatform.system}".pkgs.perlPackages.ConfigIniFiles
|
self.nixosConfigurations."test-flash-machine-${pkgs.stdenv.hostPlatform.system}".pkgs.perlPackages.ConfigIniFiles
|
||||||
self.nixosConfigurations."test-flash-machine-${pkgs.hostPlatform.system}".pkgs.perlPackages.FileSlurp
|
self.nixosConfigurations."test-flash-machine-${pkgs.stdenv.hostPlatform.system}".pkgs.perlPackages.FileSlurp
|
||||||
pkgs.bubblewrap
|
pkgs.bubblewrap
|
||||||
|
|
||||||
self.nixosConfigurations."test-flash-machine-${pkgs.hostPlatform.system}".config.system.build.toplevel
|
self.nixosConfigurations."test-flash-machine-${pkgs.stdenv.hostPlatform.system}".config.system.build.toplevel
|
||||||
self.nixosConfigurations."test-flash-machine-${pkgs.hostPlatform.system}".config.system.build.diskoScript
|
self.nixosConfigurations."test-flash-machine-${pkgs.stdenv.hostPlatform.system}".config.system.build.diskoScript
|
||||||
self.nixosConfigurations."test-flash-machine-${pkgs.hostPlatform.system}".config.system.build.diskoScript.drvPath
|
self.nixosConfigurations."test-flash-machine-${pkgs.stdenv.hostPlatform.system}".config.system.build.diskoScript.drvPath
|
||||||
]
|
]
|
||||||
++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||||
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Skip flash test on aarch64-linux for now as it's too slow
|
# Skip flash test on aarch64-linux for now as it's too slow
|
||||||
checks = lib.optionalAttrs (pkgs.stdenv.isLinux && pkgs.hostPlatform.system != "aarch64-linux") {
|
checks =
|
||||||
|
lib.optionalAttrs (pkgs.stdenv.isLinux && pkgs.stdenv.hostPlatform.system != "aarch64-linux")
|
||||||
|
{
|
||||||
nixos-test-flash = self.clanLib.test.baseTest {
|
nixos-test-flash = self.clanLib.test.baseTest {
|
||||||
name = "flash";
|
name = "flash";
|
||||||
nodes.target = {
|
nodes.target = {
|
||||||
@@ -100,7 +102,7 @@
|
|||||||
machine.succeed("echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIRWUusawhlIorx7VFeQJHmMkhl9X3QpnvOdhnV/bQNG root@target' > ./test_id_ed25519.pub")
|
machine.succeed("echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIRWUusawhlIorx7VFeQJHmMkhl9X3QpnvOdhnV/bQNG root@target' > ./test_id_ed25519.pub")
|
||||||
# Some distros like to automount disks with spaces
|
# Some distros like to automount disks with spaces
|
||||||
machine.succeed('mkdir -p "/mnt/with spaces" && mkfs.ext4 /dev/vdc && mount /dev/vdc "/mnt/with spaces"')
|
machine.succeed('mkdir -p "/mnt/with spaces" && mkfs.ext4 /dev/vdc && mount /dev/vdc "/mnt/with spaces"')
|
||||||
machine.succeed("clan flash write --ssh-pubkey ./test_id_ed25519.pub --keymap de --language de_DE.UTF-8 --debug --flake ${self.checks.x86_64-linux.clan-core-for-checks} --yes --disk main /dev/vdc test-flash-machine-${pkgs.hostPlatform.system}")
|
machine.succeed("clan flash write --ssh-pubkey ./test_id_ed25519.pub --keymap de --language de_DE.UTF-8 --debug --flake ${self.checks.x86_64-linux.clan-core-for-checks} --yes --disk main /dev/vdc test-flash-machine-${pkgs.stdenv.hostPlatform.system}")
|
||||||
'';
|
'';
|
||||||
} { inherit pkgs self; };
|
} { inherit pkgs self; };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -160,9 +160,9 @@
|
|||||||
closureInfo = pkgs.closureInfo {
|
closureInfo = pkgs.closureInfo {
|
||||||
rootPaths = [
|
rootPaths = [
|
||||||
privateInputs.clan-core-for-checks
|
privateInputs.clan-core-for-checks
|
||||||
self.nixosConfigurations."test-install-machine-${pkgs.hostPlatform.system}".config.system.build.toplevel
|
self.nixosConfigurations."test-install-machine-${pkgs.stdenv.hostPlatform.system}".config.system.build.toplevel
|
||||||
self.nixosConfigurations."test-install-machine-${pkgs.hostPlatform.system}".config.system.build.initialRamdisk
|
self.nixosConfigurations."test-install-machine-${pkgs.stdenv.hostPlatform.system}".config.system.build.initialRamdisk
|
||||||
self.nixosConfigurations."test-install-machine-${pkgs.hostPlatform.system}".config.system.build.diskoScript
|
self.nixosConfigurations."test-install-machine-${pkgs.stdenv.hostPlatform.system}".config.system.build.diskoScript
|
||||||
pkgs.stdenv.drvPath
|
pkgs.stdenv.drvPath
|
||||||
pkgs.bash.drvPath
|
pkgs.bash.drvPath
|
||||||
pkgs.buildPackages.xorg.lndir
|
pkgs.buildPackages.xorg.lndir
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
# Prepare test flake and Nix store
|
# Prepare test flake and Nix store
|
||||||
flake_dir = prepare_test_flake(
|
flake_dir = prepare_test_flake(
|
||||||
temp_dir,
|
temp_dir,
|
||||||
"${self.checks.${pkgs.hostPlatform.system}.clan-core-for-checks}",
|
"${self.checks.${pkgs.stdenv.hostPlatform.system}.clan-core-for-checks}",
|
||||||
"${closureInfo}"
|
"${closureInfo}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@
|
|||||||
# Prepare test flake and Nix store
|
# Prepare test flake and Nix store
|
||||||
flake_dir = prepare_test_flake(
|
flake_dir = prepare_test_flake(
|
||||||
temp_dir,
|
temp_dir,
|
||||||
"${self.checks.${pkgs.hostPlatform.system}.clan-core-for-checks}",
|
"${self.checks.${pkgs.stdenv.hostPlatform.system}.clan-core-for-checks}",
|
||||||
"${closureInfo}"
|
"${closureInfo}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cli = self.packages.${pkgs.hostPlatform.system}.clan-cli-full;
|
cli = self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli-full;
|
||||||
|
|
||||||
ollama-model = pkgs.callPackage ./qwen3-4b-instruct.nix { };
|
ollama-model = pkgs.callPackage ./qwen3-4b-instruct.nix { };
|
||||||
in
|
in
|
||||||
@@ -53,7 +53,7 @@ in
|
|||||||
pytest
|
pytest
|
||||||
pytest-xdist
|
pytest-xdist
|
||||||
(cli.pythonRuntime.pkgs.toPythonModule cli)
|
(cli.pythonRuntime.pkgs.toPythonModule cli)
|
||||||
self.legacyPackages.${pkgs.hostPlatform.system}.nixosTestLib
|
self.legacyPackages.${pkgs.stdenv.hostPlatform.system}.nixosTestLib
|
||||||
]
|
]
|
||||||
))
|
))
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cli = self.packages.${pkgs.hostPlatform.system}.clan-cli-full;
|
cli = self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli-full;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
name = "systemd-abstraction";
|
name = "systemd-abstraction";
|
||||||
|
|||||||
@@ -115,9 +115,9 @@
|
|||||||
let
|
let
|
||||||
closureInfo = pkgs.closureInfo {
|
closureInfo = pkgs.closureInfo {
|
||||||
rootPaths = [
|
rootPaths = [
|
||||||
self.packages.${pkgs.hostPlatform.system}.clan-cli
|
self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli
|
||||||
self.checks.${pkgs.hostPlatform.system}.clan-core-for-checks
|
self.checks.${pkgs.stdenv.hostPlatform.system}.clan-core-for-checks
|
||||||
self.clanInternals.machines.${pkgs.hostPlatform.system}.test-update-machine.config.system.build.toplevel
|
self.clanInternals.machines.${pkgs.stdenv.hostPlatform.system}.test-update-machine.config.system.build.toplevel
|
||||||
pkgs.stdenv.drvPath
|
pkgs.stdenv.drvPath
|
||||||
pkgs.bash.drvPath
|
pkgs.bash.drvPath
|
||||||
pkgs.buildPackages.xorg.lndir
|
pkgs.buildPackages.xorg.lndir
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
imports = [ self.nixosModules.test-update-machine ];
|
imports = [ self.nixosModules.test-update-machine ];
|
||||||
};
|
};
|
||||||
extraPythonPackages = _p: [
|
extraPythonPackages = _p: [
|
||||||
self.legacyPackages.${pkgs.hostPlatform.system}.nixosTestLib
|
self.legacyPackages.${pkgs.stdenv.hostPlatform.system}.nixosTestLib
|
||||||
];
|
];
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
# Prepare test flake and Nix store
|
# Prepare test flake and Nix store
|
||||||
flake_dir = prepare_test_flake(
|
flake_dir = prepare_test_flake(
|
||||||
temp_dir,
|
temp_dir,
|
||||||
"${self.checks.${pkgs.hostPlatform.system}.clan-core-for-checks}",
|
"${self.checks.${pkgs.stdenv.hostPlatform.system}.clan-core-for-checks}",
|
||||||
"${closureInfo}"
|
"${closureInfo}"
|
||||||
)
|
)
|
||||||
(flake_dir / ".clan-flake").write_text("") # Ensure .clan-flake exists
|
(flake_dir / ".clan-flake").write_text("") # Ensure .clan-flake exists
|
||||||
@@ -226,7 +226,7 @@
|
|||||||
"--to",
|
"--to",
|
||||||
"ssh://root@192.168.1.1",
|
"ssh://root@192.168.1.1",
|
||||||
"--no-check-sigs",
|
"--no-check-sigs",
|
||||||
f"${self.packages.${pkgs.hostPlatform.system}.clan-cli}",
|
f"${self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli}",
|
||||||
"--extra-experimental-features", "nix-command flakes",
|
"--extra-experimental-features", "nix-command flakes",
|
||||||
],
|
],
|
||||||
check=True,
|
check=True,
|
||||||
@@ -242,7 +242,7 @@
|
|||||||
"-o", "UserKnownHostsFile=/dev/null",
|
"-o", "UserKnownHostsFile=/dev/null",
|
||||||
"-o", "StrictHostKeyChecking=no",
|
"-o", "StrictHostKeyChecking=no",
|
||||||
f"root@192.168.1.1",
|
f"root@192.168.1.1",
|
||||||
"${self.packages.${pkgs.hostPlatform.system}.clan-cli}/bin/clan",
|
"${self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli}/bin/clan",
|
||||||
"machines",
|
"machines",
|
||||||
"update",
|
"update",
|
||||||
"--debug",
|
"--debug",
|
||||||
@@ -270,7 +270,7 @@
|
|||||||
|
|
||||||
# Run clan update command
|
# Run clan update command
|
||||||
subprocess.run([
|
subprocess.run([
|
||||||
"${self.packages.${pkgs.hostPlatform.system}.clan-cli-full}/bin/clan",
|
"${self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli-full}/bin/clan",
|
||||||
"machines",
|
"machines",
|
||||||
"update",
|
"update",
|
||||||
"--debug",
|
"--debug",
|
||||||
@@ -297,7 +297,7 @@
|
|||||||
|
|
||||||
# Run clan update command with --build-host
|
# Run clan update command with --build-host
|
||||||
subprocess.run([
|
subprocess.run([
|
||||||
"${self.packages.${pkgs.hostPlatform.system}.clan-cli-full}/bin/clan",
|
"${self.packages.${pkgs.stdenv.hostPlatform.system}.clan-cli-full}/bin/clan",
|
||||||
"machines",
|
"machines",
|
||||||
"update",
|
"update",
|
||||||
"--debug",
|
"--debug",
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
!!! Danger "Experimental"
|
||||||
|
This service is experimental and will change in the future.
|
||||||
|
|
||||||
This service sets up a certificate authority (CA) that can issue certificates to
|
This service sets up a certificate authority (CA) that can issue certificates to
|
||||||
other machines in your clan. For this the `ca` role is used.
|
other machines in your clan. For this the `ca` role is used.
|
||||||
It additionally provides a `default` role, that can be applied to all machines
|
It additionally provides a `default` role, that can be applied to all machines
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
!!! Danger "Experimental"
|
||||||
|
This service is experimental and will change in the future.
|
||||||
|
|
||||||
This module enables hosting clan-internal services easily, which can be resolved
|
This module enables hosting clan-internal services easily, which can be resolved
|
||||||
inside your VPN. This allows defining a custom top-level domain (e.g. `.clan`)
|
inside your VPN. This allows defining a custom top-level domain (e.g. `.clan`)
|
||||||
and exposing endpoints from a machine to others, which will be
|
and exposing endpoints from a machine to others, which will be
|
||||||
|
|||||||
@@ -1 +1,83 @@
|
|||||||
This a test README just to appease the eval warnings if we don't have one
|
!!! Danger "Experimental"
|
||||||
|
This service is for demonstration purpose only and may change in the future.
|
||||||
|
|
||||||
|
The Hello-World Clan Service is a minimal example showing how to build and register your own service.
|
||||||
|
|
||||||
|
It serves as a reference implementation and is used in clan-core CI tests to ensure compatibility.
|
||||||
|
|
||||||
|
## What it demonstrates
|
||||||
|
|
||||||
|
- How to define a basic Clan-compatible service.
|
||||||
|
- How to structure your service for discovery and configuration.
|
||||||
|
- How Clan services interact with nixos.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
This service demonstrates two levels of testing to ensure quality and stability across releases:
|
||||||
|
|
||||||
|
1. **Unit & Integration Testing** — via [`nix-unit`](https://github.com/nix-community/nix-unit)
|
||||||
|
2. **End-to-End Testing** — via **NixOS VM tests**, which we extended to support **container virtualization** for better performance.
|
||||||
|
|
||||||
|
We highly advocate following the [Practical Testing Pyramid](https://martinfowler.com/articles/practical-test-pyramid.html):
|
||||||
|
|
||||||
|
* Write **unit tests** for core logic and invariants.
|
||||||
|
* Add **one or two end-to-end (E2E)** tests to confirm your service starts and behaves correctly in a real NixOS environment.
|
||||||
|
|
||||||
|
NixOS is **untyped** and frequently changes; tests are the safest way to ensure long-term stability of services.
|
||||||
|
|
||||||
|
```
|
||||||
|
/ \
|
||||||
|
/ \
|
||||||
|
/ E2E \
|
||||||
|
/-------\
|
||||||
|
/ \
|
||||||
|
/Integration\
|
||||||
|
/-------------\
|
||||||
|
/ \
|
||||||
|
/ Unit Tests \
|
||||||
|
-------------------
|
||||||
|
```
|
||||||
|
|
||||||
|
### nix-unit
|
||||||
|
|
||||||
|
We highly advocate the usage of
|
||||||
|
|
||||||
|
[nix-unit](https://github.com/nix-community/nix-unit)
|
||||||
|
|
||||||
|
Example in: tests/eval-tests.nix
|
||||||
|
|
||||||
|
If you use flake-parts you can use the [native integration](https://flake.parts/options/nix-unit.html)
|
||||||
|
|
||||||
|
If nix-unit succeeds you'r nixos evaluation should be mostly correct.
|
||||||
|
|
||||||
|
!!! Tip
|
||||||
|
- Ensure most used 'settings' and variants are tested.
|
||||||
|
- Think about some important edge-cases your system should handle.
|
||||||
|
|
||||||
|
### NixOS VM / Container Test
|
||||||
|
|
||||||
|
!!! Warning "Early Vars & clanTest"
|
||||||
|
The testing system around vars is experimental
|
||||||
|
|
||||||
|
`clanTest` is still experimental and enables container virtualization by default.
|
||||||
|
This is still early and might have some limitations.
|
||||||
|
|
||||||
|
Some minimal boilerplate is needed to use `clanTest`
|
||||||
|
|
||||||
|
```nix
|
||||||
|
nixosLib = import (inputs.nixpkgs + "/nixos/lib") { }
|
||||||
|
nixosLib.runTest (
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
self.modules.nixosTest.clanTest
|
||||||
|
# Example in tests/vm/default.nix
|
||||||
|
testModule
|
||||||
|
];
|
||||||
|
hostPkgs = pkgs;
|
||||||
|
|
||||||
|
# Uncomment if you don't want or cannot use containers
|
||||||
|
# test.useContainers = false;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
{
|
{
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
manifest.name = "clan-core/hello-word";
|
manifest.name = "clan-core/hello-word";
|
||||||
manifest.description = "This is a test";
|
manifest.description = "Minimal example clan service that greets the world";
|
||||||
manifest.readme = builtins.readFile ./README.md;
|
manifest.readme = builtins.readFile ./README.md;
|
||||||
|
|
||||||
# This service provides two roles: "morning" and "evening". Roles can be
|
# This service provides two roles: "morning" and "evening". Roles can be
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ in
|
|||||||
# The hello-world service being tested
|
# The hello-world service being tested
|
||||||
../../clanServices/hello-world
|
../../clanServices/hello-world
|
||||||
# Required modules
|
# Required modules
|
||||||
../../nixosModules/clanCore
|
../../nixosModules
|
||||||
];
|
];
|
||||||
testName = "hello-world";
|
testName = "hello-world";
|
||||||
tests = ./tests/eval-tests.nix;
|
tests = ./tests/eval-tests.nix;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
testFlake = clanLib.clan {
|
testClan = clanLib.clan {
|
||||||
self = { };
|
self = { };
|
||||||
# Point to the folder of the module
|
# Point to the folder of the module
|
||||||
# TODO: make this optional
|
# TODO: make this optional
|
||||||
@@ -33,10 +33,20 @@ let
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_simple = {
|
/**
|
||||||
config = testFlake.config;
|
We highly advocate the usage of:
|
||||||
|
https://github.com/nix-community/nix-unit
|
||||||
|
|
||||||
expr = { };
|
If you use flake-parts you can use the native integration: https://flake.parts/options/nix-unit.html
|
||||||
expected = { };
|
*/
|
||||||
|
test_simple = {
|
||||||
|
# Allows inspection via the nix-repl
|
||||||
|
# Ignored by nix-unit; it only looks at 'expr' and 'expected'
|
||||||
|
inherit testClan;
|
||||||
|
|
||||||
|
# Assert that jon has the
|
||||||
|
# configured greeting in 'environment.etc.hello.text'
|
||||||
|
expr = testClan.config.nixosConfigurations.jon.config.environment.etc."hello".text;
|
||||||
|
expected = "Good evening World!";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
🚧🚧🚧 Experimental 🚧🚧🚧
|
!!! Danger "Experimental"
|
||||||
|
This service is experimental and will change in the future.
|
||||||
Use at your own risk.
|
|
||||||
|
|
||||||
We are still refining its interfaces, instability and breakages are expected.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
!!! Danger "Experimental"
|
||||||
|
This service is experimental and will change in the future.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
|
||||||
# Collect searchDomains from all servers in this instance
|
# Collect searchDomains from all servers in this instance
|
||||||
allServerSearchDomains = lib.flatten (
|
allServerSearchDomains = lib.flatten (
|
||||||
lib.mapAttrsToList (_name: machineConfig: machineConfig.settings.certificate.searchDomains or [ ]) (
|
lib.mapAttrsToList (_name: machineConfig: machineConfig.settings.certificate.searchDomains or [ ]) (
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
# Merge client's searchDomains with all servers' searchDomains
|
# Merge client's searchDomains with all servers' searchDomains
|
||||||
searchDomains = lib.uniqueStrings (settings.certificate.searchDomains ++ allServerSearchDomains);
|
searchDomains = uniqueStrings (settings.certificate.searchDomains ++ allServerSearchDomains);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
clan.core.vars.generators.openssh-ca = lib.mkIf (searchDomains != [ ]) {
|
clan.core.vars.generators.openssh-ca = lib.mkIf (searchDomains != [ ]) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ in
|
|||||||
../../clanServices/syncthing
|
../../clanServices/syncthing
|
||||||
# Required modules
|
# Required modules
|
||||||
../../nixosModules/clanCore
|
../../nixosModules/clanCore
|
||||||
|
../../nixosModules/machineModules
|
||||||
# Dependencies like clan-cli
|
# Dependencies like clan-cli
|
||||||
../../pkgs/clan-cli
|
../../pkgs/clan-cli
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
🚧🚧🚧 Experimental 🚧🚧🚧
|
!!! Danger "Experimental"
|
||||||
|
This service is experimental and will change in the future.
|
||||||
Use at your own risk.
|
|
||||||
|
|
||||||
We are still refining its interfaces, instability and breakages are expected.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ let
|
|||||||
# In this case it is 'self-zerotier-redux'
|
# In this case it is 'self-zerotier-redux'
|
||||||
# This is usually only used internally, but we can use it to test the evaluation of service module in isolation
|
# This is usually only used internally, but we can use it to test the evaluation of service module in isolation
|
||||||
# evaluatedService =
|
# evaluatedService =
|
||||||
# testFlake.clanInternals.inventoryClass.distributedServices.importedModulesEvaluated.self-zerotier-redux.config;
|
# testFlake.clanInternals.inventoryClass.distributedServices.servicesEval.config.mappedServices.self-zerotier-redux.config;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_simple = {
|
test_simple = {
|
||||||
inherit testFlake;
|
inherit testFlake;
|
||||||
|
|
||||||
expr =
|
expr =
|
||||||
testFlake.config.clan.clanInternals.inventoryClass.distributedServices.importedModulesEvaluated.self-wifi.config;
|
testFlake.config.clan.clanInternals.inventoryClass.distributedServices.servicesEval.config.mappedServices.self-wifi.config;
|
||||||
expected = 1;
|
expected = 1;
|
||||||
|
|
||||||
# expr = {
|
# expr = {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
🚧🚧🚧 Experimental 🚧🚧🚧
|
!!! Danger "Experimental"
|
||||||
|
This service is experimental and will change in the future.
|
||||||
Use at your own risk.
|
|
||||||
|
|
||||||
We are still refining its interfaces, instability and breakages are expected.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,9 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
|
||||||
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(import ./shared.nix {
|
(import ./shared.nix {
|
||||||
@@ -156,7 +159,7 @@
|
|||||||
config = {
|
config = {
|
||||||
systemd.services.zerotier-inventory-autoaccept =
|
systemd.services.zerotier-inventory-autoaccept =
|
||||||
let
|
let
|
||||||
machines = lib.uniqueStrings (
|
machines = uniqueStrings (
|
||||||
(lib.optionals (roles ? moon) (lib.attrNames roles.moon.machines))
|
(lib.optionals (roles ? moon) (lib.attrNames roles.moon.machines))
|
||||||
++ (lib.optionals (roles ? controller) (lib.attrNames roles.controller.machines))
|
++ (lib.optionals (roles ? controller) (lib.attrNames roles.controller.machines))
|
||||||
++ (lib.optionals (roles ? peer) (lib.attrNames roles.peer.machines))
|
++ (lib.optionals (roles ? peer) (lib.attrNames roles.peer.machines))
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ in
|
|||||||
../../clanServices/zerotier
|
../../clanServices/zerotier
|
||||||
# Required modules
|
# Required modules
|
||||||
../../nixosModules/clanCore
|
../../nixosModules/clanCore
|
||||||
|
../../nixosModules/machineModules
|
||||||
# Dependencies like clan-cli
|
# Dependencies like clan-cli
|
||||||
../../pkgs/clan-cli
|
../../pkgs/clan-cli
|
||||||
];
|
];
|
||||||
|
|||||||
12
devFlake/flake.lock
generated
12
devFlake/flake.lock
generated
@@ -105,11 +105,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-dev": {
|
"nixpkgs-dev": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1761544814,
|
"lastModified": 1762080734,
|
||||||
"narHash": "sha256-t5f0A+2MtSWTfA6hzMNiotpIMGLlSQF2JnK9m6nkzIY=",
|
"narHash": "sha256-fFunzA7ITlPHRr7dECaFGTBucNiWYEVDNPBw/9gFmII=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "e5aa45ed6c45058ec109658b2b7352a9a062cdf3",
|
"rev": "bc7f6fa86de9b208edf4ea7bbf40bcd8cc7d70a5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -128,11 +128,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760652422,
|
"lastModified": 1761730856,
|
||||||
"narHash": "sha256-C88Pgz38QIl9JxQceexqL2G7sw9vodHWx1Uaq+NRJrw=",
|
"narHash": "sha256-t1i5p/vSWwueZSC0Z2BImxx3BjoUDNKyC2mk24krcMY=",
|
||||||
"owner": "NuschtOS",
|
"owner": "NuschtOS",
|
||||||
"repo": "search",
|
"repo": "search",
|
||||||
"rev": "3ebeebe8b6a49dfb11f771f761e0310f7c48d726",
|
"rev": "e29de6db0cb3182e9aee75a3b1fd1919d995d85b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ Make sure you have the following:
|
|||||||
**Note:** This creates a new directory in your current location
|
**Note:** This creates a new directory in your current location
|
||||||
|
|
||||||
```shellSession
|
```shellSession
|
||||||
nix run https://git.clan.lol/clan/clan-core/archive/main.tar.gz#clan-cli --refresh -- flakes create
|
nix run "https://git.clan.lol/clan/clan-core/archive/main.tar.gz#clan-cli" --refresh -- flakes create
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Enter a **name** in the prompt:
|
3. Enter a **name** in the prompt:
|
||||||
|
|||||||
24
flake.lock
generated
24
flake.lock
generated
@@ -31,11 +31,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760701190,
|
"lastModified": 1761899396,
|
||||||
"narHash": "sha256-y7UhnWlER8r776JsySqsbTUh2Txf7K30smfHlqdaIQw=",
|
"narHash": "sha256-XOpKBp6HLzzMCbzW50TEuXN35zN5WGQREC7n34DcNMM=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "disko",
|
"repo": "disko",
|
||||||
"rev": "3a9450b26e69dcb6f8de6e2b07b3fc1c288d85f5",
|
"rev": "6f4cf5abbe318e4cd1e879506f6eeafd83f7b998",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -51,11 +51,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760948891,
|
"lastModified": 1762040540,
|
||||||
"narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=",
|
"narHash": "sha256-z5PlZ47j50VNF3R+IMS9LmzI5fYRGY/Z5O5tol1c9I4=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04",
|
"rev": "0010412d62a25d959151790968765a70c436598b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -71,11 +71,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1761339987,
|
"lastModified": 1762039661,
|
||||||
"narHash": "sha256-IUaawVwItZKi64IA6kF6wQCLCzpXbk2R46dHn8sHkig=",
|
"narHash": "sha256-oM5BwAGE78IBLZn+AqxwH/saqwq3e926rNq5HmOulkc=",
|
||||||
"owner": "nix-darwin",
|
"owner": "nix-darwin",
|
||||||
"repo": "nix-darwin",
|
"repo": "nix-darwin",
|
||||||
"rev": "7cd9aac79ee2924a85c211d21fafd394b06a38de",
|
"rev": "c3c8c9f2a5ed43175ac4dc030308756620e6e4e4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -115,10 +115,10 @@
|
|||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 315532800,
|
"lastModified": 315532800,
|
||||||
"narHash": "sha256-yDxtm0PESdgNetiJN5+MFxgubBcLDTiuSjjrJiyvsvM=",
|
"narHash": "sha256-LDT9wuUZtjPfmviCcVWif5+7j4kBI2mWaZwjNNeg4eg=",
|
||||||
"rev": "d7f52a7a640bc54c7bb414cca603835bf8dd4b10",
|
"rev": "a7fc11be66bdfb5cdde611ee5ce381c183da8386",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.11pre871443.d7f52a7a640b/nixexprs.tar.xz"
|
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.11pre887438.a7fc11be66bd/nixexprs.tar.xz"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
|
|||||||
@@ -39,32 +39,10 @@ in
|
|||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
clan-core.modules.clan.default
|
clan-core.modules.clan.default
|
||||||
{
|
|
||||||
checks.minNixpkgsVersion = {
|
|
||||||
assertion = lib.versionAtLeast nixpkgs.lib.version "25.11";
|
|
||||||
message = ''
|
|
||||||
Nixpkgs version: ${nixpkgs.lib.version} is incompatible with clan-core. (>= 25.11 is recommended)
|
|
||||||
---
|
|
||||||
Your version of 'nixpkgs' seems too old for clan-core.
|
|
||||||
Please read: https://docs.clan.lol/guides/nixpkgs-flake-input
|
|
||||||
|
|
||||||
You can ignore this check by setting:
|
|
||||||
clan.checks.minNixpkgsVersion.ignore = true;
|
|
||||||
---
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
apply =
|
# Important: !This logic needs to be kept in sync with lib.clan function!
|
||||||
config:
|
apply = config: clan-core.lib.checkConfig config.checks config;
|
||||||
lib.deepSeq (lib.mapAttrs (
|
|
||||||
id: check:
|
|
||||||
if check.ignore || check.assertion then
|
|
||||||
null
|
|
||||||
else
|
|
||||||
throw "clan.checks.${id} failed with message\n${check.message}"
|
|
||||||
) config.checks) config;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Mapped flake toplevel outputs
|
# Mapped flake toplevel outputs
|
||||||
|
|||||||
19
lib/clan/checkConfig.nix
Normal file
19
lib/clan/checkConfig.nix
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{ lib, ... }:
|
||||||
|
/**
|
||||||
|
Function to assert clan configuration checks.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
- 'checks' attribute of clan configuration
|
||||||
|
- Any: the returned configuration (can be anything, is just passed through)
|
||||||
|
*/
|
||||||
|
checks:
|
||||||
|
lib.deepSeq (
|
||||||
|
lib.mapAttrs (
|
||||||
|
id: check:
|
||||||
|
if check.ignore || check.assertion then
|
||||||
|
null
|
||||||
|
else
|
||||||
|
throw "clan.checks.${id} failed with message\n${check.message}"
|
||||||
|
) checks
|
||||||
|
)
|
||||||
@@ -33,8 +33,8 @@
|
|||||||
let
|
let
|
||||||
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
||||||
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
||||||
in
|
configuration = (
|
||||||
lib.evalModules {
|
lib.evalModules {
|
||||||
class = "clan";
|
class = "clan";
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit
|
inherit
|
||||||
@@ -49,4 +49,7 @@ lib.evalModules {
|
|||||||
clan-core.modules.clan.default
|
clan-core.modules.clan.default
|
||||||
m
|
m
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
clan-core.clanLib.checkConfig configuration.config.checks configuration
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ lib.fix (
|
|||||||
*/
|
*/
|
||||||
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
||||||
|
|
||||||
|
checkConfig = clanLib.callLib ./clan/checkConfig.nix { };
|
||||||
|
|
||||||
evalService = clanLib.callLib ./evalService.nix { };
|
evalService = clanLib.callLib ./evalService.nix { };
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# ClanLib functions
|
# ClanLib functions
|
||||||
|
|||||||
@@ -53,7 +53,12 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}).clan
|
}).clan
|
||||||
{ config.directory = rootPath; };
|
{
|
||||||
|
directory = rootPath;
|
||||||
|
self = {
|
||||||
|
inputs.nixpkgs.lib.version = "25.11";
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit vclan;
|
inherit vclan;
|
||||||
@@ -94,7 +99,12 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}).clan
|
}).clan
|
||||||
{ config.directory = rootPath; };
|
{
|
||||||
|
directory = rootPath;
|
||||||
|
self = {
|
||||||
|
inputs.nixpkgs.lib.version = "25.11";
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit vclan;
|
inherit vclan;
|
||||||
|
|||||||
@@ -2,11 +2,7 @@
|
|||||||
lib,
|
lib,
|
||||||
clanLib,
|
clanLib,
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
inherit (services) mapInstances;
|
|
||||||
inventoryModule = {
|
inventoryModule = {
|
||||||
_file = "clanLib.inventory.module";
|
_file = "clanLib.inventory.module";
|
||||||
imports = [
|
imports = [
|
||||||
|
|||||||
@@ -28,19 +28,15 @@ in
|
|||||||
elemType = submoduleWith {
|
elemType = submoduleWith {
|
||||||
class = "clan.service";
|
class = "clan.service";
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
exports = config.exports;
|
|
||||||
directory = directory;
|
directory = directory;
|
||||||
clanLib = specialArgs.clanLib;
|
clanLib = specialArgs.clanLib;
|
||||||
|
exports = config.exports;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
(
|
(
|
||||||
{ name, ... }:
|
{ name, ... }:
|
||||||
{
|
{
|
||||||
_module.args._ctx = [ name ];
|
_module.args._ctx = [ name ];
|
||||||
_module.args.clanLib = specialArgs.clanLib;
|
|
||||||
_module.args.exports = config.exports;
|
|
||||||
_module.args.directory = directory;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
./service-module.nix
|
./service-module.nix
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ in
|
|||||||
../../../flakeModules
|
../../../flakeModules
|
||||||
../../../lib
|
../../../lib
|
||||||
../../../nixosModules/clanCore
|
../../../nixosModules/clanCore
|
||||||
|
../../../nixosModules/machineModules
|
||||||
../../../machines
|
../../../machines
|
||||||
../../../inventory.json
|
../../../inventory.json
|
||||||
../../../modules
|
../../../modules
|
||||||
|
|||||||
@@ -1,171 +0,0 @@
|
|||||||
# Adapter function between the inventory.instances and the clan.service module
|
|
||||||
#
|
|
||||||
# Data flow:
|
|
||||||
# - inventory.instances -> Adapter -> clan.service module -> Service Resources (i.e. NixosModules per Machine, Vars per Service, etc.)
|
|
||||||
#
|
|
||||||
# What this file does:
|
|
||||||
#
|
|
||||||
# - Resolves the [Module] to an actual module-path and imports it.
|
|
||||||
# - Groups together all the same modules into a single import and creates all instances for it.
|
|
||||||
# - Resolves the inventory tags into machines. Tags don't exist at the service level.
|
|
||||||
# Also combines the settings for 'machines' and 'tags'.
|
|
||||||
{
|
|
||||||
lib,
|
|
||||||
clanLib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
mapInstances =
|
|
||||||
{
|
|
||||||
# This is used to resolve the module imports from 'flake.inputs'
|
|
||||||
flakeInputs,
|
|
||||||
# The clan inventory
|
|
||||||
inventory,
|
|
||||||
directory,
|
|
||||||
clanCoreModules,
|
|
||||||
prefix ? [ ],
|
|
||||||
exportsModule,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
# machineHasTag = machineName: tagName: lib.elem tagName inventory.machines.${machineName}.tags;
|
|
||||||
|
|
||||||
# map the instances into the module
|
|
||||||
importedModuleWithInstances = lib.mapAttrs (
|
|
||||||
instanceName: instance:
|
|
||||||
let
|
|
||||||
resolvedModule = clanLib.resolveModule {
|
|
||||||
moduleSpec = instance.module;
|
|
||||||
inherit flakeInputs clanCoreModules;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Every instance includes machines via roles
|
|
||||||
# :: { client :: ... }
|
|
||||||
instanceRoles = lib.mapAttrs (
|
|
||||||
roleName: role:
|
|
||||||
let
|
|
||||||
resolvedMachines = clanLib.inventory.resolveTags {
|
|
||||||
members = {
|
|
||||||
# Explicit members
|
|
||||||
machines = lib.attrNames role.machines;
|
|
||||||
# Resolved Members
|
|
||||||
tags = lib.attrNames role.tags;
|
|
||||||
};
|
|
||||||
inherit (inventory) machines;
|
|
||||||
inherit instanceName roleName;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
# instances.<instanceName>.roles.<roleName> =
|
|
||||||
# Remove "tags", they are resolved into "machines"
|
|
||||||
(removeAttrs role [ "tags" ])
|
|
||||||
// {
|
|
||||||
machines = lib.genAttrs resolvedMachines.machines (
|
|
||||||
machineName:
|
|
||||||
let
|
|
||||||
machineSettings = instance.roles.${roleName}.machines.${machineName}.settings or { };
|
|
||||||
in
|
|
||||||
# TODO: tag settings
|
|
||||||
# Wait for this feature until option introspection for 'settings' is done.
|
|
||||||
# This might get too complex to handle otherwise.
|
|
||||||
# settingsViaTags = lib.filterAttrs (
|
|
||||||
# tagName: _: machineHasTag machineName tagName
|
|
||||||
# ) instance.roles.${roleName}.tags;
|
|
||||||
{
|
|
||||||
# TODO: Do we want to wrap settings with
|
|
||||||
# setDefaultModuleLocation "inventory.instances.${instanceName}.roles.${roleName}.tags.${tagName}";
|
|
||||||
settings = {
|
|
||||||
imports = [
|
|
||||||
machineSettings
|
|
||||||
]; # ++ lib.attrValues (lib.mapAttrs (_tagName: v: v.settings) settingsViaTags);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
) instance.roles;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit (instance) module;
|
|
||||||
inherit resolvedModule instanceRoles;
|
|
||||||
}
|
|
||||||
) inventory.instances or { };
|
|
||||||
|
|
||||||
# Group the instances by the module they resolve to
|
|
||||||
# This is necessary to evaluate the module in a single pass
|
|
||||||
# :: { <module.input>_<module.name> :: [ { name, value } ] }
|
|
||||||
# Since 'perMachine' needs access to all the instances we should include them as a whole
|
|
||||||
grouped = lib.foldlAttrs (
|
|
||||||
acc: instanceName: instance:
|
|
||||||
let
|
|
||||||
inputName = if instance.module.input == null then "<clan-core>" else instance.module.input;
|
|
||||||
id = inputName + "-" + instance.module.name;
|
|
||||||
in
|
|
||||||
acc
|
|
||||||
// {
|
|
||||||
${id} = acc.${id} or [ ] ++ [
|
|
||||||
{
|
|
||||||
inherit instanceName instance;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
) { } importedModuleWithInstances;
|
|
||||||
|
|
||||||
# servicesEval.config.mappedServices.self-A.result.final.jon.nixosModule
|
|
||||||
allMachines = lib.mapAttrs (machineName: _: {
|
|
||||||
# This is the list of nixosModules for each machine
|
|
||||||
machineImports = lib.foldlAttrs (
|
|
||||||
acc: _module_ident: serviceModule:
|
|
||||||
acc ++ [ serviceModule.result.final.${machineName}.nixosModule or { } ]
|
|
||||||
) [ ] servicesEval.config.mappedServices;
|
|
||||||
}) inventory.machines or { };
|
|
||||||
|
|
||||||
evalServices =
|
|
||||||
{ modules, prefix }:
|
|
||||||
lib.evalModules {
|
|
||||||
class = "clan";
|
|
||||||
specialArgs = {
|
|
||||||
inherit clanLib;
|
|
||||||
_ctx = prefix;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
(import ./all-services-wrapper.nix { inherit directory; })
|
|
||||||
]
|
|
||||||
++ modules;
|
|
||||||
};
|
|
||||||
|
|
||||||
servicesEval = evalServices {
|
|
||||||
inherit prefix;
|
|
||||||
modules = [
|
|
||||||
{
|
|
||||||
inherit exportsModule;
|
|
||||||
mappedServices = lib.mapAttrs (_module_ident: instances: {
|
|
||||||
imports = [
|
|
||||||
# Import the resolved module.
|
|
||||||
# i.e. clan.modules.admin
|
|
||||||
{
|
|
||||||
options.module = lib.mkOption {
|
|
||||||
type = lib.types.raw;
|
|
||||||
default = (builtins.head instances).instance.module;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
(builtins.head instances).instance.resolvedModule
|
|
||||||
] # Include all the instances that correlate to the resolved module
|
|
||||||
++ (builtins.map (v: {
|
|
||||||
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
|
||||||
}) instances);
|
|
||||||
}) grouped;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
importedModulesEvaluated = servicesEval.config.mappedServices;
|
|
||||||
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit
|
|
||||||
servicesEval
|
|
||||||
importedModuleWithInstances
|
|
||||||
# Exposed for testing
|
|
||||||
grouped
|
|
||||||
allMachines
|
|
||||||
importedModulesEvaluated
|
|
||||||
;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -7,10 +7,14 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types uniqueStrings;
|
inherit (lib) mkOption types;
|
||||||
inherit (types) attrsWith submoduleWith;
|
inherit (types) attrsWith submoduleWith;
|
||||||
|
|
||||||
errorContext = "Error context: ${lib.concatStringsSep "." _ctx}";
|
errorContext = "Error context: ${lib.concatStringsSep "." _ctx}";
|
||||||
|
# TODO:
|
||||||
|
# Remove once this gets merged upstream; performs in O(n*log(n) instead of O(n^2))
|
||||||
|
# https://github.com/NixOS/nixpkgs/pull/355616/files
|
||||||
|
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
|
||||||
/**
|
/**
|
||||||
Merges the role- and machine-settings using the role interface
|
Merges the role- and machine-settings using the role interface
|
||||||
|
|
||||||
|
|||||||
@@ -4,36 +4,8 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
|
||||||
evalModules
|
|
||||||
;
|
|
||||||
|
|
||||||
evalInventory =
|
|
||||||
m:
|
|
||||||
(evalModules {
|
|
||||||
# Static modules
|
|
||||||
modules = [
|
|
||||||
clanLib.inventory.inventoryModule
|
|
||||||
{
|
|
||||||
_file = "test file";
|
|
||||||
tags.all = [ ];
|
|
||||||
tags.nixos = [ ];
|
|
||||||
tags.darwin = [ ];
|
|
||||||
}
|
|
||||||
{
|
|
||||||
modules.test = { };
|
|
||||||
}
|
|
||||||
m
|
|
||||||
];
|
|
||||||
}).config;
|
|
||||||
|
|
||||||
callInventoryAdapter =
|
|
||||||
inventoryModule:
|
|
||||||
let
|
|
||||||
inventory = evalInventory inventoryModule;
|
|
||||||
flakeInputsFixture = {
|
flakeInputsFixture = {
|
||||||
self.clan.modules = inventoryModule.modules or { };
|
|
||||||
# Example upstream module
|
|
||||||
upstream.clan.modules = {
|
upstream.clan.modules = {
|
||||||
uzzi = {
|
uzzi = {
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
@@ -43,24 +15,42 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
|
||||||
clanLib.inventory.mapInstances {
|
createTestClan =
|
||||||
directory = ./.;
|
testClan:
|
||||||
clanCoreModules = { };
|
let
|
||||||
flakeInputs = flakeInputsFixture;
|
res = clanLib.clan ({
|
||||||
inherit inventory;
|
# Static / mocked
|
||||||
exportsModule = { };
|
specialArgs = {
|
||||||
|
clan-core = {
|
||||||
|
clan.modules = { };
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
self.inputs = flakeInputsFixture // {
|
||||||
|
self.clan = res.config;
|
||||||
|
};
|
||||||
|
directory = ./.;
|
||||||
|
exportsModule = { };
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
testClan
|
||||||
|
];
|
||||||
|
});
|
||||||
|
in
|
||||||
|
res;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
extraModules = import ./extraModules.nix { inherit clanLib; };
|
extraModules = import ./extraModules.nix { inherit clanLib; };
|
||||||
exports = import ./exports.nix { inherit lib clanLib; };
|
exports = import ./exports.nix { inherit lib clanLib; };
|
||||||
settings = import ./settings.nix { inherit lib callInventoryAdapter; };
|
settings = import ./settings.nix { inherit lib createTestClan; };
|
||||||
specialArgs = import ./specialArgs.nix { inherit lib callInventoryAdapter; };
|
specialArgs = import ./specialArgs.nix { inherit lib createTestClan; };
|
||||||
resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; };
|
resolve_module_spec = import ./import_module_spec.nix {
|
||||||
|
inherit lib createTestClan;
|
||||||
|
};
|
||||||
test_simple =
|
test_simple =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -71,7 +61,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
# User config
|
# User config
|
||||||
instances."instance_foo" = {
|
inventory.instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "simple-module";
|
name = "simple-module";
|
||||||
};
|
};
|
||||||
@@ -81,7 +71,7 @@ in
|
|||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = res.importedModulesEvaluated ? "<clan-core>-simple-module";
|
expr = res.config._services.mappedServices ? "<clan-core>-simple-module";
|
||||||
expected = true;
|
expected = true;
|
||||||
inherit res;
|
inherit res;
|
||||||
};
|
};
|
||||||
@@ -92,7 +82,7 @@ in
|
|||||||
# All instances should be included within one evaluation to make all of them available
|
# All instances should be included within one evaluation to make all of them available
|
||||||
test_module_grouping =
|
test_module_grouping =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -112,18 +102,19 @@ in
|
|||||||
|
|
||||||
perMachine = { }: { };
|
perMachine = { }: { };
|
||||||
};
|
};
|
||||||
|
|
||||||
# User config
|
# User config
|
||||||
instances."instance_foo" = {
|
inventory.instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
instances."instance_bar" = {
|
inventory.instances."instance_bar" = {
|
||||||
module = {
|
module = {
|
||||||
name = "B";
|
name = "B";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
instances."instance_baz" = {
|
inventory.instances."instance_baz" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
};
|
};
|
||||||
@@ -133,16 +124,16 @@ in
|
|||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.mapAttrs (_n: v: builtins.length v) res.grouped;
|
expr = lib.attrNames res.config._services.mappedServices;
|
||||||
expected = {
|
expected = [
|
||||||
"<clan-core>-A" = 2;
|
"<clan-core>-A"
|
||||||
"<clan-core>-B" = 1;
|
"<clan-core>-B"
|
||||||
};
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
test_creates_all_instances =
|
test_creates_all_instances =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -154,6 +145,7 @@ in
|
|||||||
|
|
||||||
perMachine = { }: { };
|
perMachine = { }: { };
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
@@ -173,11 +165,12 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.attrNames res.importedModulesEvaluated.self-A.instances;
|
expr = lib.attrNames res.config._services.mappedServices.self-A.instances;
|
||||||
expected = [
|
expected = [
|
||||||
"instance_bar"
|
"instance_bar"
|
||||||
"instance_foo"
|
"instance_foo"
|
||||||
@@ -187,7 +180,7 @@ in
|
|||||||
# Membership via roles
|
# Membership via roles
|
||||||
test_add_machines_directly =
|
test_add_machines_directly =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -202,6 +195,7 @@ in
|
|||||||
|
|
||||||
# perMachine = {}: {};
|
# perMachine = {}: {};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = { };
|
jon = { };
|
||||||
sara = { };
|
sara = { };
|
||||||
@@ -229,11 +223,12 @@ in
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.attrNames res.importedModulesEvaluated.self-A.result.allMachines;
|
expr = lib.attrNames res.config._services.mappedServices.self-A.result.allMachines;
|
||||||
expected = [
|
expected = [
|
||||||
"jon"
|
"jon"
|
||||||
"sara"
|
"sara"
|
||||||
@@ -243,7 +238,7 @@ in
|
|||||||
# Membership via tags
|
# Membership via tags
|
||||||
test_add_machines_via_tags =
|
test_add_machines_via_tags =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -257,6 +252,7 @@ in
|
|||||||
|
|
||||||
# perMachine = {}: {};
|
# perMachine = {}: {};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = {
|
jon = {
|
||||||
tags = [ "foo" ];
|
tags = [ "foo" ];
|
||||||
@@ -281,11 +277,12 @@ in
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.attrNames res.importedModulesEvaluated.self-A.result.allMachines;
|
expr = lib.attrNames res.config._services.mappedServices.self-A.result.allMachines;
|
||||||
expected = [
|
expected = [
|
||||||
"jon"
|
"jon"
|
||||||
"sara"
|
"sara"
|
||||||
@@ -293,6 +290,9 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
machine_imports = import ./machine_imports.nix { inherit lib clanLib; };
|
machine_imports = import ./machine_imports.nix { inherit lib clanLib; };
|
||||||
per_machine_args = import ./per_machine_args.nix { inherit lib callInventoryAdapter; };
|
per_machine_args = import ./per_machine_args.nix { inherit lib createTestClan; };
|
||||||
per_instance_args = import ./per_instance_args.nix { inherit lib callInventoryAdapter; };
|
per_instance_args = import ./per_instance_args.nix {
|
||||||
|
inherit lib;
|
||||||
|
callInventoryAdapter = createTestClan;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ callInventoryAdapter, ... }:
|
{ createTestClan, ... }:
|
||||||
let
|
let
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
@@ -23,12 +23,15 @@ let
|
|||||||
|
|
||||||
resolve =
|
resolve =
|
||||||
spec:
|
spec:
|
||||||
callInventoryAdapter {
|
createTestClan {
|
||||||
inherit modules machines;
|
inherit modules;
|
||||||
|
inventory = {
|
||||||
|
inherit machines;
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = spec;
|
module = spec;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_import_local_module_by_name = {
|
test_import_local_module_by_name = {
|
||||||
@@ -36,25 +39,16 @@ in
|
|||||||
(resolve {
|
(resolve {
|
||||||
name = "A";
|
name = "A";
|
||||||
input = "self";
|
input = "self";
|
||||||
}).importedModuleWithInstances.instance_foo.resolvedModule;
|
}).config._services.mappedServices.self-A.manifest.name;
|
||||||
expected = {
|
expected = "network";
|
||||||
_class = "clan.service";
|
|
||||||
manifest = {
|
|
||||||
name = "network";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
test_import_remote_module_by_name = {
|
test_import_remote_module_by_name = {
|
||||||
expr =
|
expr =
|
||||||
(resolve {
|
(resolve {
|
||||||
name = "uzzi";
|
name = "uzzi";
|
||||||
input = "upstream";
|
input = "upstream";
|
||||||
}).importedModuleWithInstances.instance_foo.resolvedModule;
|
}).config._services.mappedServices.upstream-uzzi.manifest.name;
|
||||||
expected = {
|
expected = "uzzi-from-upstream";
|
||||||
_class = "clan.service";
|
|
||||||
manifest = {
|
|
||||||
name = "uzzi-from-upstream";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ let
|
|||||||
sara = { };
|
sara = { };
|
||||||
};
|
};
|
||||||
res = callInventoryAdapter {
|
res = callInventoryAdapter {
|
||||||
inherit modules machines;
|
inherit modules;
|
||||||
|
|
||||||
|
inventory = {
|
||||||
|
inherit machines;
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
@@ -93,6 +96,7 @@ let
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1 { imports = [ { instanceName = "instance_foo"; machine = { name = "jon"; roles = [ "controller" "pe 1 null
|
1 { imports = [ { instanceName = "instance_foo"; machine = { name = "jon"; roles = [ "controller" "pe 1 null
|
||||||
@@ -105,9 +109,10 @@ in
|
|||||||
{
|
{
|
||||||
# settings should evaluate
|
# settings should evaluate
|
||||||
test_per_instance_arguments = {
|
test_per_instance_arguments = {
|
||||||
|
inherit res;
|
||||||
expr = {
|
expr = {
|
||||||
instanceName =
|
instanceName =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances."instance_foo".allMachines.jon.passthru.instanceName;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances."instance_foo".allMachines.jon.passthru.instanceName;
|
||||||
|
|
||||||
# settings are specific.
|
# settings are specific.
|
||||||
# Below we access:
|
# Below we access:
|
||||||
@@ -115,11 +120,11 @@ in
|
|||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = jon
|
# machines = jon
|
||||||
settings =
|
settings =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.settings;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.settings;
|
||||||
machine =
|
machine =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.machine;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.machine;
|
||||||
roles =
|
roles =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.roles;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.roles;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
instanceName = "instance_foo";
|
instanceName = "instance_foo";
|
||||||
@@ -160,9 +165,9 @@ in
|
|||||||
|
|
||||||
# TODO: Cannot be tested like this anymore
|
# TODO: Cannot be tested like this anymore
|
||||||
test_per_instance_settings_vendoring = {
|
test_per_instance_settings_vendoring = {
|
||||||
x = res.importedModulesEvaluated.self-A;
|
x = res.config._services.mappedServices.self-A;
|
||||||
expr =
|
expr =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.vendoredSettings;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.vendoredSettings;
|
||||||
expected = {
|
expected = {
|
||||||
timeout = "config.thing";
|
timeout = "config.thing";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ lib, callInventoryAdapter }:
|
{ lib, createTestClan }:
|
||||||
let
|
let
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
@@ -39,8 +39,11 @@ let
|
|||||||
jon = { };
|
jon = { };
|
||||||
sara = { };
|
sara = { };
|
||||||
};
|
};
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
inherit modules machines;
|
inherit modules;
|
||||||
|
inventory = {
|
||||||
|
|
||||||
|
inherit machines;
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
@@ -70,6 +73,7 @@ let
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -79,7 +83,7 @@ in
|
|||||||
inherit res;
|
inherit res;
|
||||||
expr = {
|
expr = {
|
||||||
hasMachineSettings =
|
hasMachineSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon
|
||||||
? settings;
|
? settings;
|
||||||
|
|
||||||
# settings are specific.
|
# settings are specific.
|
||||||
@@ -88,10 +92,10 @@ in
|
|||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = jon
|
# machines = jon
|
||||||
specificMachineSettings =
|
specificMachineSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon.settings;
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon.settings;
|
||||||
|
|
||||||
hasRoleSettings =
|
hasRoleSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer
|
||||||
? settings;
|
? settings;
|
||||||
|
|
||||||
# settings are specific.
|
# settings are specific.
|
||||||
@@ -100,7 +104,7 @@ in
|
|||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = *
|
# machines = *
|
||||||
specificRoleSettings =
|
specificRoleSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer;
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
hasMachineSettings = true;
|
hasMachineSettings = true;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{ callInventoryAdapter, lib, ... }:
|
{ createTestClan, lib, ... }:
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
modules."A" = {
|
modules."A" = {
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
manifest = {
|
manifest = {
|
||||||
@@ -21,6 +21,8 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
|
|
||||||
machines = {
|
machines = {
|
||||||
jon = { };
|
jon = { };
|
||||||
sara = { };
|
sara = { };
|
||||||
@@ -41,8 +43,9 @@ let
|
|||||||
roles.peer.machines.sara = { };
|
roles.peer.machines.sara = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config = res.servicesEval.config.mappedServices.self-A;
|
config = res.config._services.mappedServices.self-A;
|
||||||
|
|
||||||
#
|
#
|
||||||
applySettings =
|
applySettings =
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{ callInventoryAdapter, lib, ... }:
|
{ createTestClan, lib, ... }:
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
modules."A" = m: {
|
modules."A" = m: {
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
config = {
|
config = {
|
||||||
@@ -14,6 +14,7 @@ let
|
|||||||
default = m;
|
default = m;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = { };
|
jon = { };
|
||||||
};
|
};
|
||||||
@@ -25,8 +26,9 @@ let
|
|||||||
roles.peer.machines.jon = { };
|
roles.peer.machines.jon = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
specialArgs = lib.attrNames res.servicesEval.config.mappedServices.self-A.test.specialArgs;
|
specialArgs = lib.attrNames res.config._services.mappedServices.self-A.test.specialArgs;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_simple = {
|
test_simple = {
|
||||||
|
|||||||
@@ -212,6 +212,36 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test_clan_check_simple_fail =
|
||||||
|
let
|
||||||
|
eval = clan {
|
||||||
|
checks.constFail = {
|
||||||
|
assertion = false;
|
||||||
|
message = "This is a constant failure";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
result = eval;
|
||||||
|
expr = eval.config;
|
||||||
|
expectedError.type = "ThrownError";
|
||||||
|
expectedError.msg = "This is a constant failure";
|
||||||
|
};
|
||||||
|
test_clan_check_simple_pass =
|
||||||
|
let
|
||||||
|
eval = clan {
|
||||||
|
checks.constFail = {
|
||||||
|
assertion = true;
|
||||||
|
message = "This is a constant success";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
result = eval;
|
||||||
|
expr = lib.seq eval.config 42;
|
||||||
|
expected = 42;
|
||||||
|
};
|
||||||
|
|
||||||
test_get_var_machine =
|
test_get_var_machine =
|
||||||
let
|
let
|
||||||
varsLib = import ./vars.nix { };
|
varsLib = import ./vars.nix { };
|
||||||
|
|||||||
16
modules/clan/checks.nix
Normal file
16
modules/clan/checks.nix
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{ lib, nixpkgs, ... }:
|
||||||
|
{
|
||||||
|
checks.minNixpkgsVersion = {
|
||||||
|
assertion = lib.versionAtLeast nixpkgs.lib.version "25.11";
|
||||||
|
message = ''
|
||||||
|
Nixpkgs version: ${nixpkgs.lib.version} is incompatible with clan-core. (>= 25.11 is recommended)
|
||||||
|
---
|
||||||
|
Your version of 'nixpkgs' seems too old for clan-core.
|
||||||
|
Please read: https://docs.clan.lol/guides/nixpkgs-flake-input
|
||||||
|
|
||||||
|
You can ignore this check by setting:
|
||||||
|
clan.checks.minNixpkgsVersion.ignore = true;
|
||||||
|
---
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/**
|
||||||
|
Root 'clan' Module
|
||||||
|
|
||||||
|
Defines lib.clan and flake-parts.clan options
|
||||||
|
and all common logic for the 'clan' module.
|
||||||
|
|
||||||
|
- has Class _class = "clan"
|
||||||
|
|
||||||
|
- _module.args.clan-core: reference to clan-core flake
|
||||||
|
- _module.args.clanLib: reference to lib.clan function
|
||||||
|
*/
|
||||||
{ clan-core }:
|
{ clan-core }:
|
||||||
{
|
{
|
||||||
_class = "clan";
|
_class = "clan";
|
||||||
@@ -6,7 +17,9 @@
|
|||||||
inherit (clan-core) clanLib;
|
inherit (clan-core) clanLib;
|
||||||
};
|
};
|
||||||
imports = [
|
imports = [
|
||||||
|
./top-level-interface.nix
|
||||||
./module.nix
|
./module.nix
|
||||||
./interface.nix
|
./distributed-services.nix
|
||||||
|
./checks.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
163
modules/clan/distributed-services.nix
Normal file
163
modules/clan/distributed-services.nix
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
clanLib,
|
||||||
|
config,
|
||||||
|
clan-core,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
# Keep a reference to top-level
|
||||||
|
clanConfig = config;
|
||||||
|
|
||||||
|
inventory = clanConfig.inventory;
|
||||||
|
flakeInputs = clanConfig.self.inputs;
|
||||||
|
clanCoreModules = clan-core.clan.modules;
|
||||||
|
|
||||||
|
grouped = lib.foldlAttrs (
|
||||||
|
acc: instanceName: instance:
|
||||||
|
let
|
||||||
|
inputName = if instance.module.input == null then "<clan-core>" else instance.module.input;
|
||||||
|
id = inputName + "-" + instance.module.name;
|
||||||
|
in
|
||||||
|
acc
|
||||||
|
// {
|
||||||
|
${id} = acc.${id} or [ ] ++ [
|
||||||
|
{
|
||||||
|
inherit instanceName instance;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
) { } importedModuleWithInstances;
|
||||||
|
|
||||||
|
importedModuleWithInstances = lib.mapAttrs (
|
||||||
|
instanceName: instance:
|
||||||
|
let
|
||||||
|
resolvedModule = clanLib.resolveModule {
|
||||||
|
moduleSpec = instance.module;
|
||||||
|
inherit flakeInputs clanCoreModules;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Every instance includes machines via roles
|
||||||
|
# :: { client :: ... }
|
||||||
|
instanceRoles = lib.mapAttrs (
|
||||||
|
roleName: role:
|
||||||
|
let
|
||||||
|
resolvedMachines = clanLib.inventory.resolveTags {
|
||||||
|
members = {
|
||||||
|
# Explicit members
|
||||||
|
machines = lib.attrNames role.machines;
|
||||||
|
# Resolved Members
|
||||||
|
tags = lib.attrNames role.tags;
|
||||||
|
};
|
||||||
|
inherit (inventory) machines;
|
||||||
|
inherit instanceName roleName;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
# instances.<instanceName>.roles.<roleName> =
|
||||||
|
# Remove "tags", they are resolved into "machines"
|
||||||
|
(removeAttrs role [ "tags" ])
|
||||||
|
// {
|
||||||
|
machines = lib.genAttrs resolvedMachines.machines (
|
||||||
|
machineName:
|
||||||
|
let
|
||||||
|
machineSettings = instance.roles.${roleName}.machines.${machineName}.settings or { };
|
||||||
|
in
|
||||||
|
# TODO: tag settings
|
||||||
|
# Wait for this feature until option introspection for 'settings' is done.
|
||||||
|
# This might get too complex to handle otherwise.
|
||||||
|
# settingsViaTags = lib.filterAttrs (
|
||||||
|
# tagName: _: machineHasTag machineName tagName
|
||||||
|
# ) instance.roles.${roleName}.tags;
|
||||||
|
{
|
||||||
|
# TODO: Do we want to wrap settings with
|
||||||
|
# setDefaultModuleLocation "inventory.instances.${instanceName}.roles.${roleName}.tags.${tagName}";
|
||||||
|
settings = {
|
||||||
|
imports = [
|
||||||
|
machineSettings
|
||||||
|
]; # ++ lib.attrValues (lib.mapAttrs (_tagName: v: v.settings) settingsViaTags);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
) instance.roles;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit (instance) module;
|
||||||
|
inherit resolvedModule instanceRoles;
|
||||||
|
}
|
||||||
|
) inventory.instances or { };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
_class = "clan";
|
||||||
|
options._services = mkOption {
|
||||||
|
visible = false;
|
||||||
|
description = ''
|
||||||
|
All service instances
|
||||||
|
|
||||||
|
!!! Danger "Internal API"
|
||||||
|
Do not rely on this API yet.
|
||||||
|
|
||||||
|
- Will be renamed to just 'services' in the future.
|
||||||
|
Once the name can be claimed again.
|
||||||
|
- Structure will change.
|
||||||
|
|
||||||
|
API will be declared as public after beeing simplified.
|
||||||
|
'';
|
||||||
|
type = types.submoduleWith {
|
||||||
|
# TODO: Remove specialArgs
|
||||||
|
specialArgs = {
|
||||||
|
inherit clanLib;
|
||||||
|
};
|
||||||
|
modules = [
|
||||||
|
(import ../../lib/inventory/distributed-service/all-services-wrapper.nix {
|
||||||
|
inherit (clanConfig) directory;
|
||||||
|
})
|
||||||
|
# Dependencies
|
||||||
|
{
|
||||||
|
exportsModule = clanConfig.exportsModule;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# TODO: Rename to "allServices"
|
||||||
|
# All services
|
||||||
|
mappedServices = lib.mapAttrs (_module_ident: instances: {
|
||||||
|
imports = [
|
||||||
|
# Import the resolved module.
|
||||||
|
# i.e. clan.modules.admin
|
||||||
|
{
|
||||||
|
options.module = lib.mkOption {
|
||||||
|
type = lib.types.raw;
|
||||||
|
default = (builtins.head instances).instance.module;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(builtins.head instances).instance.resolvedModule
|
||||||
|
] # Include all the instances that correlate to the resolved module
|
||||||
|
++ (builtins.map (v: {
|
||||||
|
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
||||||
|
}) instances);
|
||||||
|
}) grouped;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
options._allMachines = mkOption {
|
||||||
|
internal = true;
|
||||||
|
type = types.raw;
|
||||||
|
default = lib.mapAttrs (machineName: _: {
|
||||||
|
# This is the list of nixosModules for each machine
|
||||||
|
machineImports = lib.foldlAttrs (
|
||||||
|
acc: _module_ident: serviceModule:
|
||||||
|
acc ++ [ serviceModule.result.final.${machineName}.nixosModule or { } ]
|
||||||
|
) [ ] config._services.mappedServices;
|
||||||
|
}) inventory.machines or { };
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
clanInternals.inventoryClass.machines = config._allMachines;
|
||||||
|
# clanInternals.inventoryClass.distributedServices = config._services;
|
||||||
|
|
||||||
|
# Exports from distributed services
|
||||||
|
exports = config._services.exports;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -3,12 +3,16 @@
|
|||||||
lib,
|
lib,
|
||||||
clanModule,
|
clanModule,
|
||||||
clanLib,
|
clanLib,
|
||||||
|
clan-core,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
eval = lib.evalModules {
|
eval = lib.evalModules {
|
||||||
modules = [
|
modules = [
|
||||||
clanModule
|
clanModule
|
||||||
];
|
];
|
||||||
|
specialArgs = {
|
||||||
|
self = clan-core;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
evalDocs = pkgs.nixosOptionsDoc {
|
evalDocs = pkgs.nixosOptionsDoc {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ in
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
jsonDocs = import ./eval-docs.nix {
|
jsonDocs = import ./eval-docs.nix {
|
||||||
|
clan-core = self;
|
||||||
inherit
|
inherit
|
||||||
pkgs
|
pkgs
|
||||||
lib
|
lib
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ let
|
|||||||
_: machine:
|
_: machine:
|
||||||
machine.extendModules {
|
machine.extendModules {
|
||||||
modules = [
|
modules = [
|
||||||
(lib.modules.importApply ../machineModules/overridePkgs.nix {
|
(lib.modules.importApply ../../nixosModules/machineModules/overridePkgs.nix {
|
||||||
pkgs = pkgsFor.${system};
|
pkgs = pkgsFor.${system};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@@ -167,6 +167,9 @@ in
|
|||||||
{ ... }@args:
|
{ ... }@args:
|
||||||
let
|
let
|
||||||
_class =
|
_class =
|
||||||
|
# _class was added in https://github.com/NixOS/nixpkgs/pull/395141
|
||||||
|
# Clan relies on it to determine which modules to load
|
||||||
|
# people need to use at least that version of nixpkgs
|
||||||
args._class or (throw ''
|
args._class or (throw ''
|
||||||
Your version of nixpkgs is incompatible with the latest clan.
|
Your version of nixpkgs is incompatible with the latest clan.
|
||||||
Please update nixpkgs input to the latest nixos-unstable or nixpkgs-unstable.
|
Please update nixpkgs input to the latest nixos-unstable or nixpkgs-unstable.
|
||||||
@@ -176,7 +179,7 @@ in
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(lib.modules.importApply ../machineModules/forName.nix {
|
(lib.modules.importApply ../../nixosModules/machineModules/forName.nix {
|
||||||
inherit (config.inventory) meta;
|
inherit (config.inventory) meta;
|
||||||
inherit
|
inherit
|
||||||
name
|
name
|
||||||
@@ -216,8 +219,6 @@ in
|
|||||||
inherit nixosConfigurations;
|
inherit nixosConfigurations;
|
||||||
inherit darwinConfigurations;
|
inherit darwinConfigurations;
|
||||||
|
|
||||||
exports = config.clanInternals.inventoryClass.distributedServices.servicesEval.config.exports;
|
|
||||||
|
|
||||||
clanInternals = {
|
clanInternals = {
|
||||||
inventoryClass =
|
inventoryClass =
|
||||||
let
|
let
|
||||||
@@ -251,21 +252,9 @@ in
|
|||||||
exportsModule = config.exportsModule;
|
exportsModule = config.exportsModule;
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
{ config, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
staticModules = clan-core.clan.modules;
|
staticModules = clan-core.clan.modules;
|
||||||
|
|
||||||
distributedServices = clanLib.inventory.mapInstances {
|
|
||||||
inherit (config)
|
|
||||||
inventory
|
|
||||||
directory
|
|
||||||
flakeInputs
|
|
||||||
exportsModule
|
|
||||||
;
|
|
||||||
clanCoreModules = clan-core.clan.modules;
|
|
||||||
prefix = [ "distributedServices" ];
|
|
||||||
};
|
|
||||||
machines = config.distributedServices.allMachines;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,3 +1,28 @@
|
|||||||
|
/**
|
||||||
|
The templates submodule
|
||||||
|
|
||||||
|
'clan.templates'
|
||||||
|
|
||||||
|
Different kinds supported:
|
||||||
|
|
||||||
|
- clan templates: 'clan.templates.clan'
|
||||||
|
- disko templates: 'clan.templates.disko'
|
||||||
|
- machine templates: 'clan.templates.machine'
|
||||||
|
|
||||||
|
A template has the form:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
description: string; # short summary what the template contains
|
||||||
|
path: path; # path to the template
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The clan API copies the template from the given 'path'
|
||||||
|
into a target folder. For example,
|
||||||
|
|
||||||
|
`./machines/<machine-name>` for 'machine' templates.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -67,9 +67,6 @@ in
|
|||||||
type = types.raw;
|
type = types.raw;
|
||||||
};
|
};
|
||||||
|
|
||||||
distributedServices = mkOption {
|
|
||||||
type = types.raw;
|
|
||||||
};
|
|
||||||
inventory = mkOption {
|
inventory = mkOption {
|
||||||
type = types.raw;
|
type = types.raw;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ let
|
|||||||
inputs.data-mesher.nixosModules.data-mesher
|
inputs.data-mesher.nixosModules.data-mesher
|
||||||
];
|
];
|
||||||
config = {
|
config = {
|
||||||
clan.core.clanPkgs = lib.mkDefault self.packages.${pkgs.hostPlatform.system};
|
clan.core.clanPkgs = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Note this might jump back and worth as kernel get added or removed.
|
# Note this might jump back and worth as kernel get added or removed.
|
||||||
boot.kernelPackages = lib.mkIf (lib.meta.availableOn pkgs.hostPlatform pkgs.zfs) latestKernelPackage;
|
boot.kernelPackages = lib.mkIf (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.zfs) latestKernelPackage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
directory,
|
directory,
|
||||||
meta,
|
meta,
|
||||||
}:
|
}:
|
||||||
|
# The following is a nixos/darwin module
|
||||||
{
|
{
|
||||||
_class,
|
_class,
|
||||||
lib,
|
lib,
|
||||||
@@ -245,7 +245,7 @@ class SecretStore(StoreBase):
|
|||||||
output_dir / "activation" / generator.name / file.name
|
output_dir / "activation" / generator.name / file.name
|
||||||
)
|
)
|
||||||
out_file.parent.mkdir(parents=True, exist_ok=True)
|
out_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
out_file.write_bytes(self.get(generator, file.name))
|
out_file.write_bytes(file.value)
|
||||||
if "partitioning" in phases:
|
if "partitioning" in phases:
|
||||||
for generator in vars_generators:
|
for generator in vars_generators:
|
||||||
for file in generator.files:
|
for file in generator.files:
|
||||||
@@ -254,7 +254,7 @@ class SecretStore(StoreBase):
|
|||||||
output_dir / "partitioning" / generator.name / file.name
|
output_dir / "partitioning" / generator.name / file.name
|
||||||
)
|
)
|
||||||
out_file.parent.mkdir(parents=True, exist_ok=True)
|
out_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
out_file.write_bytes(self.get(generator, file.name))
|
out_file.write_bytes(file.value)
|
||||||
|
|
||||||
hash_data = self.generate_hash(machine)
|
hash_data = self.generate_hash(machine)
|
||||||
if hash_data:
|
if hash_data:
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ class SecretStore(StoreBase):
|
|||||||
)
|
)
|
||||||
# chmod after in case it doesn't have u+w
|
# chmod after in case it doesn't have u+w
|
||||||
target_path.touch(mode=0o600)
|
target_path.touch(mode=0o600)
|
||||||
target_path.write_bytes(self.get(generator, file.name))
|
target_path.write_bytes(file.value)
|
||||||
target_path.chmod(file.mode)
|
target_path.chmod(file.mode)
|
||||||
|
|
||||||
if "partitioning" in phases:
|
if "partitioning" in phases:
|
||||||
@@ -260,7 +260,7 @@ class SecretStore(StoreBase):
|
|||||||
)
|
)
|
||||||
# chmod after in case it doesn't have u+w
|
# chmod after in case it doesn't have u+w
|
||||||
target_path.touch(mode=0o600)
|
target_path.touch(mode=0o600)
|
||||||
target_path.write_bytes(self.get(generator, file.name))
|
target_path.write_bytes(file.value)
|
||||||
target_path.chmod(file.mode)
|
target_path.chmod(file.mode)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ class ClanSelectError(ClanError):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
if self.description:
|
if self.description:
|
||||||
return f"{self.msg} Reason: {self.description}"
|
return f"{self.msg} Reason: {self.description}. Use flag '--debug' to see full nix trace."
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
|||||||
@@ -59,9 +59,7 @@ def upload_sources(machine: Machine, ssh: Host, upload_inputs: bool) -> str:
|
|||||||
if not has_path_inputs and not upload_inputs:
|
if not has_path_inputs and not upload_inputs:
|
||||||
# Just copy the flake to the remote machine, we can substitute other inputs there.
|
# Just copy the flake to the remote machine, we can substitute other inputs there.
|
||||||
path = flake_data["path"]
|
path = flake_data["path"]
|
||||||
if machine._class_ == "darwin":
|
remote_url = f"ssh-ng://{remote_url_base}"
|
||||||
remote_program_params = "?remote-program=bash -lc 'exec nix-daemon --stdio'"
|
|
||||||
remote_url = f"ssh-ng://{remote_url_base}{remote_program_params}"
|
|
||||||
cmd = nix_command(
|
cmd = nix_command(
|
||||||
[
|
[
|
||||||
"copy",
|
"copy",
|
||||||
|
|||||||
@@ -64,6 +64,9 @@
|
|||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
legacyPackages = {
|
||||||
|
inherit jsonDocs clanModulesViaService;
|
||||||
|
};
|
||||||
packages = {
|
packages = {
|
||||||
inherit module-docs;
|
inherit module-docs;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,151 +11,10 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
|
||||||
mapAttrsToList
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
|
||||||
types
|
|
||||||
splitString
|
|
||||||
stringLength
|
|
||||||
substring
|
|
||||||
;
|
|
||||||
inherit (self) clanLib;
|
|
||||||
|
|
||||||
serviceModules = self.clan.modules;
|
|
||||||
|
|
||||||
baseHref = "/option-search/";
|
baseHref = "/option-search/";
|
||||||
|
|
||||||
getRoles =
|
|
||||||
module:
|
|
||||||
(clanLib.evalService {
|
|
||||||
modules = [ module ];
|
|
||||||
prefix = [ ];
|
|
||||||
}).config.roles;
|
|
||||||
|
|
||||||
getManifest =
|
|
||||||
module:
|
|
||||||
(clanLib.evalService {
|
|
||||||
modules = [ module ];
|
|
||||||
prefix = [ ];
|
|
||||||
}).config.manifest;
|
|
||||||
|
|
||||||
settingsModules = module: mapAttrs (_roleName: roleConfig: roleConfig.interface) (getRoles module);
|
|
||||||
|
|
||||||
# Map each letter to its capitalized version
|
# Map each letter to its capitalized version
|
||||||
capitalizeChar =
|
|
||||||
char:
|
|
||||||
{
|
|
||||||
a = "A";
|
|
||||||
b = "B";
|
|
||||||
c = "C";
|
|
||||||
d = "D";
|
|
||||||
e = "E";
|
|
||||||
f = "F";
|
|
||||||
g = "G";
|
|
||||||
h = "H";
|
|
||||||
i = "I";
|
|
||||||
j = "J";
|
|
||||||
k = "K";
|
|
||||||
l = "L";
|
|
||||||
m = "M";
|
|
||||||
n = "N";
|
|
||||||
o = "O";
|
|
||||||
p = "P";
|
|
||||||
q = "Q";
|
|
||||||
r = "R";
|
|
||||||
s = "S";
|
|
||||||
t = "T";
|
|
||||||
u = "U";
|
|
||||||
v = "V";
|
|
||||||
w = "W";
|
|
||||||
x = "X";
|
|
||||||
y = "Y";
|
|
||||||
z = "Z";
|
|
||||||
}
|
|
||||||
.${char};
|
|
||||||
|
|
||||||
title =
|
|
||||||
name:
|
|
||||||
let
|
|
||||||
# split by -
|
|
||||||
parts = splitString "-" name;
|
|
||||||
# capitalize first letter of each part
|
|
||||||
capitalize = part: (capitalizeChar (substring 0 1 part)) + substring 1 (stringLength part) part;
|
|
||||||
capitalizedParts = map capitalize parts;
|
|
||||||
in
|
|
||||||
builtins.concatStringsSep " " capitalizedParts;
|
|
||||||
|
|
||||||
fakeInstanceOptions =
|
|
||||||
name: module:
|
|
||||||
let
|
|
||||||
manifest = getManifest module;
|
|
||||||
description = ''
|
|
||||||
# ${title name} (Clan Service)
|
|
||||||
|
|
||||||
**${manifest.description}**
|
|
||||||
|
|
||||||
${lib.optionalString (manifest ? readme) manifest.readme}
|
|
||||||
|
|
||||||
${
|
|
||||||
if manifest.categories != [ ] then
|
|
||||||
"Categories: " + builtins.concatStringsSep ", " manifest.categories
|
|
||||||
else
|
|
||||||
"No categories defined"
|
|
||||||
}
|
|
||||||
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
instances.${name} = lib.mkOption {
|
|
||||||
inherit description;
|
|
||||||
type = types.submodule {
|
|
||||||
options.roles = mapAttrs (
|
|
||||||
roleName: roleSettingsModule:
|
|
||||||
mkOption {
|
|
||||||
type = types.submodule {
|
|
||||||
_file = "docs flake-module";
|
|
||||||
imports = [
|
|
||||||
{ _module.args = { inherit clanLib; }; }
|
|
||||||
(import ../../modules/inventoryClass/role.nix {
|
|
||||||
nestedSettingsOption = mkOption {
|
|
||||||
type = types.raw;
|
|
||||||
description = ''
|
|
||||||
See [instances.${name}.roles.${roleName}.settings](${baseHref}?option_scope=0&option=inventory.instances.${name}.roles.${roleName}.settings)
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
settingsOption = mkOption {
|
|
||||||
type = types.submoduleWith {
|
|
||||||
modules = [ roleSettingsModule ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
) (settingsModules module);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
docModules = [
|
|
||||||
{
|
|
||||||
inherit self;
|
|
||||||
}
|
|
||||||
self.modules.clan.default
|
|
||||||
{
|
|
||||||
options.inventory = lib.mkOption {
|
|
||||||
type = types.submoduleWith {
|
|
||||||
modules = [
|
|
||||||
{ noInstanceOptions = true; }
|
|
||||||
]
|
|
||||||
++ mapAttrsToList fakeInstanceOptions serviceModules;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
baseModule =
|
baseModule =
|
||||||
# Module
|
# Module
|
||||||
@@ -208,12 +67,6 @@
|
|||||||
title = "Clan Options";
|
title = "Clan Options";
|
||||||
# scopes = mapAttrsToList mkScope serviceModules;
|
# scopes = mapAttrsToList mkScope serviceModules;
|
||||||
scopes = [
|
scopes = [
|
||||||
{
|
|
||||||
inherit baseHref;
|
|
||||||
name = "Flake Options (clan.nix file)";
|
|
||||||
modules = docModules;
|
|
||||||
urlPrefix = "https://git.clan.lol/clan/clan-core/src/branch/main/";
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
name = "Machine Options (clan.core NixOS options)";
|
name = "Machine Options (clan.core NixOS options)";
|
||||||
optionsJSON = "${coreOptions}/share/doc/nixos/options.json";
|
optionsJSON = "${coreOptions}/share/doc/nixos/options.json";
|
||||||
|
|||||||
Reference in New Issue
Block a user