Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print version information when entering shell #739

Open
sagikazarmark opened this issue Jul 19, 2023 · 9 comments · May be fixed by #1320
Open

Print version information when entering shell #739

sagikazarmark opened this issue Jul 19, 2023 · 9 comments · May be fixed by #1320
Labels
enhancement New feature or request

Comments

@sagikazarmark
Copy link
Contributor

One thing I like doing is print version information when entering the shell of a new/different project. It tells me what tools I get for the project.

However, writing the version script over and over again results in a lot of duplications.

I propose adding a module that prints version information for already supported tools (eg. languages) and allows users to opt-in for displaying version information when entering a devshell.

Here is what I cooked up:

{ config, lib, ... }:

let
  cfg = config.versions;
in
{
  options.versions = {
    enable = lib.mkEnableOption "Print versions when entering a shell";

    exec = lib.mkOption {
      type = lib.types.lines;
      description = "Bash code to execute to print version information.";
      default = "";
    };
  };

  config = lib.mkIf cfg.enable {
    scripts = {
      versions.exec = cfg.exec;
    };

    enterShell = ''
      versions
    '';
  };
}

In case of Go, the integration would look like this:

  config = lib.mkIf cfg.enable {
    # ...
    versions.exec = "${cfg.package}/bin/go version";
  };

Would you be interested in adding such a module?

@sagikazarmark sagikazarmark added the enhancement New feature or request label Jul 19, 2023
@thenonameguy
Copy link
Contributor

'devenv info' already lists the package names, which contain the version strings already, without needing to execute binaries.

@sagikazarmark
Copy link
Contributor Author

Hm, interesting. Unfortunately, it's not available when using flakes (but I'm guessing that's an easy fix). :/

Also, not all packages may be important. For example, when I'm working on a Go/Kubernetes project, I'm mostly interested in those tools, but not the version of curl or jq being used.

@sagikazarmark
Copy link
Contributor Author

Any ideas how to expose config.info in flakes?

@thenonameguy
Copy link
Contributor

thenonameguy commented Jul 19, 2023

You don't necessarily need to do that, you can just solve it within the devenv NixOS module itself, with something like this:

  enterShell =
    "${lib.concatMapStringsSep "\n" (pkg: ''
      echo "${pkg.pname}: ${if pkg ? "version" then pkg.version else "unknown"}"
    '') (builtins.filter (pkg: pkg ? "pname" && builtins.elem pkg.pname ["terraform" "ngrok"]) config.packages)}";

Produces:

terraform: 1.4.5
ngrok: 3.1.1

@sagikazarmark
Copy link
Contributor Author

Thanks @thenonameguy

Looking at devenv info though, I think it would be worth exposing in the flake module.

@domenkozar
Copy link
Member

It should be available at devShells.default.config.info.

@sagikazarmark
Copy link
Contributor Author

@domenkozar thanks!

I tried that, but similarly to #711, it doesn't seem to work.

@domenkozar
Copy link
Member

Today I got an idea how we could support flakes in a better way.

Will create a prototype in a few days.

@sagikazarmark
Copy link
Contributor Author

Sounds good! Happy to test-drive it once you have something cooked up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants