Skip to content
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

Installer nushell support #10439

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ perl/Makefile.config
/scripts/nix-profile-daemon.sh
/scripts/nix-profile.fish
/scripts/nix-profile-daemon.fish
/scripts/nix-profile.nu
/scripts/nix-profile-daemon.nu

# /src/libexpr/
/src/libexpr/lexer-tab.cc
Expand Down
8 changes: 8 additions & 0 deletions scripts/install-nix-from-closure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ added=
p=
p_sh=$NIX_LINK/etc/profile.d/nix.sh
p_fish=$NIX_LINK/etc/profile.d/nix.fish
p_nu=$NIX_LINK/etc/profile.d/nix.nu
if [ -z "$NIX_INSTALLER_NO_MODIFY_PROFILE" ]; then
# Make the shell source nix.sh during login.
for i in .bash_profile .bash_login .profile; do
Expand Down Expand Up @@ -257,6 +258,13 @@ if [ -z "$NIX_INSTALLER_NO_MODIFY_PROFILE" ]; then
added=1
p=${p_fish}
fi

if [ -d "$HOME/.config/nushell" ]; then
fn="$HOME/.config/nushell/env.nu"
printf '\nif ("%s" | path exists) { source "%s"; } # added by Nix installer\n' "$p_nu" "$p_nu" >> "$fn"
added=1
p=${p_nu}
fi
else
p=${p_sh}
fi
Expand Down
2 changes: 2 additions & 0 deletions scripts/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ profiledir = $(sysconfdir)/profile.d

$(eval $(call install-file-as, $(d)/nix-profile.sh, $(profiledir)/nix.sh, 0644))
$(eval $(call install-file-as, $(d)/nix-profile.fish, $(profiledir)/nix.fish, 0644))
$(eval $(call install-file-as, $(d)/nix-profile.nu, $(profiledir)/nix.nu, 0644))
$(eval $(call install-file-as, $(d)/nix-profile-daemon.sh, $(profiledir)/nix-daemon.sh, 0644))
$(eval $(call install-file-as, $(d)/nix-profile-daemon.fish, $(profiledir)/nix-daemon.fish, 0644))
$(eval $(call install-file-as, $(d)/nix-profile-daemon.nu, $(profiledir)/nix-daemon.nu, 0644))

clean-files += $(nix_noinst_scripts)
51 changes: 51 additions & 0 deletions scripts/nix-profile-daemon.nu.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Only execute this file once per shell.
if ('__ETC_PROFILE_NIX_SOURCED' in $env) {
return;
}
$env.__ETC_PROFILE_NIX_SOURCED = 1;

mut NIX_LINK = [$env.HOME '.nix-profile'] | path join;
mut NIX_LINK_NEW = [$env.HOME '.local/state/nix/profile'];
if 'XDG_STATE_HOME' in $env {
$NIX_LINK_NEW = [$env.XDG_STATE_HOME 'nix/profile'];
}
$NIX_LINK_NEW = ($NIX_LINK_NEW | path join);
if ($NIX_LINK_NEW | path exists) {
$NIX_LINK = $NIX_LINK_NEW;
}

$env.NIX_PROFILES = (['@localstatedir@/nix/profiles/default' $NIX_LINK] | str join ' ');

# Populate bash completions, .desktop files, etc
if 'XDG_DATA_DIRS' not-in $env {
# According to XDG spec the default is /usr/local/share:/usr/share, don't set something that prevents that default
$env.XDG_DATA_DIRS = (['/usr/local/share' '/usr/share'] | str join (char esep));
}
$env.XDG_DATA_DIRS = (
$env.XDG_DATA_DIRS
| split row (char esep)
| append ([$NIX_LINK 'share'] | path join)
| append '/nix/var/nix/profiles/default/share'
| str join (char esep)
);

# Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work.
if ('NIX_SSL_CERT_FILE' in $env) {
# Allow users to override the NIX_SSL_CERT_FILE
} else if ('/etc/ssl/certs/ca-certificates.crt' | path exists) { # NixOS, Ubuntu, Debian, Gentoo, Arch
$env.NIX_SSL_CERT_FILE = '/etc/ssl/certs/ca-certificates.crt';
} else if ('/etc/ssl/ca-bundle.pem' | path exists) { # openSUSE Tumbleweed
$env.NIX_SSL_CERT_FILE = '/etc/ssl/ca-bundle.pem';
} else if ('/etc/ssl/certs/ca-bundle.crt' | path exists) { # Old NixOS
$env.NIX_SSL_CERT_FILE = '/etc/ssl/certs/ca-bundle.crt';
} else if ('/etc/pki/tls/certs/ca-bundle.crt' | path exists) { # Fedora, CentOS
$env.NIX_SSL_CERT_FILE = '/etc/pki/tls/certs/ca-bundle.crt';
} else {
# Fall back to what is in the nix profiles, favouring whatever is defined last.
$env.NIX_PROFILES
| split row (char space)
| where ([$it 'etc/ssl/certs/ca-bundle.crt'] | path join | path exists)
| each { |it| $env.NIX_SSL_CERT_FILE = ([$it 'etc/ssl/certs/ca-bundle.crt'] | path join) }
}

$env.PATH = ($env.PATH | prepend '@localstatedir@/nix/profiles/default/bin' | prepend ([$NIX_LINK 'bin'] | path join));
54 changes: 54 additions & 0 deletions scripts/nix-profile.nu.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
if ([$env.HOME $env.USER] | all {nu-check}) {

# Set up the per-user profile.
mut NIX_LINK = [$env.HOME '.nix-profile'] | path join;
mut NIX_LINK_NEW = [$env.HOME '.local/state/nix/profile'];
if 'XDG_STATE_HOME' in $env {
$NIX_LINK_NEW = [$env.XDG_STATE_HOME 'nix/profile'];
}
$NIX_LINK_NEW = ($NIX_LINK_NEW | path join);
if ($NIX_LINK_NEW | path exists) {
$NIX_LINK = $NIX_LINK_NEW;
}

# Set up environment.
# This part should be kept in sync with nixpkgs:nixos/modules/programs/environment.nix
$env.NIX_PROFILES = (['@localstatedir@/nix/profiles/default' $NIX_LINK] | str join ' ');

# Populate bash completions, .desktop files, etc
if 'XDG_DATA_DIRS' not-in $env {
# According to XDG spec the default is /usr/local/share:/usr/share, don't set something that prevents that default
$env.XDG_DATA_DIRS = (['/usr/local/share' '/usr/share'] | str join (char esep));
}
$env.XDG_DATA_DIRS = (
$env.XDG_DATA_DIRS
| split row (char esep)
| append ([$NIX_LINK 'share'] | path join)
| append '/nix/var/nix/profiles/default/share'
| str join (char esep)
);

# Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work.
if ('/etc/ssl/certs/ca-certificates.crt' | path exists) { # NixOS, Ubuntu, Debian, Gentoo, Arch
$env.NIX_SSL_CERT_FILE = '/etc/ssl/certs/ca-certificates.crt';
} else if ('/etc/ssl/ca-bundle.pem' | path exists) { # openSUSE Tumbleweed
$env.NIX_SSL_CERT_FILE = '/etc/ssl/ca-bundle.pem';
} else if ('/etc/ssl/certs/ca-bundle.crt' | path exists) { # Old NixOS
$env.NIX_SSL_CERT_FILE = '/etc/ssl/certs/ca-bundle.crt';
} else if ('/etc/pki/tls/certs/ca-bundle.crt' | path exists) { # Fedora, CentOS
$env.NIX_SSL_CERT_FILE = '/etc/pki/tls/certs/ca-bundle.crt';
} else if ([$NIX_LINK 'etc/ssl/certs/ca-bundle.crt'] | path join | path exists) { # fall back to cacert in Nix profile
$env.NIX_SSL_CERT_FILE = ([$NIX_LINK 'etc/ssl/certs/ca-bundle.crt'] | path join);
} else if ([$NIX_LINK 'etc/ca-bundle.crt'] | path join | path exists) { # old cacert in Nix profile
$env.NIX_SSL_CERT_FILE = ([$NIX_LINK '/etc/ca-bundle.crt'] | path join);
}

# Only use MANPATH if it is already set. In general `man` will just simply
# pick up `.nix-profile/share/man` because is it close to `.nix-profile/bin`
# which is in the $PATH. For more info, run `manpath -d`.
if ('MANPATH' in $env) {
$env.MANPATH = ([$NIX_LINK 'share/man'] | path join | append $"(char esep)($env.MANPATH)");
}

$env.PATH = ($env.PATH | prepend ([$NIX_LINK 'bin'] | path join));
}