cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

New examples #12

Closed domenkozar closed 2 months ago

domenkozar commented 1 year ago

Please, comment with what kind of an example you'd like to see.

paultiplady commented 1 year ago

Would be great to see an example (if it's possible) of how to wire up Python with specific packages; something equivalent to

pkgs.python3.withPackages (p: with p; [
  django
])

From https://nixos.wiki/wiki/Python.

The most complete devenv.nix I've found is https://github.com/cachix/devenv/blob/4787a79b00c5415139c2ae7029c8d870eea831e6/devenv.nix which doesn't have this wired up.

sacsar commented 1 year ago

I'm currently trying to figure out how to use niv and devenv together (since the nix docs point you to both). I'm honestly not sure if this is a missing example or if the answer is "don't do that".

domenkozar commented 1 year ago

Would be great to see an example (if it's possible) of how to wire up Python with specific packages; something equivalent to

pkgs.python3.withPackages (p: with p; [
  django
])

From https://nixos.wiki/wiki/Python.

The most complete devenv.nix I've found is https://github.com/cachix/devenv/blob/4787a79b00c5415139c2ae7029c8d870eea831e6/devenv.nix which doesn't have this wired up.

That's something I've been thinking quite a bit in the last days. There are different levels of language support and I still need to do a bit of experimentation. Regardless, this will be supported!

domenkozar commented 1 year ago

I'm currently trying to figure out how to use niv and devenv together (since the nix docs point you to both). I'm honestly not sure if this is a missing example or if the answer is "don't do that".

You don't need niv since you can use https://devenv.sh/inputs/

paultiplady commented 1 year ago

There are different levels of language support and I still need to do a bit of experimentation.

Worth noting that in practice, for applications withPackages isn't that useful since it doesn't have all the packages, and I'll probably end up using something like https://github.com/nix-community/poetry2nix.

ostrolucky commented 1 year ago

I'm a PHP developer. I noticed there is a PHP-FPM service which is nice, but I'm wondering how to use it together with web server. Usual combination is NGINX + PHP-FPM, but looks like you don't provide nginx service? What's the recommended approach to use a php-fpm then, what to connect it to? Hence would be nice to provide example for HTTP server that connects to FPM.

sonn-gamm commented 1 year ago

+1 for Nginx support / setup.

domenkozar commented 1 year ago

I think @shyim mentioned recently to add nginx service

Juhlinus commented 1 year ago

I am currently using devenv within a PHP project. For now we are using caddy, but since caddy does not support file uploading out of the box, we wanted to switch to nginx.

Definitely a +1 to a nginx service.

shyim commented 1 year ago

Are you sure with file uploading? Never head problems with that. Tried now working :D

ostrolucky commented 1 year ago

In my setup, I simply run symfony serve. With that you don't need nginx. You need pkgs.symfony-cli.

Juhlinus commented 1 year ago

Are you sure with file uploading? Never head problems with that. Tried now working :D

Really? Using Laravel I am having issues uploading. I've tried setting the upload_tmp_dir explicitly. Is there a recommended folder to set this to? I'm going to try with a fresh Laravel app to make sure that it is not some configuration within the current app interfering.

shyim commented 1 year ago

If you have a reproducer repo I would like to debug it and fix it :)

domenkozar commented 1 year ago

There's now nginx at https://devenv.sh/reference/options/#servicesnginxenable

frontsideair commented 1 year ago

It would be really nice to have a Node.js/Postgres full-stack example. I tried to build one a few weeks ago but didn't work out smoothly. I think one of the reasons might be that I was using Prisma as my ORM, which may require some tweaking with socket files.

domenkozar commented 1 year ago

@frontsideair is there a getting started repo that devenv should work with?

frontsideair commented 1 year ago

This Remix template is a good candidate I think, it has a docker compose file and should work with minimal changes.

pathetic-lynx commented 7 months ago

I'd really like an example that shows how to wire up a devenv flake setup with a flake that exposes packages.

My current flake looks like this and is used together with direnv and use flake . --impure but the nativeBuildInputs declared in default.nix are not present in the shell. I think i am doing something fundamentally wrong or misunderstood the usecase of devenv. Is it even supposed to be used this way? Please enlighten me

{
  description = "myPackage";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    flake-utils.url = "github:numtide/flake-utils";
    myDependency = {
      url =
        "git+ssh://git@our.git.com/myDependency";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    code-generator = {
      url =
        "git+ssh://git@our.git.com/code-generator";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    devenv = {
      url = "github:cachix/devenv";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, myDependency, devenv, code-generator, systems
    , flake-utils, ... }@inputs:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system};
      in rec {
        packages = rec {
          default = myPackage-default;
          myPackage-default = pkgs.callPackage ./default.nix {
            pkgs = pkgs;
            myDependency = myDependency;
            code-generator = code-generator;
          };
          myPackage-prod = pkgs.callPackage ./default.nix {
            pkgs = pkgs;
            myDependency = myDependency;
            code-generator = code-generator;
            debug = false;
          };
        };
        devShells = {
          default = devenv.lib.mkShell {
            inherit inputs pkgs;
            # packages = packages.default.${system}.buildInputs ++ packages.default.${system}.nativeBuildInputs;
            modules = [{
              # https://devenv.sh/reference/options/
              pre-commit.hooks = {
                # TODO: add hooks for xml and json formatting
                alejandra.enable = true; # black for nix
                black.enable = true;
                clang-format.enable = true;
                # editorconfig-checker.enable = true;
                ruff.enable = true;
                shellcheck.enable = true;
              };
            }];
          };
        };
      });
}
domenkozar commented 2 months ago

Best to open a separate issue for each.