-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide a
devShell
with packages from enabled services (#355)
resolves #194
- Loading branch information
1 parent
9ee3aa3
commit 6e1251b
Showing
7 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# DevShell | ||
|
||
`services-flake` uses [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell) function to provide a shell with packages of all the enabled services. | ||
|
||
```nix | ||
# Inside `perSystem` | ||
{ | ||
process-compose."my-pc" = { ... }; | ||
devShells.default = pkgs.mkShell { | ||
inputsFrom = [ | ||
config.process-compose."my-pc".services.outputs.devShell; | ||
]; | ||
# ... | ||
}; | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
# Guide | ||
|
||
- [[datadir]]# | ||
- [[devshell]]# | ||
- [[custom-service]]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ config, pkgs, lib, ... }: | ||
let | ||
inherit (lib) types; | ||
in | ||
{ | ||
options.services.outputs = { | ||
enabledServices = lib.mkOption { | ||
type = types.attrsOf (types.listOf types.str); | ||
readOnly = true; | ||
description = '' | ||
Names of all the enabled service instances, grouped by the service name. | ||
''; | ||
example = lib.literalExpression '' | ||
{ | ||
mysql = [ "m1" "m2" ]; | ||
redis = [ "r1" ]; | ||
} | ||
''; | ||
}; | ||
devShell = lib.mkOption { | ||
type = types.package; | ||
readOnly = true; | ||
description = '' | ||
The devShell that aggregates packages from all the enabled services. | ||
''; | ||
}; | ||
}; | ||
|
||
config = { | ||
services.outputs.enabledServices = lib.pipe config.services [ | ||
# `outputs` is a reserved attribute set and is not the name of a service. | ||
(lib.filterAttrs (n: _: n != "outputs")) | ||
|
||
(lib.mapAttrs (_service: instances: | ||
lib.attrNames (lib.filterAttrs (_: v: v.enable) instances))) | ||
]; | ||
|
||
services.outputs.devShell = pkgs.mkShell { | ||
packages = lib.pipe config.services.outputs.enabledServices [ | ||
(lib.mapAttrsToList (service: instances: | ||
map | ||
(instance: | ||
lib.attrByPath ([ service instance "package" ]) (builtins.throw "${service}.${instance} doesn't define a `package` option") config.services) | ||
instances)) | ||
|
||
lib.flatten | ||
]; | ||
}; | ||
}; | ||
} |