Skip to content

Commit

Permalink
add option for excluding envs from exposition in devShells
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Jul 19, 2023
1 parent 6b5c2e5 commit cf7df6d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

* Allow envs to be excluded from being exposed as `devShells` for specific systems.

# 0.6.0

* Support multiple Cabal libraries in a single package.
Expand Down
5 changes: 5 additions & 0 deletions lib/doc/prose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ in {
since it will try to read the file and terminate with an error.
In that (unlikely) case, you'll have to set `gen-overrides.enable = false` before running it for the first time.
:::
Another potential source for `nix flake check` to fail is when an environment with a virtual machine is exposed as a
shell.
For that purpose, the option [](#opt-env-systems) can be used to define for which systems the environment should be
exposed.
'';

environments = ''
Expand Down
4 changes: 4 additions & 0 deletions lib/with-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ let
${pkgs.git}/bin/git add flake.lock
'';

envSystemAllowed = env:
env.systems == null || (elem config.system env.systems);

in basic // {
inherit
paramApp
Expand All @@ -146,5 +149,6 @@ in basic // {
downloadStaticCli
bootstrapWithStaticCli
bootstrapWithDynamicCli
envSystemAllowed
;
}
14 changes: 14 additions & 0 deletions modules/env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,20 @@ in {
readOnly = true;
};

systems = mkOption {
description = mdDoc ''
The architecture/system identifiers like `x86_64-linux` for which this environment works.
This is used to exclude environments from being exposed as shells when they are system-specific, for example when
using a VM that only works with Linux.
If those shells were exposed, the command `nix flake check` would fail while evaluating the `devShells` outputs,
since that doesn't only select the current system.
If set to `null` (the default), all systems are accepted.
'';
type = nullOr (listOf str);
default = null;
};

vm = {

enable = mkEnableOption (mdDoc "the service VM for this env");
Expand Down
2 changes: 1 addition & 1 deletion modules/output.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ in {

devShells = let

shells = mapAttrs (_: e: e.shell) util.visibleEnvs;
shells = mapAttrs (_: e: e.shell) (filterAttrs (_: util.envSystemAllowed) util.visibleEnvs);

in shells // { default = shells.dev; };

Expand Down

0 comments on commit cf7df6d

Please sign in to comment.