hello so i just move in to nixos and my trouble is how i setup laravel on nixos? like how i can install composer?
You can either install composer system wide by adding php84Packages.composer to your configuration.nix (or other version of php), or use write a nix-shell to temporary add composer to your environment.
I just happened to setup lumen project today, so if you are using nix flake you can refer to this flake and modify as your need:
# flake.nix
{
description = "php environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in
{
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {
packages = with pkgs; [php84Packages.composer php84];
shellHook = ''
export SHELL=/run/current-system/sw/bin/bash
'';
};
});
};
}
to enter the development shell, first add the flake to your git repo, and then run:
nix develop
# then do your composer stuff
unfortunately i didn’t use flake then how i setup?
There is no need for flakes, you can use nix-shell
as well and define an equivalent shell in shell.nix
.
where? can u gimme the step-by-step guide?
- create
shell.nix
in your project - edit it to contain a proper shell (I do not use laravel or PHP and therefore can’t say anything about the details here)
- save it
- run
nix-shell
to get into your shell or use (nix-
)direnv
for a more seemless integration in your shell.
Yes you can just write your shell.nix like this:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
packages = with pkgs; [php84Packages.composer php84];
}
then in the same directory just run nix-shell.
For php project php and composer is all you will need for development.
Just remember you will need to enter the nix shell everytime you need php and composer.
You might want to read something about how this work from here
https://nixos.wiki/wiki/Development_environment_with_nix-shell