Skip to content

Commit 4acfeff

Browse files
committed
refactor(ci): changes Dockerfile and entrypoint
1 parent dce2bb5 commit 4acfeff

3 files changed

Lines changed: 43 additions & 52 deletions

File tree

nix_test_env/Dockerfile

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,31 @@ RUN mkdir -m 0755 /nix \
2020
# Set environment so Nix is on PATH
2121
ENV USER=root
2222
ENV HOME=/root
23-
ENV PATH=/root/.nix-profile/bin:/root/.nix-profile/sbin:$PATH
24-
25-
# Install Nix
26-
RUN curl -L https://nixos.org/nix/install | sh -s -- --daemon
2723

2824
# Configure Nix to run in unprivileged mode (no nixbld group needed)
2925
RUN mkdir -p /etc/nix && echo "build-users-group =" >> /etc/nix/nix.conf
3026

27+
# Install Nix
28+
RUN curl -L https://nixos.org/nix/install | sh -s -- --no-daemon --no-modify-profile --no-channel-add --yes
29+
30+
# Set PATH after Nix installation to include Nix binaries explicitly
31+
ENV PATH="/root/.nix-profile/bin:/root/.nix-profile/sbin:${PATH}"
32+
3133
# Add Nix channels for Nixpkgs and Home Manager
3234
# Source the Nix profile before running nix-channel commands
33-
RUN . /root/.nix-profile/etc/profile.d/nix.sh && \
34-
nix-channel --add https://nixos.org/channels/nixos-25.05 nixpkgs && \
35-
nix-channel --add https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz home-manager && \
36-
nix-channel --update
35+
RUN . /root/.nix-profile/etc/profile.d/nix.sh
36+
RUN nix-channel --add https://nixos.org/channels/nixos-25.05 nixpkgs
37+
RUN nix-channel --add https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz home-manager
38+
RUN nix-channel --update
3739

38-
# Install home-manager for the root user
39-
RUN . /root/.nix-profile/etc/profile.d/nix.sh && \
40-
nix-shell '<home-manager>' -A install
40+
# Install home-manager
41+
RUN nix-env -iA home-manager -f '<home-manager>'
4142

42-
# Nix bin path for any shells
43-
RUN echo 'export PATH="/root/.nix-profile/bin:$PATH"' \
44-
> /etc/profile.d/hm-path.sh
43+
# Copy into the container
44+
WORKDIR /root/.config/home-manager
45+
COPY . .
4546

46-
# Entrypoint
47-
COPY nix_test_env/docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
48-
RUN chmod +x /usr/local/bin/docker_entrypoint.sh
47+
RUN chmod +x ./nix_test_env/docker_entrypoint.sh
48+
ENTRYPOINT ["./nix_test_env/docker_entrypoint.sh"]
4949

50-
WORKDIR /root
51-
ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh"]
5250
CMD ["tail", "-f", "/dev/null"]

nix_test_env/docker_entrypoint.sh

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# FIX: Initialize the variable before it's used to satisfy `set -u`
45
export __HM_SESS_VARS_SOURCED="${__HM_SESS_VARS_SOURCED:-0}"
56

6-
source /root/.nix-profile/etc/profile.d/nix.sh
7+
# Source the Nix profile script to ensure PATH is set correctly
8+
# Check if the profile script exists before sourcing
9+
if [ -f "/root/.nix-profile/etc/profile.d/nix.sh" ]; then
10+
echo "Sourcing /root/.nix-profile/etc/profile.d/nix.sh"
11+
source /root/.nix-profile/etc/profile.d/nix.sh
12+
else
13+
echo "Warning: /root/.nix-profile/etc/profile.d/nix.sh not found. Nix environment may not be fully set up."
14+
fi
715

8-
if command -v home-manager &>/dev/null; then
9-
home-manager switch || echo "home-manager switch fail"
16+
# Source hm-session-vars.sh if it exists (for home-manager)
17+
if [ -f "/root/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
18+
echo "Sourcing /root/.nix-profile/etc/profile.d/hm-session-vars.sh"
19+
source /root/.nix-profile/etc/profile.d/hm-session-vars.sh
20+
else
21+
echo "Warning: /root/.nix-profile/etc/profile.d/hm-session-vars.sh not found. Home-manager variables may not be set."
1022
fi
1123

12-
source /root/.nix-profile/etc/profile.d/hm-session-vars.sh
24+
# Ensure Nix binaries are in PATH for subsequent commands
25+
export PATH="/root/.nix-profile/bin:/root/.nix-profile/sbin:${PATH}"
1326

14-
export PATH="/root/.nix-profile/bin:$PATH"
27+
# Run home-manager switch if home-manager is available
28+
if command -v home-manager &>/dev/null; then
29+
echo "Running home-manager switch..."
30+
home-manager switch || echo "home-manager switch failed."
31+
else
32+
echo "Warning: home-manager not found. Skipping home-manager switch."
33+
fi
1534

35+
# If no arguments are provided, keep the container running
1636
if [[ $# -eq 0 ]]; then
37+
echo "No command provided, keeping container alive..."
1738
set -- tail -f /dev/null
1839
fi
1940

nix_tests/debug_shell.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)