New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declarative management of user environments and config files #1750

Closed
jameshfisher opened this Issue Feb 15, 2014 · 16 comments

Comments

Projects
None yet
@jameshfisher
Copy link

jameshfisher commented Feb 15, 2014

I have a user called james declared in my configuration.nix. What's not clear to me is how I customize those users' environments and config files. For example, can I declare that james should have

  • some extra package, e.g. pkgs.git, installed and available just to him.
  • a file .gitconfig in his home directory with such-and-such contents in it. (Or, more generally, an arbitrary set of files to be put in the home directory.)

On the second point, I suppose ideally this kind of config should be done by Nix expressions in the same way as global config files are. But there are always going to be custom things that are not covered by the options in configuration.nix, so I would expect there to be a lower-level way to declaratively manage those things. Is it currently possible?

@peti

This comment has been minimized.

Copy link
Member

peti commented Feb 16, 2014

configuration.nix doesn't manage user environments. If you want to configure that user's environment, then the standard way to do it is to log in as james and install the appropriate packages by running nix-env.

@shlevy

This comment has been minimized.

Copy link
Member

shlevy commented Apr 5, 2014

There are some (largely amorphous) thoughts about user nixos, but for now this is not supported.

@shlevy shlevy added the enhancement label Apr 5, 2014

@kamilchm

This comment has been minimized.

Copy link
Contributor

kamilchm commented Aug 18, 2014

I'm a Debian user and I want to migrate to NixOS. I tought that I can:

  1. Install Nix on my Debian
  2. Build my environment configuration in some *.nix file with packages I use
  3. Store my configuration in git repo
  4. Install fresh NixOS
  5. Import my nix configuration from git
  6. Build new user environment on NixOS

This issue seems like feature I need.
Or maybe there is some other way that help me do the migration to NixOS?

@wmertens

This comment has been minimized.

Copy link
Contributor

wmertens commented Aug 18, 2014

@kamilchm so right now, NixOS differs from NixPkgs in that NixPkgs only provides compiled packages and NixOS provides "modules" which create configuration files for those packages.
If you're using Nix on Debian, you're using NixPkgs. The set of installed packages is determined by what is under /nix/var/nix/profiles/per-user/kamilchm/default, and it is influenced by your .nixpkgs/config.nix if you have it.
If you want to copy your environment to a fresh NixOS install, you need to copy the entire closure, either via ssh with nix-copy-closure or manually by transferring the result of nix-store --query --requisites ~/.nix-profile.
Easiest is of course to simply use the same nix store.

@lethalman

This comment has been minimized.

Copy link
Contributor

lethalman commented Aug 18, 2014

I'm running nixos in a subdirectory of my Debian if that is of any interest
for you. So without re-partitioning and without installing grub in the mbr,
I can choose at boot time whether I want to boot into debian or into nixos.
Yet you can use your data in debian from a mountpoint inside nixos. I'm not
using debian since several months at all.

On Mon, Aug 18, 2014 at 3:10 PM, wmertens notifications@github.com wrote:

@kamilchm https://github.com/kamilchm so right now, NixOS differs from
NixPkgs in that NixPkgs only provides compiled packages and NixOS provides
"modules" which create configuration files for those packages.
If you're using Nix on Debian, you're using NixPkgs. The set of installed
packages is determined by what is under
/nix/var/nix/profiles/per-user/kamilchm/default, and it is influenced by
your .nixpkgs/config.nix if you have it.
If you want to copy your environment to a fresh NixOS install, you need to
copy the entire closure, either via ssh with nix-copy-closure or manually
by transferring the result of nix-store --query --requisites
~/.nix-profile.
Easiest is of course to simply use the same nix store.


Reply to this email directly or view it on GitHub
#1750 (comment).

www.debian.org - The Universal Operating System

@kamilchm

This comment has been minimized.

Copy link
Contributor

kamilchm commented Aug 18, 2014

As I understand NixOS I want to end up with configuration.nix like https://github.com/chaoflow/nixos-configurations/blob/master/configuration-eve.nix but build list of all systemPackages now using only Nix with my current Debian.
@lethalman could you tell something more about NixOS in subdirectory of Debian? How can I install and run it that way?

