Commit Graph

29 Commits

Author SHA1 Message Date
toonn 9555918151
nix-darwin: simplify activation script invocation
In #587, kalbasit introduce the `-i` flag so the sudo invocation would
run in an environment with `HOME` set to the correct value for the
target user. This was necessary to be able to set up multiple users
without interfering with the invoking user's `HOME`.

In #807, I switched to `-s` instead because I managed to get an
invalid shell set for my user by switching `useUserPackages` from
`true` to `false` which changes the location where packages are
installed and `~/.nix-profile/bin/<my-shell>` was no longer valid.
This was based on the assumption that `SHELL` would be set to some
sensible value by Home Manager at this point. This turned out to be
false as reported in #2900.

In 0ced6d6d (this commit's parent at this time), I explicitly set
`SHELL` to `${pkgs.bash}` so it is definitely set to a good shell when
invoking the activation script.

However, #807 broke activation for multiple users, the original
motivation for `-i`, as reported in #2856. I fixed this in #2857 by
additionally passing `--set-home`.

Further discussion with rycee in #3040 made me realize that the
activation script already has a good Nix store bash shebang. So all
the problems have been caused, not by the shell used for the
activation script but by sudo trying to use a different shell at all.
`-i` uses the shell set in the `passwd` file for the target user, but
this can become invalid as happened to me. `-s` uses either `SHELL` if
it's defined or the invoking user's shell as set in the `passwd` file.
By explicitly setting this to a shell provided by Nix we make sure
we're not trying to launch a non-existent shell. However, we're
clearly already running in an existing shell and because of
`--set-home` we can activate other users properly so there's not
actually any need to try to have sudo start a different shell first,
it just adds an extra process that then goes on to run the activation
script with a good bash because of the shebang.

Dropping `-s` altogether and keeping `--set-home` should avoid all of
these issues.
2022-09-19 22:02:58 +02:00
toonn 610b1d988c
nix-darwin: improve invocation of activation script
In #807 I changed the flag passed to `sudo` from `-i` to `-s` so
`sudo` wouldn't use a non-existent shell defined in the `passwd` file.
kalbasit also reported in that PR that `-i` didn't work for them
anymore on an M1 Mac, presumably because Apple changed something in
newer versions of macOS.

Some users reported that this broke the behavior for them because
`SHELL` was set to a path that didn't even exist on their system. It's
unclear how this came to be but it shows that my assumption that
`SHELL` would be set to a reasonable shell by Home Manager at this
point in the activation is false.

As a way around this problem we can explicitly set `SHELL` when
running the activation script to a value that we know will be good,
like `${pkgs.bash}`.

One change in behavior this causes is that the activation script will
always be run by bash, not the user's shell. If the script is
generated by Home Manager this is fine since it can be generated
taking into account the supported set of functions and behaviors. If
the intent is for the activation script to possibly be run by non-bash
and even non-POSIX shells, like tcsh, ksh or Xonsh, then this fix will
not suffice. Turns out this is indeed an assumption made by Home
Manager, so this is the proper behavior.

Fixes #2900
2022-09-19 22:02:44 +02:00
Naïm Favier 586ac1fd58
Move `integration-common.nix` to `nixos/common.nix` 2022-06-19 00:45:18 +02:00
Naïm Camille Favier 64ab7d6e8d
Prepare inclusion in nixos-search (#2971)
* Add flake.lock and clean up flake.nix

Add a lockfile to work around https://github.com/NixOS/nix/issues/6541
(and because it's a good idea anyway).

Also use flake-utils, and restrict ourselves to the five platforms
supported by nixpkgs. Otherwise, the IFD for nmd fails on weird
platforms. This fixes `nix flake check`.

Remove the redundant `apps` output, see https://github.com/nix-community/home-manager/pull/2442#issuecomment-1133670487

* nixos,nix-darwin: factor out into a common module

* nixos,nix-darwin: make `home-managers.users` shallowly visible

Make sure the option is included in the NixOS/nix-darwin manual (but the
HM submodule options aren't).

Also add a static description to the HM submodule type so that we don't need to
evaluate the submodules just to build the option manual. This makes
nixos-search able to index the home-manager flake.

Also clean up some TODOs.

* flake: add nmd and nmt

This avoids having to use `pkgs.fetchFromGitLab` in an IFD, which causes
issues when indexing packages with nixos-search because `pkgs` is
instantiated with every platform.
2022-06-07 20:45:06 +02:00
ilkecan c2726860a2
nix-darwin,nixos: convert `modulesPath` to string (#2714)
`modulesPath` is usually used with antiquotation
(`"${modulesPath}/some-module.nix"`). Since antiquoted paths are copied
to the Nix store, one must explicitly do `"${toString
modulesPath}/some-module.nix"` to avoid that. Ideally `modulesPath`
should be a string to avoid this. Note that `modulesPath` is already
defined as a string in <home-manager>/modules/default.nix and
<nixpkgs>/nixos/lib/eval-config.nix.
2022-04-17 18:23:18 -04:00
toonn e1fab012e8
nix-darwin: sudo --set-home for multiple user activation (#2857)
Changing from `sudo -i` to `sudo -s` messes up activation when multiple
users are managed. `--set-home` should have similar behavior to `-i` in
that the activation script is run from the user's home directory.

Fixes #2856
2022-04-01 11:33:07 -04:00
toonn cf62e96bf7
Run sudo with -s in the darwin module (#807)
Currently activation is run with `sudo -i` this defaults to the user's
login shell. This can lead to problems if the user's shell isn't set
properly.

By passing `-s` rather than `-i`, `sudo` runs `activate` in `SHELL`
instead. We assume that at this point in the activation `SHELL`
contains the path to a bash in the nix store. This should always be a
valid shell to run the `activate` script with.

From the `sudo` manual it seems like this cannot be fixed if `SHELL`
isn't set at this point or by passing a command to `-s` because that
command is then passed to the user's shell.
2022-03-31 11:24:26 -07:00
Nicolas Berbiche 1fa809f783
darwin: add Nix package to activation $PATH
The fix for https://github.com/nix-community/home-manager/issues/2178
did not apply the patch to nix-darwin too.

See: https://github.com/nix-community/home-manager/issues/2178#issuecomment-1029015498
2022-02-03 15:24:31 -05:00
Lorenzo Manacorda 39c5c7397e
docs: improve description of extraSpecialArgs 2021-11-13 01:01:01 +01:00
Bastien Rivière 8278c14f5f
nixos: replace types.anything with submodule type (#2396)
As discussed in this issue:
https://github.com/NixOS/nixpkgs/issues/140879
`types.anything` was never meant to be used for arbitrary modules.

Co-authored-by: Silvan Mosberger <github@infinisil.com>
2021-10-22 17:52:19 -04:00
Naïm Favier bd11e2c5e6
Replace usage of `literalExample`
Instead use the new function `literalExpression`. See

  https://github.com/NixOS/nixpkgs/pull/136909
2021-10-13 00:16:10 +02:00
Thiago Kenji Okada fd2f746016
nix-darwin: add modulesPath to specialArgs (#2375)
Same as 099cbcf13e, however now for
nix-darwin instead of NixOS.

Tested with `disabledModules = [ "programs/alacritty.nix" ];` and having an
error.
2021-10-08 16:36:41 -04:00
Nicolas Berbiche 60ebc273c9
nix-darwin,nixos: add osConfig module argument (#2302)
Having either argument defined based on the OS is a problem when
trying to write generic Nix code.

The current workaround is to use accept both and specify a default
value for each argument:

```
{ config, lib, nixosConfig ? {}, darwinConfig ? {}, ... }:

let
  osConfig = nixosConfig // darwinConfig;
in
{
  # Do something with `osConfig`
}
```

With this commit, it becomes possible to do the following:

```
{ config, lib, osConfig, ... }:

{
  # Do something with `osConfig`
}
```
2021-10-06 16:32:13 +02:00
Pacman99 fedfd430f9
nixos/nix-darwin: switch sharedModules type to anything with custom check (#1880)
functionTo tries to evaluate functions too quickly and prevents modules
from accessing pkgs argument. fixes #1878.

Co-authored-by: Pacman99 <pachum99@gmail.com>
2021-03-25 22:01:16 -04:00
Robert Helgesson aa9affb53f
nix-darwin: remove trailing whitespace 2021-02-21 18:40:19 +01:00
Pacman99 82d6ba7003
nixos,darwin: add sharedModules and extraSpecialArgs options (#1793)
This allows users of the nixos and nix-darwin module to set shared modules
for all users and extra specialArgs to be available to home-manager modules.

The latter is named extraSpecialArgs just like the argument to
modules/default.nix.
This could be confusing since the the two are independent in code,
but they do mean the same thing so I think the name fits.

Darwin can now refer to the global system configuration if used as a module
through the special `darwinConfig` argument.

Co-authored-by: Nicolas Berbiche <nicolas@normie.dev>
2021-02-21 01:02:25 -05:00
Robert Helgesson 5280360d6c
docs: NixOS and nix-darwin option documentation 2021-01-21 23:45:52 +01:00
Nicolas Berbiche bd4c2b0651
nix-darwin: add missing options
Add useGlobalPkgs, verbose and backupFileExtension support
2020-09-04 15:00:00 +02:00
Robert Helgesson a49ce0e9ed
home-environment: use per-user profile path in /etc
Before the profile directory value would point directly to the build
output in the Nix store. Unfortunately this would cause an infinite
loop if the user's configuration directly or indirectly refers to the
profile directory value.

Fixes #1188
2020-07-14 23:31:20 +02:00
Robert Helgesson 1a8ab9d9de
nixos, nix-darwin: fix user packages install
It is insufficient to install the packages in `home.packages`, it has
to be `home.path`, which includes configured extra package outputs or
profile commands.
2020-07-14 23:31:19 +02:00
Robert Helgesson 6e4b9af080
Switch to extended Nixpkg's `lib`
This change makes use of the `extend` function inside `lib` to inject
a new `hm` field containing the Home Manager library functions. This
simplifies use of the Home Manager library in the modules and reduces
the risk of accidental infinite recursion.

PR #994
2020-01-21 20:47:04 +01:00
Robert Helgesson a144c723a1
doc: surround `name?` with fancier characters 2019-09-01 21:28:40 +02:00
Robert Helgesson c2429ca0cf
nix-darwin: pass on warnings to the system configuration 2019-08-18 17:37:26 +02:00
Roman Volosatovs 1480a6ca14
nix-darwin: actually install packages
Also apply assertions when using the nix-darwin module.

Closes #702
2019-05-19 00:36:35 +02:00
Wael M. Nasreddine 7ec153889c
nix-darwin: login as the user when activating 2019-03-10 02:10:15 +01:00
Wael M. Nasreddine efc795920b
nix-darwin: support package install through user packages 2019-03-10 02:09:00 +01:00
Wael M. Nasreddine d3fd287efb
nix-darwin: activate home-manager through postActivation 2019-03-10 02:03:26 +01:00
Robert Helgesson 2f372ab4d6
Clean up support code for Home Manager as a submodule
This removes the `nixosSubmodule` option in favor of a new option
`submoduleSupport.enable`. This name better indicates that the
submodule mode applies to both NixOS and nix-darwin.
2019-02-10 00:44:55 +01:00
Will Fancher a9a4fb641f
nix-darwin: add system module for nix-darwin 2018-11-20 00:22:53 +01:00