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

nixuser: declarative user environments #9250

Open
wants to merge 11 commits into
base: master
from

Conversation

@ts468
Contributor

ts468 commented Aug 14, 2015

What is Nix User Profile (NixUP)? NixUP is a declarative configuration for the user environment. It is an equivalent to the NixOS configuration method that is based around 'nixos-rebuild' and '/etc/nixos/configuration.nix'. NixUP provides a module system for configuring the user environment and is intended as a replacement for the imperative 'nix-env' commands. NixUP allows to, e.g., install packages, manage user defined services and to manage resources.

NixUP consists of a new program, called 'nixup' and a declarative configuration rooted at '$XDG_CONFIG_HOME/nixup/profile.nix' (e.g. ~/.config/nixup/profile.nix). Basically, the workflow for managing the NixUP user profile is the same as how the NixOS system configuration is being managed. The 'profile.nix' is edited by the user, and then turned into an active environment through 'nixup'.

The important commands for using 'nixup' are:

nixup build
-- Builds a user profile. By default the profile is defined
in $XDG_CONFIG_HOME/nixup/profile.nix.

nixup login
-- Builds a user profile that will be activated on the next login.
That is similar to nixos-rebuild boot.

nixup switch
-- Builds a user profile and immediately switches to it.

nixup edit
-- Opens an editor with the current configuration.

NixUP also brings an small program that helps to install and to remove software packages. If 'config.imperativeNix.enable=true' is set in the 'profile.nix' configuration, then a program 'nix-package' becomes available that manages a list of packages to be installed into the user environment. By default the list is maintained at '$XDG_CONFIG_HOME/nixup/packages.nix', from where the list is read by a module of the NixUP system.

The commands for using 'nix-package' are:

nix-package install hello

nix-package remove hello

Note that the packages are not pinned at a particular version but are linked to the currently active nixpkgs channel. A way to pin a package will be provided later.

Besides managing software packages, NixUP also provides a way to manage user controlled services. NixUP allows to define services for 'systemd --user', similarly to how NixOS allows to define services for 'systemd'. That means that the feature of managing services within NixUP is bound very tightly to 'systemd', and will not be available on other platforms like OSX or Windows.

The last interesting feature of NixUP is that is allows to manage resources. That means, it allows to define files in 'profile.nix' that are then linked into the $HOME directory of a user, or into any sub-directory of $HOME. The necessary sub-directories and links are created as needed, and automatically removed when the 'profile.nix' changes. Automatically created sub-directories are removed if they are empty after all links have been removed. So NixUP has a built-in way for managing, e.g., dot-files.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 14, 2015

Contributor

Could I get some feedback and ideas about how to name the configuration tree for nixuser, please?

@nbp Can it be merged with #4594?

Contributor

ts468 commented Aug 14, 2015

Could I get some feedback and ideas about how to name the configuration tree for nixuser, please?

@nbp Can it be merged with #4594?

@jgeerds

This comment has been minimized.

Show comment
Hide comment
@jgeerds

jgeerds Aug 14, 2015

Member

Great work! 👍

Member

jgeerds commented Aug 14, 2015

Great work! 👍

@jagajaga

This comment has been minimized.

Show comment
Hide comment
@jagajaga

jagajaga Aug 14, 2015

Member

Why do we need this when we have .nixpkgs/config.nix where we can write our environments?
I think that's an redundant work and can confuse people.

Member

jagajaga commented Aug 14, 2015

Why do we need this when we have .nixpkgs/config.nix where we can write our environments?
I think that's an redundant work and can confuse people.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 14, 2015

Contributor

Just to preempt a discussion about WHY we need it, don't be tricked by the simplicity of the settings that are available so far. Nixuser is intended as a central place where user environment related configuration options can be collected. So it goes beyond an individually created .nixpkgs/config.nix.

Contributor

ts468 commented Aug 14, 2015

Just to preempt a discussion about WHY we need it, don't be tricked by the simplicity of the settings that are available so far. Nixuser is intended as a central place where user environment related configuration options can be collected. So it goes beyond an individually created .nixpkgs/config.nix.

@jagajaga

This comment has been minimized.

Show comment
Hide comment
@jagajaga

jagajaga Aug 14, 2015

Member

That's an extra thing. I really don't see anything we don't have now that you want there.
The only thing we miss --- managing user dotfiles.

Member

jagajaga commented Aug 14, 2015

That's an extra thing. I really don't see anything we don't have now that you want there.
The only thing we miss --- managing user dotfiles.

@dezgeg

This comment has been minimized.

Show comment
Hide comment
@dezgeg

dezgeg Aug 14, 2015

Contributor

For instance, per-user declarative systemd services (with e.g. the same start/stop and restart-if-config-changed logic that nixos-rebuild has) is something that needs nixuser-rebuild and can't be done with .nixpkgs/config.nix alone.

Contributor

dezgeg commented Aug 14, 2015

For instance, per-user declarative systemd services (with e.g. the same start/stop and restart-if-config-changed logic that nixos-rebuild has) is something that needs nixuser-rebuild and can't be done with .nixpkgs/config.nix alone.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 14, 2015

Contributor

@jagajaga maybe you want to write a nixuser module to manage dot-files?---It would be great contribution!

Contributor

ts468 commented Aug 14, 2015

@jagajaga maybe you want to write a nixuser module to manage dot-files?---It would be great contribution!

@dezgeg

This comment has been minimized.

Show comment
Hide comment
@dezgeg

dezgeg Aug 14, 2015

Contributor

The Obligatory Bikeshed: The filename configuration.nix is sort-of already taken, in particular man configuration.nix already brings up the NixOS manual. Maybe something like ~/.nixuser/user-config.nix?

Contributor

dezgeg commented Aug 14, 2015

The Obligatory Bikeshed: The filename configuration.nix is sort-of already taken, in particular man configuration.nix already brings up the NixOS manual. Maybe something like ~/.nixuser/user-config.nix?

