nix-on-droid/modules/environment/path.nix
Tobias Happ 5e7d6d1214 environment.path: fix installation with nix profile
Manual removal and installation as two non-atomical steps is required
because of https://github.com/NixOS/nix/issues/6349.
2022-12-04 13:09:02 +01:00

82 lines
1.8 KiB
Nix

# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE.
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.environment;
in
{
###### interface
options = {
environment = {
packages = mkOption {
type = types.listOf types.package;
default = [ ];
description = "List of packages to be installed as user packages.";
};
path = mkOption {
type = types.package;
readOnly = true;
internal = true;
description = "Derivation for installing user packages.";
};
};
};
###### implementation
config = {
build.activation.installPackages = ''
if [[ -e "${config.user.home}/.nix-profile/manifest.json" ]]; then
# manual removal and installation as two non-atomical steps is required
# because of https://github.com/NixOS/nix/issues/6349
nix_previous="$(command -v nix)"
nix profile list \
| grep 'nix-on-droid-path$' \
| cut -d ' ' -f 4 \
| xargs -t $DRY_RUN_CMD nix profile remove $VERBOSE_ARG
$DRY_RUN_CMD $nix_previous profile install ${cfg.path}
unset nix_previous
else
$DRY_RUN_CMD nix-env --install ${cfg.path}
fi
'';
environment = {
packages = [
(pkgs.callPackage ../../nix-on-droid { nix = config.nix.package; })
pkgs.bashInteractive
pkgs.cacert
pkgs.coreutils
pkgs.less # since nix tools really want a pager available, #27
config.nix.package
];
path = pkgs.buildEnv {
name = "nix-on-droid-path";
paths = cfg.packages;
meta = {
description = "Environment of packages installed through Nix-on-Droid.";
};
};
};
};
}