Skip to content

Commit 5489b1f

Browse files
authored
Merge branch 'main' into update_flake_lock_test
2 parents 479b24f + 2c457a2 commit 5489b1f

File tree

6 files changed

+149
-57
lines changed

6 files changed

+149
-57
lines changed

doc/share-services.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
11
# Share services
22

3-
See <https://github.com/juspay/services-flake/tree/main/example/share-services>
3+
Let's say you have two projects: `foo` and `bar`. `foo` defines a service that needs to be used by `bar`. Both `foo` and `bar`, being separate projects, have their own `flake.nix`. In order for `bar` to reuse `foo` service instead of redefining it, `foo` can export `processComposeModules` in its flake `outputs`. `processComposeModules` is not a reserved output; it can be named anything, but the naming is appropriate for this scenario.
4+
5+
Next, we will see basic `flake.nix` for `foo` and `bar`. You can find a more real-world example at <https://github.com/juspay/services-flake/tree/main/example/share-services>.
6+
7+
## foo (Exports its service)
8+
9+
```nix
10+
# foo/flake.nix
11+
{
12+
inputs = {
13+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
14+
flake-parts.url = "github:hercules-ci/flake-parts";
15+
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
16+
services-flake.url = "github:juspay/services-flake";
17+
};
18+
outputs = inputs:
19+
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
20+
systems = [ "x86_64-linux" "aarch64-darwin" ];
21+
imports = [
22+
inputs.process-compose-flake.flakeModule
23+
];
24+
flake.processComposeModules.default = ./services.nix;
25+
perSystem = { pkgs, lib, ... }: {
26+
process-compose."default" = {
27+
imports = [
28+
inputs.services-flake.processComposeModules.default
29+
inputs.self.processComposeModules.default
30+
];
31+
};
32+
};
33+
};
34+
}
35+
```
36+
37+
[[custom-service]] exported by `foo` as `processComposeModules.default`:
38+
39+
```nix
40+
# foo/services.nix
41+
{ pkgs, lib, ... }: {
42+
options = {
43+
services.foo = {
44+
enable = lib.mkEnableOption "Enable foo service";
45+
package = lib.mkPackageOption pkgs "foo" { };
46+
};
47+
};
48+
config = let cfg = config.services.foo; in
49+
lib.mkIf cfg.enable {
50+
settings.processes.foo = {
51+
command = "${lib.getExe cfg.foo}";
52+
};
53+
};
54+
}
55+
```
56+
57+
## bar (Imports foo service)
58+
59+
`bar` wants to reuse `foo`'s service.
60+
61+
```nix
62+
# bar/flake.nix
63+
{
64+
inputs = {
65+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
66+
flake-parts.url = "github:hercules-ci/flake-parts";
67+
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
68+
services-flake.url = "github:juspay/services-flake";
69+
foo.url = "<foo-source>";
70+
};
71+
outputs = inputs:
72+
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
73+
systems = [ "x86_64-linux" "aarch64-darwin" ];
74+
imports = [
75+
inputs.process-compose-flake.flakeModule
76+
];
77+
flake.processComposeModules.default = ./services.nix;
78+
perSystem = { pkgs, lib, ... }: {
79+
process-compose."default" = {
80+
imports = [
81+
inputs.services-flake.processComposeModules.default
82+
inputs.foo.processComposeModules.default
83+
];
84+
services.foo.enable = true;
85+
86+
# The rest of bar's services goes here...
87+
};
88+
};
89+
};
90+
}
91+
92+
```

example/llm/flake.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/share-services/northwind/flake.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/share-services/pgweb/flake.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/simple/flake.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/flake.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"${inputs.services-flake}/nix/services/apache-kafka_test.nix"
4343
"${inputs.services-flake}/nix/services/cassandra_test.nix"
4444
"${inputs.services-flake}/nix/services/clickhouse/clickhouse_test.nix"
45-
"${inputs.services-flake}/nix/services/elasticsearch_test.nix"
4645
"${inputs.services-flake}/nix/services/grafana_test.nix"
4746
"${inputs.services-flake}/nix/services/memcached_test.nix"
4847
"${inputs.services-flake}/nix/services/minio_test.nix"
@@ -62,6 +61,10 @@
6261
"${inputs.services-flake}/nix/services/tika_test.nix"
6362
"${inputs.services-flake}/nix/services/weaviate_test.nix"
6463
"${inputs.services-flake}/nix/services/zookeeper_test.nix"
64+
] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
65+
# Fails on macOS with: `error: chmod '"/nix/store/rcx3n94ygmd61rrv2p22sykhk0yx49n4-elasticsearch-7.17.16/modules/x-pack-ml/platform/darwin-aarch64/controller.app"': Operation not permitted`
66+
# Related: https://github.com/NixOS/nix/issues/6765
67+
"${inputs.services-flake}/nix/services/elasticsearch_test.nix"
6568
]));
6669
};
6770
};

0 commit comments

Comments
 (0)