@nbp

This comment has been minimized.

Show comment
Hide comment
@nbp

nbp Aug 14, 2015

Member

Could I get some feedback and ideas about how to name the configuration tree for nixuser, please?

I will look deeply into it later.

@nbp Can it be merged with #4594?

I think so.

The problem I wanted to avoid is that we have to edit a configuration file to add packages.

I think nix-env is a convenient tool for installing new packages. But nixuser-rebuild only provide a NixOS like approach, which is not a user friendly CLI for installing/uninstalling packages.

Member

nbp commented Aug 14, 2015

Could I get some feedback and ideas about how to name the configuration tree for nixuser, please?

I will look deeply into it later.

@nbp Can it be merged with #4594?

I think so.

The problem I wanted to avoid is that we have to edit a configuration file to add packages.

I think nix-env is a convenient tool for installing new packages. But nixuser-rebuild only provide a NixOS like approach, which is not a user friendly CLI for installing/uninstalling packages.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 14, 2015

Contributor

@dezgeg Thanks for pointing that conflict out! I hoped we could mirror nixos-rebuild as much as possible and that motivated ~/.nixuser/configure.nix. Also, what do you think about nixup (nix user profile) instead of nixuser? It's used in #4594 and would also be a good choice. I'm just trying to collect opinions :)

@nbp Thanks for going to have a look! Let me know once I can go ahead with merging our two PRs. However, having an explicit configuration file where all installed packages have to be listed is exactly what I want to achieve! To me it is one of the most important features of NixOS that the whole configuration is in one file or place, and if possible I would like to have (exactly) the same for nixuser/nixup. And, text editors are still a very good CLI based configuration tool, i think ;) But of course you're right that a nice GUI would be highly appreciated! Maybe we can generate one semi-automatically from the module definitions, I think @matejc has been working on something like that.

Contributor

ts468 commented Aug 14, 2015

@dezgeg Thanks for pointing that conflict out! I hoped we could mirror nixos-rebuild as much as possible and that motivated ~/.nixuser/configure.nix. Also, what do you think about nixup (nix user profile) instead of nixuser? It's used in #4594 and would also be a good choice. I'm just trying to collect opinions :)

@nbp Thanks for going to have a look! Let me know once I can go ahead with merging our two PRs. However, having an explicit configuration file where all installed packages have to be listed is exactly what I want to achieve! To me it is one of the most important features of NixOS that the whole configuration is in one file or place, and if possible I would like to have (exactly) the same for nixuser/nixup. And, text editors are still a very good CLI based configuration tool, i think ;) But of course you're right that a nice GUI would be highly appreciated! Maybe we can generate one semi-automatically from the module definitions, I think @matejc has been working on something like that.

@jagajaga

This comment has been minimized.

Show comment
Hide comment
@jagajaga
Member

jagajaga commented Aug 14, 2015

@copumpkin

This comment has been minimized.

Show comment
Hide comment
@copumpkin

copumpkin Aug 15, 2015

Member

Does this depend on NixOS, or could it work on other Nix platforms?

Member

copumpkin commented Aug 15, 2015

Does this depend on NixOS, or could it work on other Nix platforms?

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 15, 2015

Contributor

@copumpkin I think it should work on other platforms as well, but I haven't tested it.

Contributor

ts468 commented Aug 15, 2015

@copumpkin I think it should work on other platforms as well, but I haven't tested it.

@nbp

This comment has been minimized.

Show comment
Hide comment
@nbp

nbp Aug 15, 2015

Member

@nbp Can it be merged with #4594?

Apart from the options for managing the nixpkgs configuration, and the user packages / path, it seems that our implementations can safely be merged, except for renaming integration.

Honestly, I prefer the approach taken in NixOS, which is to have a central list of build targets stored in user.build, and then the top-level script nixuser-rebuild should pull any installable targets from this attribute set.

The interesting part of NixUP is the implementation of the activation script and the resources files, which ideally should be executed by the shell at the start-up of the shell. This activation script serves as an init-system for the user home directory.

I am not convinced by the -rebuild in the nixuser-rebuild name, as I consider this to be an implementation detail.

However, having an explicit configuration file where all installed packages have to be listed is exactly what I want to achieve! To me it is one of the most important features of NixOS that the whole configuration is in one file or place, and if possible I would like to have (exactly) the same for nixuser/nixup. And, text editors are still a very good CLI based configuration tool, i think ;) But of course you're right that a nice GUI would be highly appreciated! Maybe we can generate one semi-automatically from the module definitions, I think @matejc has been working on something like that.

I agree, being able to define packages declaratively is nice, but the imperative style provided by nix-env is convenient.

What I was thinking about was to let the CLI tool generate the modules which are adding the packages in the environment.

Member

nbp commented Aug 15, 2015

@nbp Can it be merged with #4594?

Apart from the options for managing the nixpkgs configuration, and the user packages / path, it seems that our implementations can safely be merged, except for renaming integration.

Honestly, I prefer the approach taken in NixOS, which is to have a central list of build targets stored in user.build, and then the top-level script nixuser-rebuild should pull any installable targets from this attribute set.

The interesting part of NixUP is the implementation of the activation script and the resources files, which ideally should be executed by the shell at the start-up of the shell. This activation script serves as an init-system for the user home directory.

I am not convinced by the -rebuild in the nixuser-rebuild name, as I consider this to be an implementation detail.

However, having an explicit configuration file where all installed packages have to be listed is exactly what I want to achieve! To me it is one of the most important features of NixOS that the whole configuration is in one file or place, and if possible I would like to have (exactly) the same for nixuser/nixup. And, text editors are still a very good CLI based configuration tool, i think ;) But of course you're right that a nice GUI would be highly appreciated! Maybe we can generate one semi-automatically from the module definitions, I think @matejc has been working on something like that.

