Skip to content

Commit 0745d89

Browse files
committed
fix(nix): enable nix command on all machines
- Use bash instead of POSIX sh (process substitution fails on dash) - Create persistent ~/.config/nix/nix.conf with experimental-features - Use temp file instead of <() for portability
1 parent df6bc92 commit 0745d89

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

nix/install.sh

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/sh
2-
# nix/install.sh - POSIX compliant Nix installer wrapper
1+
#!/usr/bin/env bash
2+
# nix/install.sh - Nix installer wrapper
33

44
set -eu
55

@@ -16,27 +16,48 @@ source_nix_profile() {
1616
die "Nix profile not found. Restart terminal and re-run."
1717
}
1818

19+
ensure_nix_conf() {
20+
local conf_dir="$HOME/.config/nix"
21+
local conf_file="$conf_dir/nix.conf"
22+
local required_line="experimental-features = nix-command flakes"
23+
24+
mkdir -p "$conf_dir"
25+
if [ ! -f "$conf_file" ] || ! grep -q "experimental-features" "$conf_file"; then
26+
echo "$required_line" >> "$conf_file"
27+
fi
28+
}
29+
1930
install_nix() {
2031
if command -v nix >/dev/null 2>&1; then
32+
ensure_nix_conf
2133
return 0
2234
fi
2335

2436
echo "Installing Nix..."
37+
38+
# Create temp file for extra config (process substitution not portable)
39+
local extra_conf
40+
extra_conf=$(mktemp)
41+
echo "experimental-features = nix-command flakes" > "$extra_conf"
42+
trap "rm -f '$extra_conf'" EXIT
43+
2544
if [ "${NO_SUDO:-}" = "1" ]; then
2645
# Single-user mode only (no sudo)
27-
if ! curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --no-daemon --yes --nix-extra-conf-file <(echo "experimental-features = nix-command flakes"); then
46+
if ! curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --no-daemon --yes --nix-extra-conf-file "$extra_conf"; then
2847
die "Nix installation failed"
2948
fi
3049
else
3150
# Try official installer with multi-user mode first
32-
if ! curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --daemon --yes --nix-extra-conf-file <(echo "experimental-features = nix-command flakes"); then
51+
if ! curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --daemon --yes --nix-extra-conf-file "$extra_conf"; then
3352
# Fallback to single-user mode
34-
if ! curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --no-daemon --yes --nix-extra-conf-file <(echo "experimental-features = nix-command flakes"); then
53+
if ! curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --no-daemon --yes --nix-extra-conf-file "$extra_conf"; then
3554
die "Nix installation failed"
3655
fi
3756
fi
3857
fi
58+
3959
source_nix_profile
60+
ensure_nix_conf
4061
}
4162

4263
install_nix

0 commit comments

Comments
 (0)