Skip to content

Commit

Permalink
imp: integrate devshell & nixago tightly
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jul 26, 2022
1 parent 5d8f640 commit f12e6e4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 11 deletions.
58 changes: 50 additions & 8 deletions cells/std/lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,60 @@
}: let
nixpkgs = inputs.nixpkgs;
in {
inherit (inputs.devshell.legacyPackages) mkShell;
mkShell = configuration: let
nixagoModule = {
config,
lib,
...
}:
with lib; let
cfg = config.devshell;
in {
options.nixago = mkOption {
type = types.listOf types.attrs;
default = [];
apply = x: x.passthru;
description = "List of `std` Nixago pebbles to load";
};

config.devshell = mkIf (cfg.nixago != []) {
startup.nixago-setup-hook = stringBefore ["motd"] inputs.nixago.lib.makeAll cfg.nixago;
packages = builtins.concatMap (o: o.packages) cfg.nixago;
commands = builtins.concatMap (o: o.commands) cfg.nixago;
};
};
in
inputs.devshell.legacyPackages.mkShell {
imports = [configuration nixagoModule];
};

mkNixago = configuration:
(inputs.nixago.lib.make configuration)
// {
# transparently extend config data with a functor
__functor = _: extra: (inputs.nixago.lib.make (configuration
# passthru configuration
passthru =
configuration
// {
configData = inputs.data-merge.merge configuration.configData extra;
}));
# implement a minimal numtide/devshell forward contract
packages = configuration.packages or [];
commands = configuration.commands or [];
# implement a minimal numtide/devshell forward contract
packages = configuration.packages or [];
commands = configuration.commands or [];
};

# transparently extend config data with a functor
__functor = self: {
configData ? {},
packages ? [],
commands ? [],
}: let
newSelf =
self.passthru
// {
configData = inputs.data-merge.merge self.passthru.configData configData;
packages = self.passthru.packages ++ packages;
commands = self.passthru.commands ++ commands;
};
in
inputs.nixago.lib.make (newSelf // {passthru = newSelf;});
};

fromMakesWith = inputs': let
Expand Down
17 changes: 17 additions & 0 deletions cells/std/lib/mkNixago.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@

This is a transparent convenience proxy for [`nix-community/nixago`'s][nixago] `lib.${system}.make` function.

It is enriched with a forward contract towards `std` enriched `mkShell` implementation.

In order to define [`numtide/devshell`'s][numtide-devshell] `commands` & `packages` alongside the Nixago pebble,
just add the following attrset to the Nixago spec. It will be picked up automatically by `mkShell` when that pebble
is used inside its `config.nixago`-option.

```nix
{ inputs, cell }: {
foo = inputs.std.std.lib.mkNixago {
/* ... */
packages = [ /* ... */ ];
commands = [ /* ... */ ];
};
}
```

[nixago]: https://github.com/nix-community/nixago
[numtide-devshell]: https://github.com/numtide/devshell
16 changes: 16 additions & 0 deletions cells/std/lib/mkShell.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@

This is a transparent convenience proxy for [`numtide/devshell`'s][numtide-devshell] `mkShell` function.

It is enriched with a tight integration for `std` [Nixago][nixago] pebbles:

```nix
{ inputs, cell}: {
default = inputs.std.std.lib.mkShell {
/* ... */
nixago = [
cell.nixago.foo
cell.nixago.bar
cell.nixago.quz
];
};
}
```

[nixago]: https://github.com/nix-community/nixago
[numtide-devshell]: https://github.com/numtide/devshell
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f12e6e4

Please sign in to comment.