I agree, being able to define packages declaratively is nice, but the imperative style provided by nix-env is convenient.

What I was thinking about was to let the CLI tool generate the modules which are adding the packages in the environment.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 15, 2015

Contributor

@nbp Thanks for your feedback, I'll take it into account! I already had a closer look at how to merge the two implementations, and I have to say, I just started to fully understand and appreciate all the nice details that you put into NixUP! I think you've done an amazing job! Thank you very much for putting it together, it would be a shame if your work wouldn't make it upstream. I just hope I don't break too much while merging the two PRs.

I was reading up on the mailing list again about your introduction of your PR, especially the question when to activate a new user environment. I think it should be possible to have different options like nixup switch or nixup login or nixup shell to distinguish between an immediate activation, an activation with a new login or an activation just for the current shell. What do you think?

I like the idea about your CLI very much. What about a hidden configuration file outside of the nixup/nixuser configuration tree that is only managed by an CLI, and then sourced appropriately? I could imagine to have, e.g., ~/.nixup/profile/managed/{permanent,temporary} where packages are added or removed. The difference could be that the temporary packages are only available until the next rebuild of the declarative environment, whereas permanent packages are kept until they are removed. Could that work?

Contributor

ts468 commented Aug 15, 2015

@nbp Thanks for your feedback, I'll take it into account! I already had a closer look at how to merge the two implementations, and I have to say, I just started to fully understand and appreciate all the nice details that you put into NixUP! I think you've done an amazing job! Thank you very much for putting it together, it would be a shame if your work wouldn't make it upstream. I just hope I don't break too much while merging the two PRs.

I was reading up on the mailing list again about your introduction of your PR, especially the question when to activate a new user environment. I think it should be possible to have different options like nixup switch or nixup login or nixup shell to distinguish between an immediate activation, an activation with a new login or an activation just for the current shell. What do you think?

I like the idea about your CLI very much. What about a hidden configuration file outside of the nixup/nixuser configuration tree that is only managed by an CLI, and then sourced appropriately? I could imagine to have, e.g., ~/.nixup/profile/managed/{permanent,temporary} where packages are added or removed. The difference could be that the temporary packages are only available until the next rebuild of the declarative environment, whereas permanent packages are kept until they are removed. Could that work?

@nbp

This comment has been minimized.

Show comment
Hide comment
@nbp

nbp Aug 15, 2015

Member

I was reading up on the mailing list again about your introduction of your PR, especially the question when to activate a new user environment. I think it should be possible to have different options like nixup switch or nixup login or nixup shell to distinguish between an immediate activation, an activation with a new login or an activation just for the current shell. What do you think?

The problem, is that as opposed to NixOS, we can have multiple instances of the shell, which can share some common configuration, such as agent program which are running in the background, as long as there is one session open.

Doing it for the current shell sounds interesting, but then the question is how do you ensure that the configuration files are only visible within the current shell and only within any application started by this shell.

Since I read about buildFHSUserEnv, I was wondering if we could use a mount-point namespace solution to make such testing mechanism possible. Then the question, is why do we have a different solution for the testing mechanism and the standard mechanism. If we are going that way, then we should do it for everything. The problem, is that mount-point namespaces are a Linux only feature, as far as know, which makes this unpractical for MacOS users.

I like the idea about your CLI very much. What about a hidden configuration file outside of the nixup/nixuser configuration tree that is only managed by an CLI, and then sourced appropriately?

Yes, that's what I was thinking about, which is to have a ~/.nixup/generated/user.packages.firefox.nix module generated when you install firefox from the command line. And do the same for every option which is defined from the command line.

Basically, the name of the file is used as a simple way to manipulate each definition without having any knowledge on how modules are written & handled.

I could imagine to have, e.g., ~/.nixup/profile/managed/{permanent,temporary} where packages are added or removed. The difference could be that the temporary packages are only available until the next rebuild of the declarative environment, whereas permanent packages are kept until they are removed. Could that work?

That's sounds doable, but I would not worry about that right now.

Member

nbp commented Aug 15, 2015

I was reading up on the mailing list again about your introduction of your PR, especially the question when to activate a new user environment. I think it should be possible to have different options like nixup switch or nixup login or nixup shell to distinguish between an immediate activation, an activation with a new login or an activation just for the current shell. What do you think?

The problem, is that as opposed to NixOS, we can have multiple instances of the shell, which can share some common configuration, such as agent program which are running in the background, as long as there is one session open.

Doing it for the current shell sounds interesting, but then the question is how do you ensure that the configuration files are only visible within the current shell and only within any application started by this shell.

Since I read about buildFHSUserEnv, I was wondering if we could use a mount-point namespace solution to make such testing mechanism possible. Then the question, is why do we have a different solution for the testing mechanism and the standard mechanism. If we are going that way, then we should do it for everything. The problem, is that mount-point namespaces are a Linux only feature, as far as know, which makes this unpractical for MacOS users.

I like the idea about your CLI very much. What about a hidden configuration file outside of the nixup/nixuser configuration tree that is only managed by an CLI, and then sourced appropriately?

Yes, that's what I was thinking about, which is to have a ~/.nixup/generated/user.packages.firefox.nix module generated when you install firefox from the command line. And do the same for every option which is defined from the command line.

Basically, the name of the file is used as a simple way to manipulate each definition without having any knowledge on how modules are written & handled.

I could imagine to have, e.g., ~/.nixup/profile/managed/{permanent,temporary} where packages are added or removed. The difference could be that the temporary packages are only available until the next rebuild of the declarative environment, whereas permanent packages are kept until they are removed. Could that work?

That's sounds doable, but I would not worry about that right now.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 23, 2015

Contributor

I've pushed an updated version of the declarative user environment. I tried to merge with #4594. Have a look and give me some feedback, please!

Contributor

ts468 commented Aug 23, 2015

I've pushed an updated version of the declarative user environment. I tried to merge with #4594. Have a look and give me some feedback, please!

@bjornfor

This comment has been minimized.

Show comment
Hide comment
@bjornfor

bjornfor Aug 23, 2015

Contributor

(I haven't had the time read everything, so I hope I'm not saying something silly, or something already suggested.)

Is it planned to be able to hook into user environments from /etc/nixos/configuration.nix?

I'm thinking that if "~/.nixup/profile.nix" contains

{ config, pkgs, ... }:
{
  user.packages = with pkgs; [ vim firefox thunderbird ];
}

then a similar option can exist in /etc/nixos/configuration.nix (options gets merged):

{ config, pkgs, ... }:
{
  users.extraUsers.<name>.packages = with pkgs; [ vim firefox thunderbird ];
}

Basically, options in "~/.nixup/profile.nix" can be rooted in configuration.nix at "users.extraUsers..*" (or something like it).

Contributor

bjornfor commented Aug 23, 2015

(I haven't had the time read everything, so I hope I'm not saying something silly, or something already suggested.)

Is it planned to be able to hook into user environments from /etc/nixos/configuration.nix?

I'm thinking that if "~/.nixup/profile.nix" contains

{ config, pkgs, ... }:
{
  user.packages = with pkgs; [ vim firefox thunderbird ];
}

then a similar option can exist in /etc/nixos/configuration.nix (options gets merged):

{ config, pkgs, ... }:
{
  users.extraUsers.<name>.packages = with pkgs; [ vim firefox thunderbird ];
}

Basically, options in "~/.nixup/profile.nix" can be rooted in configuration.nix at "users.extraUsers..*" (or something like it).

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 23, 2015

Contributor

@bjornfor Thanks for your interest! Indeed, it is planed to make all NixUP options that are available under "~/.nixup/profile.nix" also available in the NixOS configuration, probably under "users.extraUsers..profile". However, I'm just not so sure how to merge the options defined in NixOS and NixUP, yet. Should they just be added up? Should the options defined in NixOS be defaults that can be overwritten with NixUP, or should that be prohibited? If you have any suggestions or ideas that would be great! :)

Contributor

ts468 commented Aug 23, 2015

@bjornfor Thanks for your interest! Indeed, it is planed to make all NixUP options that are available under "~/.nixup/profile.nix" also available in the NixOS configuration, probably under "users.extraUsers..profile". However, I'm just not so sure how to merge the options defined in NixOS and NixUP, yet. Should they just be added up? Should the options defined in NixOS be defaults that can be overwritten with NixUP, or should that be prohibited? If you have any suggestions or ideas that would be great! :)

@nbp

This comment has been minimized.

Show comment
Hide comment
@nbp

nbp Aug 24, 2015

Member

Basically, options in "~/.nixup/profile.nix" can be rooted in configuration.nix at "users.extraUsers..*" (or something like it).

This can be done quite easily, as by design modules are valid submodules.

Member

nbp commented Aug 24, 2015

Basically, options in "~/.nixup/profile.nix" can be rooted in configuration.nix at "users.extraUsers..*" (or something like it).

This can be done quite easily, as by design modules are valid submodules.

@benley

This comment has been minimized.

Show comment
Hide comment
@benley

benley Aug 29, 2015

Member

I would love to be able to use something like this on non-NixOS systems, fwiw. One can approximate it with buildEnv in ~/.nixpkgs/config.nix, but it would be very, very nice to have something that actually handles user dotfiles.

Member

benley commented Aug 29, 2015

I would love to be able to use something like this on non-NixOS systems, fwiw. One can approximate it with buildEnv in ~/.nixpkgs/config.nix, but it would be very, very nice to have something that actually handles user dotfiles.

