Skip to content

Enable the use of a shell.nix file as environment definition. #364

Description

@Equanox

It's currently not possible to load an development environments from a shell.nix file which makes use of the pkgs.mkShell utility function due to the way Bob builds nix package and creates the environment for it's internal shell.

How Bob calls nix-build && nix-shell

Bob uses nix-build to build nix package and the output of nix-shell to create a fully controlled build environement. Inbetween those calls Bob uses caching to assure that no extra work is done. The intend was to make it easier to depend on nix packages without the need to understand the nix language.

Bob calls to nix-*

1) nix-build:

nix-build --no-out-link -E with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.05.tar.gz") { }; [go_1_20]

2) nix-shell:

nix-shell --pure --keep NIX_SSL_CERT_FILE --command env -E 
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.05.tar.gz") {} }:
pkgs.mkShell {
  buildInputs = [
    pkgs.go_1_20
   (pkgs.callPackage ./oapicodegen_v1.12.4.nix{ } )
   (pkgs.callPackage ./empty.nix{ } )
 ];
}

Content of empty.nix

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [];
}

Content of oapicodegen_v1.12.4.nix

{ lib, buildGoModule }:

buildGoModule rec {
  # Args...
}

The call to nix-shell fails with an error

exit status 127
/nix/store/zb4vimfhcgc8hphkqmmfcj2lxmgg9y2f-nix-shell: line 1: ------------------------------------------------------------: command not found
/nix/store/37p8gq9zijbw6pj3lpi1ckqiv18j2g62-stdenv-linux/setup: line 703: pop_var_context: head of shell_variables not a function context
/nix/store/37p8gq9zijbw6pj3lpi1ckqiv18j2g62-stdenv-linux/setup: line 710: pop_var_context: head of shell_variables not a function context

Possible Solution

A solution could be to to introduce a new shell: directive which takes the path to a shell.nix file like you would do it with plain nix-shell. Internally it would omit the nix-build -> cache -> nix-shell chain. The shell: and dependencies: directive are mutually exclusive.

cc: @srstrong

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions