Gnome user-specific locales

Hello,

after using Debian for many years I am trying out Nixos and almost everything works as expected.

Now I’d like to set the language for a (specific) user, but want to keep C or en_US.UTF-8/UTF-8 as the default locale for other users, especially root. So I have

  i18n.supportedLocales = [
    "en_US.UTF-8/UTF-8"
    "de_AT.UTF-8/UTF-8"
  ];

in my configuration. I understand that setting the language in Gnome settings doesn’t work, but I seem to be unable to find any other way.

Is there any configuration option I am missing or do I simply have to set some environment variables like

LANG=de_AT.UTF-8
LC_ALL=de_AT.UTF-8

and if so how can I do it the nixos-way, preferably without using home-manager?

So, you want to set an environment variable for a specific user? That’s probably a home-manager thing.

Do I, i am not too sure about that? Since gnome settings/systemd-localed doesn’t work, it is just the only other possibility to set the locales I know about.

But let’s say I want to set a var for a specific user and do not yet want to use home-manager. There are so many place where I could set a var, that I am still lost

  • I could put it in ~/.zprofile (the user’s default shell is zsh), but without having tested it I suspect that this won’t set the var for the whole gnome session?
  • On the other hand if I put it in ~/.profile and log in on a virtual console in text mode it will not be set either, because zsh ignores it.

Sorry, I must have skipped over this. I don’t see why this shouldn’t work. Did you see anyone else reporting this doesn’t work?

Obviously I am not too familiar with NixOS yet, but as far as I understand, gnome uses systemd-localed to set up locales, but since this would or at least could change the system configuration it is disabled in Nixos [1].

[1] Some standart systemd services are missing from default configuration · Issue #82 · NixOS/nixos · GitHub

Oh, alright. That makes sense.

Well, this is what home-manager is for. If you don’t want to actually use it then at least consider seeing how it does it.

See link at end of this option’s documentation:

https://nix-community.github.io/home-manager/options.xhtml#opt-home.sessionVariables

Also Appendix A. Home Manager Configuration Options

1 Like

Yes, thank you.

I haven’t tested it, but it seems that home-manager would create a shell script ~/.nix-profile/etc/profile.d/hm-session-vars.sh, which then would be sourced by all shells.

Have you tried changing the language? I’m quite sure it should work. I manually changed gnome settings many times without issue.
NixOS manages system level configuration. User level settings like your gnome user’s language should be unchanged, unless you are using Home Manager to overwrite them.

I don’t know, it’s probably possible (since basically everything is when using Nix :smile: ), but I’m quite sure it would be easier with Home Manager.
To be honest, for some reason I was also reluctant to start using Home Manager until month or two ago. I don’t know why I was reluctant, but I’m very glad that I started using it. Configuring Gnome with Home Manager is really easy, change whatever you want in Gnome setting and just use dconf dump /org/gnome and add those dconf setting to you Home Manager module. You can see how I did it here: nix-setup/modules/home-manager/default.nix at a41e35034f500e23359045e94be643d4bff60ad5 · MatejaMaric/nix-setup · GitHub

Yes, I did (with no effect).

I did too, but I guess you never tried to change the language? :wink:

I searched for an explanation and found the one on github I posted earlier. gnome-settings not only allows to set the language of the logged in user, but also for the login screen. It relies on systemd-localed, which is disabled in nixos, probably exactly for this reason.

$ systemctl status systemd-localed  
○ systemd-localed.service - Locale Service
     Loaded: loaded (/etc/systemd/system/systemd-localed.service; linked; preset: enabled)
     Active: inactive (dead)
       Docs: man:systemd-localed.service(8)
             man:locale.conf(5)
             man:vconsole.conf(5)
             man:org.freedesktop.locale1(5)

I already did the same thing to change the systemwide dconf-defaults (without home-manager), so I can see how convenient home-manager would be.

There a few reasons for me not using it, at least not yet for my private computer:

  • I don’t understand what it would do in certain situations: For example if I already had written my own .zshrc and used home-manager to configure zsh, what would happen to my existing .zshrc?
  • I have a lot configuration files and shell scripts in my home directory. It would take me ages to move the configuration into home-manager (if it is even possible for all programs) and I haven’t found out yet if or how I could put my shell scripts into the nixos configuration.
  • In the future I do want to keep my files (documents, photos, music,…) somewhere else, but right now most of them are still in my home directory and as long as they are there, I’ll have to take my home-directory with me anyway, so I don’t think I would benefit greatly from home-manager.
1 Like

Home Manager will error out before overwriting any existing files. (And in case there’s a bug… you back up your home directory, right?)

Home Manager isn’t an all-or-nothing thing. Keep as much config out of it as you want. I started with just a list of home.packages because I thought using sudo to edit a system-wide config file just to add a program for myself was silly, and only gradually started adding config stuff to it. I’m still only around 60% migrated. It’s totally fine.

2 Likes