# as subcomponents (e.g. the container feature, or nixops if network
# expressions are ever made modular at the top level) can just use
# types.submodule instead of using eval-config.nix
{ # !!! system can be set modularly, would be nice to remove

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

can these first three (system, pkgs, baseModules) already be addressed (which I guess would mean removed, based on the comments?)

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

can these first three (system, pkgs, baseModules) already be addressed (which I guess would mean removed, based on the comments?)

Show outdated Hide outdated nixup/lib/from-env.nix
@@ -0,0 +1,4 @@
# TODO: remove this file. There is lib.maybeEnv now

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

can this already be done?

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

can this already be done?

nix.package = mkOption {
type = types.package;
default = pkgs.nix;

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

what's another possible value that someone might want to set this to?

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

what's another possible value that someone might want to set this to?

This comment has been minimized.

@joachifm

joachifm Aug 30, 2015

Contributor

pkgs.nixUnstable

@joachifm

joachifm Aug 30, 2015

Contributor

pkgs.nixUnstable

Show outdated Hide outdated nixup/modules/config/packages.nix
'';
};
user.pathsToLink =

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

is this dead code due to the commented-out line 10 above?

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

is this dead code due to the commented-out line 10 above?

Show outdated Hide outdated nixup/modules/config/resourceFiles.nix
default = {};
type = types.loaOf (types.submodule options);
example = literalExample ''
[ { target = ".ssh/config";

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

could this be simplified to an attribute set where the key is the file name and the value is the string contents? Nix already has utilities for e.g. reading in file contents as a string (bulitins.readFile), so it seems unecessary to reinvent that with the "source" option

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

could this be simplified to an attribute set where the key is the file name and the value is the string contents? Nix already has utilities for e.g. reading in file contents as a string (bulitins.readFile), so it seems unecessary to reinvent that with the "source" option

Show outdated Hide outdated nixup/modules/misc/legacynixpkgsconfig.nix
in
# allow both:
# { /* the config */ } and

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

it would probably save some copy-pasting beginners some headache to only have one way (the second one)

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

it would probably save some copy-pasting beginners some headache to only have one way (the second one)

Show outdated Hide outdated nixup/modules/nixup/nixup.sh
# If the Nix daemon is running, then use it. This allows us to use
# the latest Nix from Nixpkgs (below) for expression evaluation, while
# still using the old Nix (via the daemon) for actual store access.
if systemctl show nix-daemon.socket nix-daemon.service | grep -q ActiveState=active; then

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

systemctl is-active nix-daemon.socket
systemctl is-active nix-daemon.service

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

systemctl is-active nix-daemon.socket
systemctl is-active nix-daemon.service

Show outdated Hide outdated nixup/modules/nixup/nixup.sh
fi
# First build Nix, since NixOS may require a newer version than the

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

Can this logic be shared with the same logic for the NixOS-level?

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

Can this logic be shared with the same logic for the NixOS-level?

Show outdated Hide outdated nixup/modules/nixup/switch-to-configuration.pl
# Stopping a target generally has no effect on other units
# (unless there is a PartOf dependency), so this is just a
# bookkeeping thing to get systemd to do the right thing.
if (boolIsTrue($unitInfo->{'X-StopOnReconfiguration'} // "no")) {

This comment has been minimized.

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

Is all of this systemd-related logic copy-pasted from NixOS-level code?

@anderspapitto

anderspapitto Aug 30, 2015

Contributor

Is all of this systemd-related logic copy-pasted from NixOS-level code?

Show outdated Hide outdated nixup/modules/nixup/switch-to-configuration.pl
@@ -0,0 +1,458 @@
#! @perl@

This comment has been minimized.

@jagajaga

jagajaga Aug 30, 2015

Member

We are trying to get rid of perl in nix...

@jagajaga

jagajaga Aug 30, 2015

Member

We are trying to get rid of perl in nix...

This comment has been minimized.

@jgeerds

jgeerds Aug 30, 2015

Member

@jagajaga What's the preferred language? Python?

@jgeerds

jgeerds Aug 30, 2015

Member

@jagajaga What's the preferred language? Python?

This comment has been minimized.

@dezgeg

dezgeg Aug 30, 2015

Contributor

Isn't that just for the nix core, not NixOS/nixpkgs

@dezgeg

dezgeg Aug 30, 2015

Contributor

Isn't that just for the nix core, not NixOS/nixpkgs

This comment has been minimized.

@jagajaga

jagajaga Aug 30, 2015

Member

I think this issue can be related to this module.

@jagajaga

jagajaga Aug 30, 2015

Member

I think this issue can be related to this module.

This comment has been minimized.

@edolstra

edolstra Aug 31, 2015

Member

@jagajaga We may be trying to get rid of Perl in Nix, but not in NixOS.

@edolstra

edolstra Aug 31, 2015

Member

@jagajaga We may be trying to get rid of Perl in Nix, but not in NixOS.

@nbp

This comment has been minimized.

Show comment
Hide comment
@nbp

nbp Aug 30, 2015

Member

The first version does not have to be perfect, it just has to handle basic features on which we can iterate.

If you want to eliminate dead code, rewrite everything in another language, share the logic with other part of the repository, … then we can still do these after these modifications are merged.

The most important part is to have something which is working, and merged.
Do anybody see any blocker which might prevent this from working?

Member

nbp commented Aug 30, 2015

The first version does not have to be perfect, it just has to handle basic features on which we can iterate.

If you want to eliminate dead code, rewrite everything in another language, share the logic with other part of the repository, … then we can still do these after these modifications are merged.

The most important part is to have something which is working, and merged.
Do anybody see any blocker which might prevent this from working?

Show outdated Hide outdated nixos/modules/config/nixup.nix
# Activate nixup user profile.
if test -e $NIXUP_USER_PROFILE_DIR/default/activate; then
HOME=$PAM_HOME $NIXUP_USER_PROFILE_DIR/default/activate

This comment has been minimized.

@dezgeg

dezgeg Aug 30, 2015

Contributor

Isn't this executing a user-controlled script as root?

@dezgeg

dezgeg Aug 30, 2015

Contributor

Isn't this executing a user-controlled script as root?

Show outdated Hide outdated nixos/modules/installer/tools/nixos-install.sh
@@ -219,6 +219,7 @@ NIX_PATH="nixpkgs=/tmp/root/$nixpkgs:nixos-config=$NIXOS_CONFIG" NIXOS_CONFIG= \
# Copy the NixOS/Nixpkgs sources to the target as the initial contents
# of the NixOS channel.
mkdir -m 0755 -p $mountPoint/nix/var/nix/profiles
mkdir -m 1777 -p $mountPoint/nix/var/nix/profiles/nixup

This comment has been minimized.

@dezgeg

dezgeg Aug 30, 2015

Contributor

Do we actually need a new subdirectory for nixup profiles? For instance, per-user channels use e.g. /nix/var/nix/profiles/per-user/root/channels

@dezgeg

dezgeg Aug 30, 2015

Contributor

Do we actually need a new subdirectory for nixup profiles? For instance, per-user channels use e.g. /nix/var/nix/profiles/per-user/root/channels

This comment has been minimized.

@wmertens

wmertens May 26, 2016

Contributor

👍 for using per-user/$USER/nixup. It won't conflict with what's there and it is backwards compatible with current installations.

@wmertens

wmertens May 26, 2016

Contributor

👍 for using per-user/$USER/nixup. It won't conflict with what's there and it is backwards compatible with current installations.

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Aug 30, 2015

Contributor

Thank you all very much for your feedback! Especially @nbp and @anderspapitto for your detailed review, it's highly appreciated! I will get back to it as soon as possible.

As Nicolas said, the current aim is to get something merged that we can build up on. That means, I'm particularly interested in suggestions concerning the "front-end", that is the interface that nixup modules are written against. The "back-end" stuff is mostly copied from NixOS and can be changed later without too much disruptions, I think.

Concerning the question of how to support non-NixOS systems. I think that basic functions like, e.g., the abstractions around nixpkgs, might be quite NixOS-independent, and so could work on other systems. When it comes to the support of nixup user services, I'm not so sure though. Like NixOS, it will be based around systemd, like it or not. So in order to make that feature available on non-NixOS systems, there would have to be a way to run a systemd user session, or something compatible at least. I don't know if projects like systembsd could be useful for that. But that won't be anything that I'll be working on.

Contributor

ts468 commented Aug 30, 2015

Thank you all very much for your feedback! Especially @nbp and @anderspapitto for your detailed review, it's highly appreciated! I will get back to it as soon as possible.

As Nicolas said, the current aim is to get something merged that we can build up on. That means, I'm particularly interested in suggestions concerning the "front-end", that is the interface that nixup modules are written against. The "back-end" stuff is mostly copied from NixOS and can be changed later without too much disruptions, I think.

Concerning the question of how to support non-NixOS systems. I think that basic functions like, e.g., the abstractions around nixpkgs, might be quite NixOS-independent, and so could work on other systems. When it comes to the support of nixup user services, I'm not so sure though. Like NixOS, it will be based around systemd, like it or not. So in order to make that feature available on non-NixOS systems, there would have to be a way to run a systemd user session, or something compatible at least. I don't know if projects like systembsd could be useful for that. But that won't be anything that I'll be working on.

Show outdated Hide outdated nixup/modules/nixup/nixup.sh
}
# Add a sensible default value for <nixup-config> to NIX_PATH.

This comment has been minimized.

@dezgeg

dezgeg Aug 30, 2015

Contributor

nix-instantiate --find-file nixup-config could help to do this properly.

@dezgeg

dezgeg Aug 30, 2015

Contributor

nix-instantiate --find-file nixup-config could help to do this properly.

@markus1189

This comment has been minimized.

Show comment
Hide comment
@markus1189

markus1189 Aug 15, 2017

Contributor

Min 10€, this would be awesome!

Contributor

markus1189 commented Aug 15, 2017

Min 10€, this would be awesome!

@bjornfor

This comment has been minimized.

Show comment
Hide comment
@bjornfor

bjornfor Aug 20, 2017

Contributor

I've donated 50 EUR to the NixOS Foundation. (I'd like to see NixUP/Home manager integrated with Nix eventually. One CLI to rule them all.)

Contributor

bjornfor commented Aug 20, 2017

I've donated 50 EUR to the NixOS Foundation. (I'd like to see NixUP/Home manager integrated with Nix eventually. One CLI to rule them all.)

@WhittlesJr

This comment has been minimized.

Show comment
Hide comment
@WhittlesJr

WhittlesJr Aug 20, 2017

I'd give an easy 50 bucks. Brand new to NixOS but I fell in love so quickly. As others have said, user management is the major stumbling block for me right now in my learning curve.

WhittlesJr commented Aug 20, 2017

I'd give an easy 50 bucks. Brand new to NixOS but I fell in love so quickly. As others have said, user management is the major stumbling block for me right now in my learning curve.

@olejorgenb

This comment has been minimized.

Show comment
Hide comment
@olejorgenb

olejorgenb Aug 20, 2017

Contributor

I would easily give 10€ (EDIT: Donated)

Contributor

olejorgenb commented Aug 20, 2017

I would easily give 10€ (EDIT: Donated)

@4z3

This comment has been minimized.

Show comment
Hide comment
@4z3

4z3 Aug 21, 2017

Contributor

FWIW, lots of dotfiles can be already replaced by wrappers like:

{
  users.users.root.packages = [
    (pkgs.writeScriptBin "htop" ''
      #! ${pkgs.bash}/bin/bash
      export HTOPRC=${pkgs.writeText "htoprc" ...}
      exec ${pkgs.htop}/bin/htop "$@"
    '')
  ];
}

Downside of the wrapper approach:

  • There might be applications that don't provide means to specify configuration. One could override $HOME, but then there might be applications that require $HOME for other stuff than configuration. (Personally, I haven't encountered any of these, yet.)
  • Applications cannot write their configuration anymore, e.g. htop will just terminate without error and nothing changed.
Contributor

4z3 commented Aug 21, 2017

FWIW, lots of dotfiles can be already replaced by wrappers like:

{
  users.users.root.packages = [
    (pkgs.writeScriptBin "htop" ''
      #! ${pkgs.bash}/bin/bash
      export HTOPRC=${pkgs.writeText "htoprc" ...}
      exec ${pkgs.htop}/bin/htop "$@"
    '')
  ];
}

Downside of the wrapper approach:

  • There might be applications that don't provide means to specify configuration. One could override $HOME, but then there might be applications that require $HOME for other stuff than configuration. (Personally, I haven't encountered any of these, yet.)
  • Applications cannot write their configuration anymore, e.g. htop will just terminate without error and nothing changed.
@nicknovitski

This comment has been minimized.

Show comment
Hide comment
@nicknovitski

nicknovitski Aug 22, 2017

Contributor

I'm currently trying out an approach leveraging rcm. I write a custom "dotFiles" package in my ~/.nixpkgs. The source includes both static files and nix code that produces dynamic ones, all of which end up in $out at the end. Then I write an install.nix with no build steps, but a shellHook ${rcm}/bin/rcup -v -d ${dotFiles}; exit, so it can be run with nix-shell.

I started doing this because I got sick of writing wrappers like the above, and even started running into programs that did not have a flag to override where they look for configuration.

Contributor

nicknovitski commented Aug 22, 2017

I'm currently trying out an approach leveraging rcm. I write a custom "dotFiles" package in my ~/.nixpkgs. The source includes both static files and nix code that produces dynamic ones, all of which end up in $out at the end. Then I write an install.nix with no build steps, but a shellHook ${rcm}/bin/rcup -v -d ${dotFiles}; exit, so it can be run with nix-shell.

I started doing this because I got sick of writing wrappers like the above, and even started running into programs that did not have a flag to override where they look for configuration.

@seagreen

This comment has been minimized.

Show comment
Hide comment
@seagreen

seagreen Sep 3, 2017

Contributor

I'm far from a NixOS expert, but I don't know if it's a good idea to put this into Nixpkgs master without testing it somewhere else first. As other people in this thread have mentioned there are already tools for managing dotfiles, and we can't know if NixUP will be better at this time.

Would it be possible to build this as a separate service or as a fork of Nixpkgs, and only merge it into master once we know it's the clear winner over the other options?

EDIT: For instance homemanager, which is mentioned in this thread.

Contributor

seagreen commented Sep 3, 2017

I'm far from a NixOS expert, but I don't know if it's a good idea to put this into Nixpkgs master without testing it somewhere else first. As other people in this thread have mentioned there are already tools for managing dotfiles, and we can't know if NixUP will be better at this time.

Would it be possible to build this as a separate service or as a fork of Nixpkgs, and only merge it into master once we know it's the clear winner over the other options?

EDIT: For instance homemanager, which is mentioned in this thread.

@ixxie

This comment has been minimized.

Show comment
Hide comment
@ixxie

ixxie Sep 8, 2017

Contributor

@ts468 - I donated €50 for this cause!

Contributor

ixxie commented Sep 8, 2017

@ts468 - I donated €50 for this cause!

@teto

This comment has been minimized.

Show comment
Hide comment
@teto

teto Oct 5, 2017

Contributor

To sum up we have

  • https://github.com/rycee/home-manager/
  • https://github.com/sheenobu/nix-home
  • nixup
    I am looking for a solution where I could do programs.zsh.shellAliases = [ .. ] and it would generate it into $ZDOTDIR/.zshrc for instance.
    nix-home looks very basic (like a versioned repo) while home-manager and nixup look better suited. I am tempted to go for the home-manager way as it seems easier to contribute (it has own repo with issues/PRs).
Contributor

teto commented Oct 5, 2017

To sum up we have

  • https://github.com/rycee/home-manager/
  • https://github.com/sheenobu/nix-home
  • nixup
    I am looking for a solution where I could do programs.zsh.shellAliases = [ .. ] and it would generate it into $ZDOTDIR/.zshrc for instance.
    nix-home looks very basic (like a versioned repo) while home-manager and nixup look better suited. I am tempted to go for the home-manager way as it seems easier to contribute (it has own repo with issues/PRs).
@michalrus

This comment has been minimized.

Show comment
Hide comment
@michalrus
Contributor

michalrus commented Oct 21, 2017

If anyone wants something waaaaaaaaaaay easier, then:

Cheers,

@ts468 ts468 requested a review from edolstra as a code owner Oct 30, 2017

@ts468 ts468 requested a review from nbp as a code owner Nov 6, 2017

@ts468

This comment has been minimized.

Show comment
Hide comment
@ts468

ts468 Nov 6, 2017

Contributor

A new and re-based version of NixUP arrived!

It would be great if you could review and test the changes!

Special attention should go into reviewing:

  • nixos-rebuild.sh (verify to have no effect on NixOS)
  • switch-to-configuration.pl (verify to have no effect on NixOS)
  • resource-manager.c (security review as resource-manager runs with setuid=0)

Many thanks in advance!

Contributor

ts468 commented Nov 6, 2017

A new and re-based version of NixUP arrived!

It would be great if you could review and test the changes!

Special attention should go into reviewing:

  • nixos-rebuild.sh (verify to have no effect on NixOS)
  • switch-to-configuration.pl (verify to have no effect on NixOS)
  • resource-manager.c (security review as resource-manager runs with setuid=0)

Many thanks in advance!

@vcunat

This comment has been minimized.

Show comment
Hide comment
Member

vcunat commented Nov 16, 2017

ts468 added some commits Oct 18, 2017

nixos pam_env: use conffile instead of envfile
Change the internals of how the PAM module "pam_env" is configured.
So far pam_env read simple KEY=VALUE pairs from a file specified with the
option "envfile". Now, pam_env is switched to use the option "conffile" which
reads a file that allows more complex configurations. For example the file
read by "conffile" can contain special variables that are expanded by pam_env.

The effect of the switch to using "conffile" should be purely internal. On the
one hand the pam_env option "readenv=0" is used to prevent pam_env from loading
the default environment file at "/etc/environment" that would pam_env would
fall back to now. On the other hand the mechanism of creating the KEY=VALUE
pairs for the "envfile" option is adapted to fit the new format of the
"conffile" option. So there should only be a visible effect if a VALUE contained
any special variables like "@{HOME}" or "@{SHELL}" that are expanded now by
pam_env.
nixos pam: add option "sessionCommands"
Add the option "sessionCommands" to security.pam.services. "sessionCommands"
gets executed by PAM right before the systemd user session is started.
Prepare nixos-rebuild.sh for NixUP
Nixos-rebuild.sh is generalized to be equally usable for NixOS and
for NixUP. Nixos-rebuild.sh is also renamed to nix__-rebuild.sh.
The changes do not affect the behaviour for NixOS.
Prepare switch-to-configuration.pl for NixUP
switch-to-configuration.sh is generalized to be equally usable
for NixOS and for NixUP.
The changes do not affect the behaviour for NixOS.

ts468 added some commits Nov 6, 2017

nixos nixup: add NixUP initialisation hooks
Add the configuration option "config.nixup.enable" which integrates the
activation scripts of NixUP into the user login and session handling of NixOS,
and provides the "nixup-rebuild" tool for managing NixUP.
Init NixUP.
Add the NixUP module system.
@davidak

This comment has been minimized.

Show comment
Hide comment
@davidak

davidak Dec 16, 2017

Contributor

This looks amazing. I also donated 50€.

Any progress since last comment?