@lethalman

This comment has been minimized.

Copy link
Contributor

lethalman commented Aug 18, 2014

NixOS is all or nothing. It's better you don't mess with nixos
configuration inside debian. That is, the simplest option is to install nix
in debian so that you can use the nixpkgs packages. But not nixos services.

About nixos in a subdirectory, I run a patched nixpkgs with this PR which
is still wip: #3143
Basically, you install nixos in a subdir like /nixos, nixos initrd will
mount your /dev/sdaX in something like /mnt/real-root and then
/mnt/real-root/nixos will be bind-mounted to /. It requires a little of
knowledge of linux and basic nixos.
If you are willing to do this setup I can help, however I highly suggest
you to first try out nixos in a VM or such if it's your first time.

On Mon, Aug 18, 2014 at 5:50 PM, Kamil Chmielewski <notifications@github.com

wrote:

As I understand NixOS I want to end up with configuration.nix like
https://github.com/chaoflow/nixos-configurations/blob/master/configuration-eve.nix
but build list of all systemPackages now using only Nix with my current
Debian.
@lethalman https://github.com/lethalman could you tell something more
about NixOS in subdirectory of Debian? How can I install and run it that
way?


Reply to this email directly or view it on GitHub
#1750 (comment).

www.debian.org - The Universal Operating System

@kamilchm

This comment has been minimized.

Copy link
Contributor

kamilchm commented Aug 18, 2014

OK, so I'll stick with VM as I started. Migration should be easy enough after I build my VM as I like. Thx for info :)

@domenkozar

This comment has been minimized.

Copy link
Member

domenkozar commented Nov 27, 2015

Prototype implementation: #9250

@zimbatm

This comment has been minimized.

Copy link
Member

zimbatm commented Feb 19, 2016

This would be huge.

Right now most nixos users are also root on their machines and thus tend to encode everything on a system level. As a non-root user it's hard to port all of my config to another machine. It would great if instead I could port a set of nix expressions and have everything installed with a single command.

@kamilchm

This comment has been minimized.

Copy link
Contributor

kamilchm commented Feb 19, 2016

Declarative user enviroment was the biggest benefit of using NixOS that I thought I would get after moving to NixOS.
Because of that this was my first target as NixOS user.
I found package collections on https://nixos.org/wiki/Howto_keep_multiple_packages_up_to_date_at_once and started to do it that way, ended with https://github.com/kamilchm/.nixpkgs where I declare all packages and configs I need.
So if I'll need to move to different machine everything I need is just git clone ... and nix-env -i all.

Maybe I don't understand this PR correctly, but I can port all of my config to another machine now without this PR.
But it would be great if we get standard solution with separate command design exactly for this 👍

@zimbatm

This comment has been minimized.

Copy link
Member

zimbatm commented Feb 19, 2016

That's really cool. Thanks a lot for the example !

@anderspapitto

This comment has been minimized.

Copy link
Contributor

anderspapitto commented Jun 5, 2016

@kamilchm I don't quite follow how your setup works for dotfiles. For example, does your .bashrc file end up in your home directory? It seems to be installed in $out/userHome, which presumably is a path in /nix/store - so how does bash know to look there for its config file?

@kamilchm

This comment has been minimized.

Copy link
Contributor

kamilchm commented Jun 5, 2016

Yoou're right, it's not complete,
I've done one thing after nix-env -i all:

find .nix-profile/userHome/ | sed "s/.nix-profile\/userHome\///g" | grep -v "^$" | xargs -I {} echo "ln -s ~/nix.profile/userHome/{} ~/{}"
@domenkozar

This comment has been minimized.

@Profpatsch Profpatsch closed this Jun 24, 2018

@asymmetric

This comment has been minimized.

Copy link
Contributor

asymmetric commented Oct 13, 2018

An alternative to sheenobu/nix-home (mentioned in the nix-cookbook FAQ) is rycee/home-manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment