A structured-data shell in Gleam, inspired by Nushell
2.4 kB
91 lines
1{
2 description = "gleshell — structured-data shell in Gleam, inspired by Nushell";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6 systems.url = "github:nix-systems/default";
7 devenv.url = "github:cachix/devenv";
8 devenv.inputs.nixpkgs.follows = "nixpkgs";
9 };
10
11 nixConfig = {
12 extra-substituters = [ "https://devenv.cachix.org" ];
13 extra-trusted-public-keys = [
14 "devenv.cachix.org-1:ppRjvZf4JrQqfA3n7eHkSxX4z1M0RKZ77N8D66zCFAI="
15 ];
16 };
17
18 outputs =
19 {
20 self,
21 nixpkgs,
22 devenv,
23 systems,
24 ...
25 }@inputs:
26 let
27 forEachSystem = nixpkgs.lib.genAttrs (import systems);
28 in
29 {
30 packages = forEachSystem (
31 system:
32 let
33 pkgs = nixpkgs.legacyPackages.${system};
34 runtimeInputs = [
35 pkgs.gleam
36 pkgs.beamPackages.erlang
37 pkgs.rebar3
38 ];
39 # Thin wrapper: needs the gleshell source tree (cwd or GLESHELL_ROOT).
40 gleshell = pkgs.writeShellApplication {
41 name = "gleshell";
42 inherit runtimeInputs;
43 text = ''
44 root="''${GLESHELL_ROOT:-}"
45 if [ -z "$root" ]; then
46 if [ -f gleam.toml ] && grep -q 'name = "gleshell"' gleam.toml 2>/dev/null; then
47 root="$PWD"
48 else
49 echo "gleshell: run from the gleshell repo root, or set GLESHELL_ROOT" >&2
50 exit 1
51 fi
52 fi
53 cd "$root"
54 exec gleam run -- "$@"
55 '';
56 };
57 in
58 {
59 default = gleshell;
60 inherit gleshell;
61 }
62 );
63
64 apps = forEachSystem (system: {
65 default = {
66 type = "app";
67 program = "${self.packages.${system}.gleshell}/bin/gleshell";
68 };
69 });
70
71 devShells = forEachSystem (
72 system:
73 let
74 pkgs = nixpkgs.legacyPackages.${system};
75 in
76 {
77 default = devenv.lib.mkShell {
78 inherit inputs pkgs;
79 modules = [
80 {
81 devenv.root = builtins.toString ./.;
82 }
83 ./devenv.nix
84 ];
85 };
86 }
87 );
88
89 formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
90 };
91}