Contributor

davidak commented Dec 16, 2017

This looks amazing. I also donated 50€.

Any progress since last comment?

@nbp

This comment has been minimized.

Show comment
Hide comment
@nbp

nbp Jan 17, 2018

Member

@ts468 I see that I am being asked for review, but at the same time I see 2000 lines addition. Is there a way to split this work in multiple digest PR?

Member

nbp commented Jan 17, 2018

@ts468 I see that I am being asked for review, but at the same time I see 2000 lines addition. Is there a way to split this work in multiple digest PR?

showSyntax
;;
switch|boot|test|build|dry-build|dry-run|dry-activate|build-vm|build-vm-with-bootloader)
switch_*|boot_nixos|login_nixup|test_nixos|build_*|dry-build_nixos|dry-run_*|dry-activate_nixos|build-vm_nixos|build-vm-with-bootloader_nixos|edit_nixos)

This comment has been minimized.

@bobvanderlinden

bobvanderlinden Jan 27, 2018

Contributor

Doesn't this (and changes of commandline flags below) break the existing usage of nixos-rebuild?

@bobvanderlinden

bobvanderlinden Jan 27, 2018

Contributor

Doesn't this (and changes of commandline flags below) break the existing usage of nixos-rebuild?

@throwup

This comment has been minimized.

Show comment
Hide comment
@throwup

throwup Feb 1, 2018

Sorry if I am asking something that should already be clear but is this:

@bjornfor Thanks for your interest! Indeed, it is planed to make all NixUP options that are available under "~/.nixup/profile.nix" also available in the NixOS configuration, probably under "users.extraUsers..profile". However, I'm just not so sure how to merge the options defined in NixOS and NixUP, yet. Should they just be added up? Should the options defined in NixOS be defaults that can be overwritten with NixUP, or should that be prohibited? If you have any suggestions or ideas that would be great! :)

still a feature you intend to add? I like to define my system using a single git repository and would rather not link stuff to home directories manually. I read in another message, that this, based on how it's implemented, might "automatically" work, but I am not proficient enough at nix to judge that.

throwup commented Feb 1, 2018

Sorry if I am asking something that should already be clear but is this:

@bjornfor Thanks for your interest! Indeed, it is planed to make all NixUP options that are available under "~/.nixup/profile.nix" also available in the NixOS configuration, probably under "users.extraUsers..profile". However, I'm just not so sure how to merge the options defined in NixOS and NixUP, yet. Should they just be added up? Should the options defined in NixOS be defaults that can be overwritten with NixUP, or should that be prohibited? If you have any suggestions or ideas that would be great! :)

still a feature you intend to add? I like to define my system using a single git repository and would rather not link stuff to home directories manually. I read in another message, that this, based on how it's implemented, might "automatically" work, but I am not proficient enough at nix to judge that.

@timokau

This comment has been minimized.

Show comment
Hide comment
@timokau

timokau Feb 23, 2018

Contributor

What is blocking this right now? Is there any way to help push this forward?

Contributor

timokau commented Feb 23, 2018

What is blocking this right now? Is there any way to help push this forward?

@dasJ

This comment has been minimized.

Show comment
Hide comment
@dasJ

dasJ Mar 5, 2018

Contributor

Yes, it is possible this gets into 18.03? Apart from some conflicts I don't see anything keeping it from merged

Contributor

dasJ commented Mar 5, 2018

Yes, it is possible this gets into 18.03? Apart from some conflicts I don't see anything keeping it from merged

@IvanMalison

This comment has been minimized.

Show comment
Hide comment
@IvanMalison

IvanMalison Apr 16, 2018

Contributor

@ts468 status?

Contributor

IvanMalison commented Apr 16, 2018

@ts468 status?

@drvink

This comment has been minimized.

Show comment
Hide comment
@drvink

drvink Apr 22, 2018

Contributor

Is there a reason this has remained unmerged after nearly three years? The author's work is going to waste--it already needs another rebase and forward-porting effort now. It would be nice to at least hear from the Nix maintainers whether there are plans to integrate similar functionality.

Contributor

drvink commented Apr 22, 2018

Is there a reason this has remained unmerged after nearly three years? The author's work is going to waste--it already needs another rebase and forward-porting effort now. It would be nice to at least hear from the Nix maintainers whether there are plans to integrate similar functionality.

@Nadrieril

This comment has been minimized.

Show comment
Hide comment
@Nadrieril

Nadrieril Apr 22, 2018

Contributor

I personally think home-manager would be a better basis for this, as it is more featureful and actively developped

Contributor

Nadrieril commented Apr 22, 2018

I personally think home-manager would be a better basis for this, as it is more featureful and actively developped

@IvanMalison

This comment has been minimized.

Show comment
Hide comment
@IvanMalison

IvanMalison Jun 4, 2018

Contributor

Is there a reason this has remained unmerged after nearly three years? The author's work is going to waste--it already needs another rebase and forward-porting effort now. It would be nice to at least hear from the Nix maintainers whether there are plans to integrate similar functionality.

I personally think home-manager would be a better basis for this, as it is more featureful and actively developped

It would still be nice to hear something official from the maintainers, so that users of whichever system (be it nixup or homemanager) know which one is likely to be maintained and usable moving forward.

Contributor

IvanMalison commented Jun 4, 2018

Is there a reason this has remained unmerged after nearly three years? The author's work is going to waste--it already needs another rebase and forward-porting effort now. It would be nice to at least hear from the Nix maintainers whether there are plans to integrate similar functionality.

I personally think home-manager would be a better basis for this, as it is more featureful and actively developped

It would still be nice to hear something official from the maintainers, so that users of whichever system (be it nixup or homemanager) know which one is likely to be maintained and usable moving forward.

@bobvanderlinden bobvanderlinden referenced this pull request Jun 13, 2018

Open

Initial home contents #41858

4 of 8 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment