Hey,
I was wondering how I could create a devShell using a flake, for developing my database using postgreSQL.
Currently I have the following flake setup:
{
description = "Nix flake for postgresql environment.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
};
outputs = { self, nixpkgs, ... }:
let
system = "x86_64-linux";
in {
devShells."${system}".default =
let
pkgs = import nixpkgs { inherit system; };
in pkgs.mkShell {
packages = with pkgs; [
postgresql
];
shellHook = ''
postgres --version
'';
};
};
}
I then initialised my database with init -D data.
But when I run pg_ctl -D data -l logfile start I have an issue from within the logfile:
2025-10-09 14:13:44.668 BST [304481] FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
Now, I understand that NixOS doesn’t have a /run/ directory, and that postgreSQL is trying to setup its port number as 5432. Is there a way that I could do this within the flake.nix file using devShells? Or is it not possible to do so, since it is interacting with the system?
Correction: NixOS does have /run. Thanks @emmanuelrosa