Closed glottologist closed 2 months ago
Postgres service doesn't start using the flake.parts template.
Is there an error? What do you get when you run devenv up
?
@sandydoo No error. The shell comes up and uses the hello package but there is no instance of Postgres, nor any reference to Postgres when the shell is building as far as I can tell
@sandydoo I also don't think this is specific to Postgres as if I add other services like:
services.mysql.enable = true;
services.nginx.enable = true;
services.influxdb.enable = true;
services.couchdb.enable = true;
services.cassandra.enable = true;
services.clickhouse.enable = true;
I can see the packages being built in the nix store but the services do not come up in the dev env
I cannot replicate this on my end. The following works as expected:
nix develop --impure
devenv up
The processes need to be launched with devenv up
. They're not launched when entering the shell.
This issue is happening to me.
The problem is devenv is not creating state in .devenv/state/postgres
and says that it has a permission error.
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
devenv.url = "github:cachix/devenv";
nix2container.url = "github:nlewo/nix2container";
nix2container.inputs.nixpkgs.follows = "nixpkgs";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs =
inputs@{ flake-parts, nixpkgs, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.devenv.flakeModule ];
systems = nixpkgs.lib.systems.flakeExposed;
perSystem =
{
config,
self',
inputs',
lib,
pkgs,
system,
...
}:
{
devenv.shells.default = {
difftastic.enable = true;
packages = lib.optionals pkgs.stdenv.isDarwin (
with pkgs;
[
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
sqlx-cli
bacon
]
);
languages.rust = {
enable = true;
channel = "stable"; # or "nightly"
toolchain = {
rustc = pkgs.rustc-wasm32;
};
targets = [ "wasm32-unknown-unknown" ];
};
services.postgres = {
enable = true;
package = pkgs.postgresql_16;
listen_addresses = "127.0.0.1";
initialDatabases = [{ name = "teaclient"; }];
};
env = {
DATABASE_URL= "postgresql://teaclient:teaclient123@localhost:6500/teaclient?schema=public";
};
dotenv.enable = false;
};
};
};
}
using flake on v1.0.7
It works with devenv up
.
It seems devenv up
creates the necessary files to run postgres but nix develop --impure
doesn't.
if you do mkdir .devenv/state/postgres
and then get out and enter it, it will say:
postgres: could not access the server configuration file "/Users/eveeifyeve/projects/TeaClient/API/.devenv/state/postgres/postgresql.conf": No such file or directory
but when you create the file it says this:
2024-07-07 01:21:43.075 GMT [29378] FATAL: data directory "/Users/eveeifyeve/projects/TeaClient/API/.devenv/state/postgres" has invalid permissions
which could be the issue that devenv has a permission issue with nix develop --impure
which means that it can't create the directory. but the weird thing it creates the .devenv/state/run/postgres
directory with nothing.
It works with
devenv up
.
@Eveeifyeve, this is how it is intended to work. Services are launched via devenv up
.
It seems devenv up creates the necessary files to run postgres but nix develop --impure doesn't.
Initial database setup currently happens when the service is launched (devenv up
).
What exactly are you trying to accomplish?
If you have a compelling use-case, please, open a separate issue.
which could be the issue that devenv has a permission issue with nix develop --impure which means that it can't create the directory. but the weird thing it creates the .devenv/state/run/postgres directory with nothing.
The errors you're seeing have nothing to do with devenv.
First of all, everything in .devenv
is internal devenv state. You shouldn't be creating or modifying files in there.
Secondly, a postgresql
database needs to be initialized through initdb
. devenv
does this and more for you.
Closing this issue as the OP likely needed to launch the services with devenv up
. @glottologist, feel free to reopen if that is not the case.
Describe the bug Postgres service doesn't start using the flake.parts template.
To reproduce Run
nix develop --impure
with the following flake:I would expect a postgres instance to be spun up according to the service specification.
Version Using flakes ver 1.0.7