I have a very basic usage - launch a postgres docker with nix env, but I do not find corresponded docs on the internet. Also searching here with keywords like nix and docker returns nixos in docker that kind of questions or cache nix store in gitlab ci. Those are different from what I am after. So here is my question; and please correct me pointing to the doc that I should read first. I appreciate it.
My use case is to create an env in nix where I can launch postgres docker because later on I may have multiple different nix envs with corresponded postgres docker instances running at the same time on the same machine for different purposes.
The doc I follow is this one[1]. I can create nix env with following nix content, and can confirm there exists postgres command.
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.postgresql
pkgs.nixos-container
];
}
However, when trying the second step nixos-container create foo --config-file postgres-config.nix
, nix env complains
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US:en",
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
write_file '/etc/containers/foo.conf' - sysopen: Permission denied at /nix/store/jpx4hfriwdycw5rn7prblsf8mnk8g97f-nixos-container/bin/nixos-container line 250.
where postgres-config.nix uses the exact same config file mentioned in the doc as below
{ pkgs, ... }:
{
system.stateVersion = "20.09";
networking.firewall.allowedTCPPorts = [ 5432 ];
services.postgresql = {
enable = true;
enableTCPIP = true;
extraPlugins = with pkgs.postgresql.pkgs; [ postgis ];
authentication = "host all all 10.233.0.0/16 trust";
ensureDatabases = [ "foo" ];
ensureUsers = [{
name = "foo";
ensurePermissions."DATABASE foo" = "ALL PRIVILEGES";
}];
};
}
If I run nixos-container with sudo, it will complains sudo: nixos-container: command not found
because there is no nixos-container for root, and I do not want to use root to do that as well.
How can I set LOCALE for nix postgres env and how to prevent nixos-container write postgres config file foo.conf to /etc? Or what is the correct way to do that?
I appreciate any suggestions and commentary, thanks!
[1]. inv.alid.pw - Setting up a dev environment for PostgreSQL with nixos-container