NixOS: How to granularly configure locale settings? - locale

On my home laptop running NixOS 19.03, in /etc/nixos/configuration.nix, I use the default locale settings:
i18n = {
consoleFont = "Lat2-Terminus16";
consoleKeyMap = "us";
defaultLocale = "en_US.UTF-8";
};
That's the only way I know to control locale settings in NixOS, and it's too broad. I want more granular control, so that I can use a mixture of US English and Colombian Spanish. (That's a consequence of my job, not a personal choice.) Specifically, I need these settings:
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=es_CO.UTF-8
LC_TIME=es_CO.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=es_CO.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=es_CO.UTF-8
LC_NAME=es_CO.UTF-8
LC_ADDRESS=es_CO.UTF-8
LC_TELEPHONE=es_CO.UTF-8
LC_MEASUREMENT=es_CO.UTF-8
LC_IDENTIFICATION=es_CO.UTF-8
LC_ALL=
On my work desktop (running Ubuntu 18.04), if I evaluate locale in bash, that's what I see. On my home NixOS system, each of those variables is either set to US English or nothing:
[jeff#jbb-dell:~/nix-jbb]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
I thought maybe I should edit /etc/locale.conf, copying the settings from my work system into it. But when (on the NixOS system) I print that file to screen, it doesn't include any of the above variables except LANG:
[jeff#jbb-dell:~/nix-jbb]$ cat /etc/locale.conf
LANG=en_US.UTF-8
[jeff#jbb-dell:~/nix-jbb]$
Therefore the other variables, like LC_NUMERIC, must be getting set somewhere else. I'm worried that if I edit /etc/locale.conf I'll break my system. Is editing that file the right way to set granular locale information in NixOS? And if not, what is?

The option i18n.extralocalesettings is where to set those. E.g.:
i18n.extraLocaleSettings = {
LC_MESSAGES = "en_US.UTF-8";
LC_TIME = "de_DE.UTF-8";
}

I have never seen a NixOS setting for that, but I guess you can work around that with:
services.xserver.displayManager = {
sessionCommands = ''
export LC_NUMERIC=es_CO.UTF-8
export LC_TIME=es_CO.UTF-8
export LC_MONETARY=es_CO.UTF-8
export LC_PAPER=es_CO.UTF-8
export LC_NAME=es_CO.UTF-8
export LC_ADDRESS=es_CO.UTF-8
export LC_TELEPHONE=es_CO.UTF-8
export LC_MEASUREMENT=es_CO.UTF-8
export LC_IDENTIFICATION=es_CO.UTF-8
'';
};
This should work for all your local (graphical) sessions. If you access this computer with ssh as well, you might add the same exports also to ~/.bashrc
If you don't want to have the setting for all users, you can also add the exports to ~/.xession instead of /etc/nixos/configuration.nix as shown above.

Related

Access to ENV variables defined in ${workspaceFolder}/.env files

For a project I need to define the ENVIRO variable (and some others) with the values prod/stage/dev.
This variable is used in .devcontainer/docker-compose.yml, .devcontainer/Dockerfile, some shell scripts and the Python source to set paths and the like.
Therefore I defined the file ${workspaceFolder}/.env which is imported by the Python extension like described here:
ENVIRO=dev
...
To avoid to execute / debug my code in the wrong environment, I wanted to create a little VSC extension, which does nothing else than to show the value of the ENVIRO variable in the Status Bar at the bottom.
Now the problem. In the extensions activate function I don't get access to the ENV variables defined in .env file:
const envValue = process.env["ENVIRO"];
// gives: undefined
In an terminal in the same VSC instance:
echo $ENVIRO
# gives: dev
When I access ENV variables defined by the system (not the .env file), there is no problem to access them in the extension's activate function:
export function activate( context: vscode.ExtensionContext) {
const envValue = process.env["NVM_BIN"];
// gives: '/Users/andi/.nvm/versions/node/v14.15.1/bin'
Is there no way to access this variable?
My suspicion is following:
The Python extension extends the Environment with the variables using the EnvironmentVariableCollection
This adds them to the terminal environment, but prevents access to the variables in other extensions.
Or do I (hopefully) miss something?

What is the GNOME_TERMINAL_SCREEN environment variable?

I've recently installed Ubuntu 20.4 LTS on one of my computers. This release of Ubuntu uses the gnome desktop manager (3.36.3) with gnome-terminal (3.36.2) by default.
In each terminal window that I open, the GNOME_TERMINAL_SCREEN environment variable is defined to "/org/gnome/Terminal/screen/some-guid", where each terminal window's GUID is unique.
Does anyone know what this variable is supposed to be used for? Is there some way of using the GUID in Xlib or XCB to identify the terminal's X window?
The $GNOME_TERMINAL_SCREEN environment variable contains an object path for D-Bus.
It is used to address a tab in the Gnome Terminal when starting a process in it, and to be signalled of its termination.
You can see the relevant part of its D-Bus interface by running this command:
dbus-send --session --type=method_call --print-reply \
--dest=org.gnome.Terminal "$GNOME_TERMINAL_SCREEN" \
org.freedesktop.DBus.Introspectable.Introspect
The output (snipped for relevance):
[...]
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.64.6 -->
<node>
[...]
<interface name="org.gnome.Terminal.Terminal0">
<method name="Exec">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="aay" name="arguments" direction="in"/>
</method>
<signal name="ChildExited">
<arg type="i" name="exit_code"/>
</signal>
</interface>
</node>
If you run dbus-monitor and open and close a Gnome Terminal tab, you can see the D-Bus communication in action.
The X Window System is not aware of what goes on in the D-Bus realm, and as far as I know Gnome Terminal does not expose any X specific information through D-Bus.
I have found one way to tie a process to the X window of a Gnome Terminal in which it is running, but it is less than ideal. Nonetheless, it may suffice for your purposes.
The idea as that when opening a Gnome Terminal window, we will generate an identifying value, and store it both in an X property of the Gnome Terminal window, and in an environment variable.
We can then later get the environment variable from the environment of the process (via /proc/<pid>/environ if needed), and scan the windows for the one which has our value in the X property.
As the window does not exist yet when opening a new Gnome Terminal, we can not set a property ourselves, but the gnome-terminal command accepts an option --role, and stores its value in the WM_WINDOW_ROLE X property of the Gnome Terminal window.
The purpose of the WM_WINDOW_ROLE X property is to uniquely identify windows belonging to the same client.
Without --role, Gnome Terminal assigns it a unique value, but you can do this yourself.
So here is a start-gnome-terminal wrapper, which you could invoke from the key binding which would normally start gnome-terminal:
#!/bin/sh
FINDWIN_ROLE=findwin-role-$(xxd -p -l 16 < /dev/urandom)
export FINDWIN_ROLE
exec gnome-terminal --role "$FINDWIN_ROLE" "$#"
To look through the windows for the property later, you could use wmctrl -l and xprop.

lighttpd not making global environment variables availble to executables

How to set up lighttpd in order to make environment variables available to spawned processes?
I have an executable being called through CGI as an URL (e.g. http://.../cgi-bin/executable.bin).
The executable needs to load libraries and read environment variables that are set in /etc/profile using export FOO=BAR.
When I try to access the URL, it generates Internal Server Error (500), caused by an empty environment variable, which are properly set in /etc/profile.
I ended up enabling mod_setenv in modules.conf and including each environment variable I needed like this:
##
## mod_setenv
##
setenv.add-environment = ( "PATH" => env.PATH,
"WSFC_HOME" => env.WSFC_HOME,
"LD_LIBRARY_PATH" => env.LD_LIBRARY_PATH )

How to give version to a module loaded on HPC

I am very new to linux environment and I have an issue with loading a module in linux. The problem is I am trying to point an already loaded module to the one present in my local directory. For this I have changed all the path that would point the module to my local directory and also updated the MODULEPATH with my local directory path.
This is the command I am using for changing the MODULEPATH
export MODULEPATH=~/local/directory:${MODULEPATH}
Though the question I have is completely different, how to give a version number to my module?
I have a moudle file which looks like this -
#%Module
proc ModulesHelp { } {
puts stderr "Sets up users' environment to use XXXX. XXXX is the ..\n.. It is a piece of middleware developed by XXXX to \nhelp track XXX usage. \n\nIf you encounter any problems while linking or while executing aprun, please unload this module."
}
conflict totalview
setenv XXXX_SELECT_ON 0
setenv XXXX_SELECT_USERS kagrawa1
setenv XXXX_SELECT_OFF_USERS ""
setenv XXXX_VERBOSE 0
setenv XXXX_ON 1
setenv XXXX_PATH /d/home/kpilagr/
prepend-path PATH /nics/d/home/kagrawa1/altd/bin

Localizing Firefox OS (B2G)

I am trying to install a new locale in Firefox OS, but I am not sure if I am following the steps well.
Firstly, I tried to use Mercurial to download the desired locale: It
didn't work for me, Mercurial says that access is denied, so I had
to download the ZIP manually.
hg clone ssh://hg.mozilla.org/gaia-l10n/es locales/es
Secondly, unzipped it in B2G/gaia/locales/ and renamed the directory from es-7c2fcf6d1348/ to 'es'.
Thirdly, I have edited B2G/gaia/locales/dev_languages.json in order
to enable the desired language and I have set the following
environment variables:
export LOCALE_BASEDIR=$PWD/locales/
export LOCALES_FILE=$PWD/locales/languages_dev.json
export GAIA_DEFAULT_LOCALE=es
At last, I flash Gaia into my mobile device doing "make reset-gaia".
sudo NTFU=0 DOGFOOD=0 PRODUCTION=1 REMOTE_DEBUGGER=1 DEBUG=1 make reset-gaia
I expected to see the spanish language installed in the device, but it is not available. Am I missing anything?
By the way, is there any way to fix the Mercurial error?
Re the hg error, you'll want to clone via http:// instead of ssh://, then you'll be fine. You want to make sure that the branch you're using matches the one of the gaia version you're trying to work on.
The Spanish community works on transifex, https://www.transifex.com/accounts/profile/willyaranda/ has the various projects.
As for getting your local copy onto a device, flod maintains https://l10n.etherpad.mozilla.org/gaia-multilocale, that should be up-to-date. (Disclaimer, it did go through some data-loss and was buggy lately, etherpad problems)
this is my .userconfig file, which is on my b2g root:
 gll  /  b2g  1.2  cat .userconfig    master 
#export GECKO_OBJDIR=/Volumes/Trabajo/repos/mozilla-central/objdir-gonk
#export GECKO_PATH=/Volumes/Trabajo/repos/mozilla-central/
export REMOTE_DEBUGGER=1
export DEVICE_DEBUG=1
export MOZILLA_OFFICIAL=1
export PRODUCTION=1
## Gaia
export GAIA_DEFAULT_LOCALE=es
export LOCALE_BASEDIR='/b2g/gaia-locales-1.2/'
export LOCALES_FILE='/b2g/languages_propio.json'
## Gecko
export L10NBASEDIR='/b2g/gecko-locales-1.2/'
export MOZ_CHROME_MULTILOCALE="es-ES eu ca gl pt-BR"
export PATH="$PATH:/b2g/compare-locales/scripts"
export PYTHONPATH="/b2g/compare-locales/lib"
export CC='ccache /usr/bin/gcc-4.6'
export CXX='ccache /usr/bin/g++-4.6'
export CCACHE_DIR='/b2g/.ccache'
where locales_propio.json is as follows:
 gll  /  b2g  1.2  cat ../languages_propio.json
{
"ca" : "Català",
"en-US" : "English (US)",
"es" : "Español",
"eu" : "Euskara",
"gl" : "Galego",
"pt-BR" : "Portugués (BR)"
}
Here, you can add your Gaia constants, as you can see.
You must clone your locales in your LOCALE_BASEDIR, depending on the branch:
https://hg.mozilla.org/releases/gaia-l10n/v1_2/
https://hg.mozilla.org/gaia-l10n/
Cheers,
Guillermo
here's a gist help you customize your locales and keyboard dictionaries
https://gist.github.com/timdream/7716684

Resources