diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index df30756b5..000000000 --- a/.dockerignore +++ /dev/null @@ -1,9 +0,0 @@ -* -!Dockerfile -!Makefile -!flake.lock -!flake.nix -!lib/ -!lib/** -!scripts/ -!scripts/nix-cache-warmup.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1aed56863..26531bb7b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -72,28 +72,21 @@ jobs: context: . file: ./Dockerfile platforms: ${{ matrix.build.platform }} - push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + push: true tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} build-args: | COMMIT_SHA=${{ github.sha }} + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} GITHUB_PR=${{ github.event.pull_request.number }} - secrets: | - github_token=${{ secrets.GITHUB_TOKEN }} - cache-from: | - type=gha,scope=dotfiles-docker-${{ matrix.build.arch }} - type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ matrix.build.arch }} - cache-to: | - type=gha,scope=dotfiles-docker-${{ matrix.build.arch }},mode=max - ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && format('type=registry,ref={0}:buildcache-{1},mode=max', env.REGISTRY_IMAGE, matrix.build.arch) || '' }} + cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ matrix.build.arch }} + cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ matrix.build.arch }},mode=max - name: Export digest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' run: | mkdir -p ${{ runner.temp }}/digests digest="${{ steps.build.outputs.digest }}" touch "${{ runner.temp }}/digests/${digest#sha256:}" - name: Upload digest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: actions/upload-artifact@v7 with: name: digests-${{ matrix.build.arch }} diff --git a/Dockerfile b/Dockerfile index 8324b31be..7f73afdf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,3 @@ -# syntax=docker/dockerfile:1.7 - FROM ubuntu:26.04 # Set DEBIAN_FRONTEND to noninteractive to avoid prompts during package installations @@ -29,6 +27,10 @@ RUN apt-get update && apt-get install -y \ ARG USER=runner ARG USER_UID=1001 ARG USER_GID=$USER_UID +ARG COMMIT_SHA=main +ARG GITHUB_TOKEN +ARG GITHUB_PR +ENV GITHUB_PR=${GITHUB_PR} RUN set -e; \ groupadd --gid $USER_GID $USER; \ @@ -47,30 +49,17 @@ RUN mkdir -p /etc/nix && \ echo "trusted-users = root $USER" > /etc/nix/nix.conf && \ echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf && \ echo "filter-syscalls = false" >> /etc/nix/nix.conf && \ - echo "sandbox = true" >> /etc/nix/nix.conf - -COPY --chown=$USER:$USER Makefile flake.nix flake.lock /tmp/dotfiles-cache/ -COPY --chown=$USER:$USER lib /tmp/dotfiles-cache/lib -COPY --chown=$USER:$USER scripts/nix-cache-warmup.sh /tmp/dotfiles-cache/scripts/nix-cache-warmup.sh - -RUN --mount=type=secret,id=github_token,mode=0444 \ - set -e; \ - /usr/bin/nix-daemon & \ - sleep 5 && \ - sudo -u "$USER" -H env GITHUB_TOKEN_FILE=/run/secrets/github_token IN_DOCKER=true USER="$USER" \ - make -C /tmp/dotfiles-cache nix-cache-warmup - -ARG COMMIT_SHA=main -ARG GITHUB_PR= + echo "sandbox = true" >> /etc/nix/nix.conf && \ + if [ -n "$GITHUB_TOKEN" ]; then \ + echo "access-tokens = github.com=$GITHUB_TOKEN" >> /etc/nix/nix.conf ; \ + fi -RUN --mount=type=secret,id=github_token,mode=0444 \ - set -e; \ - /usr/bin/nix-daemon & \ +RUN /usr/bin/nix-daemon & \ sleep 5 && \ # Run your dotfiles installation script. # This script is expected to install fish and other tools. # Make sure this script is idempotent or handles being run in a fresh environment. - sudo -u "$USER" -H env GITHUB_PR="$GITHUB_PR" GITHUB_TOKEN_FILE=/run/secrets/github_token IN_DOCKER=true USER="$USER" bash -c "curl -fsSL https://raw.githubusercontent.com/shunkakinoki/dotfiles/$COMMIT_SHA/install.sh | bash" + sudo -u $USER -E -H bash -c "curl -fsSL https://raw.githubusercontent.com/shunkakinoki/dotfiles/$COMMIT_SHA/install.sh | bash" # Switch to the non-root user USER $USER diff --git a/Makefile b/Makefile index ffc207765..606f7c12c 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ ARCH := $(shell uname -m) OS := $(shell uname -s) # Git variables -GIT_REMOTE_ORIGIN_URL := $(shell git config --get remote.origin.url 2>/dev/null) +GIT_REMOTE_ORIGIN_URL := $(shell git config --get remote.origin.url) GITHUB_REPO_PATH := $(shell echo $(GIT_REMOTE_ORIGIN_URL) | sed -n 's/.*github.com[:/]\(.*\)\.git/\1/p') GITHUB_REPO_OWNER := $(shell echo $(GITHUB_REPO_PATH) | cut -d'/' -f1) GITHUB_REPO_NAME := $(shell echo $(GITHUB_REPO_PATH) | cut -d'/' -f2) -GIT_COMMIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) +GIT_COMMIT_SHA := $(shell git rev-parse --short HEAD) # Env ironment variables NIX_ALLOW_UNFREE := NIXPKGS_ALLOW_UNFREE=1 @@ -151,7 +151,7 @@ help: ## Show this help message. ##@ General .PHONY: install -install: setup git-submodule-sync nix-cache-warmup nix-build nix-switch shell-install ## Set up full environment (setup, cache warmup, build, switch, shell-install). +install: setup git-submodule-sync nix-build nix-switch shell-install ## Set up full environment (setup, flake-update, build, switch, shell-install). .PHONY: build build: nix-build ## Build Nix configuration. @@ -432,16 +432,6 @@ nix-install: ## Install Nix if not already installed. fi @echo "✅ Nix environment installed!" -.PHONY: nix-cache-warmup -nix-cache-warmup: nix-connect nix-trust ## Warm flake input metadata before build/switch. - @echo "🔥 Warming Nix flake cache..." - @if command -v nix >/dev/null 2>&1; then \ - $(NIX_ALLOW_UNFREE) sh ./scripts/nix-cache-warmup.sh . $(NIX_FLAGS); \ - echo "✅ Nix flake cache warmed"; \ - else \ - echo "⚠️ Nix unavailable; skipping cache warmup"; \ - fi - ##@ Nix .PHONY: nix-update diff --git a/home-manager/programs/atuin/default.nix b/home-manager/programs/atuin/default.nix index c5243fbe8..17a2a3fed 100644 --- a/home-manager/programs/atuin/default.nix +++ b/home-manager/programs/atuin/default.nix @@ -10,9 +10,6 @@ sync_address = "https://api.atuin.sh"; search_mode = "fuzzy"; filter_mode = "global"; - history = { - exit_code = "all"; - }; sync = { records = true; }; diff --git a/install.sh b/install.sh index 2eca1d854..74ab8196e 100755 --- a/install.sh +++ b/install.sh @@ -38,25 +38,6 @@ else echo "USER variable is already set to: $USER. Ensuring it is exported." fi -NIX_GITHUB_TOKEN="" -if [ -n "${GITHUB_TOKEN:-}" ]; then - NIX_GITHUB_TOKEN="$GITHUB_TOKEN" -elif [ -n "${GITHUB_TOKEN_FILE:-}" ] && [ -r "$GITHUB_TOKEN_FILE" ]; then - NIX_GITHUB_TOKEN=$(cat "$GITHUB_TOKEN_FILE") -fi - -if [ -n "$NIX_GITHUB_TOKEN" ]; then - if [ -n "${NIX_CONFIG:-}" ]; then - NIX_CONFIG="${NIX_CONFIG} -access-tokens = github.com=$NIX_GITHUB_TOKEN" - else - NIX_CONFIG="access-tokens = github.com=$NIX_GITHUB_TOKEN" - fi - export NIX_CONFIG - echo "Configured a GitHub token for Nix fetches during this install." -fi -unset NIX_GITHUB_TOKEN - # Install Nix if not already installed if ! command -v nix >/dev/null 2>&1; then echo "Installing Nix..." diff --git a/scripts/nix-cache-warmup.sh b/scripts/nix-cache-warmup.sh deleted file mode 100644 index 52dd75ae1..000000000 --- a/scripts/nix-cache-warmup.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -set -e - -repo_dir=${1:-.} -if [ "$#" -gt 0 ]; then - shift -fi - -nix_github_token="" -if [ -n "${GITHUB_TOKEN:-}" ]; then - nix_github_token="$GITHUB_TOKEN" -elif [ -n "${GITHUB_TOKEN_FILE:-}" ] && [ -r "$GITHUB_TOKEN_FILE" ]; then - nix_github_token=$(cat "$GITHUB_TOKEN_FILE") -fi - -if [ -n "$nix_github_token" ]; then - if [ -n "${NIX_CONFIG:-}" ]; then - NIX_CONFIG="${NIX_CONFIG} -access-tokens = github.com=$nix_github_token" - else - NIX_CONFIG="access-tokens = github.com=$nix_github_token" - fi - export NIX_CONFIG -fi -unset nix_github_token - -if ! command -v nix >/dev/null 2>&1; then - echo "Nix unavailable; skipping cache warmup" - exit 0 -fi - -nix flake metadata "$repo_dir" "$@" --no-write-lock-file >/dev/null diff --git a/spec/coverage_spec.sh b/spec/coverage_spec.sh index d7cdd7b54..f37755fa3 100644 --- a/spec/coverage_spec.sh +++ b/spec/coverage_spec.sh @@ -117,10 +117,6 @@ It 'has spec file for named-hosts/kyber/setup.sh' The path "spec/kyber_setup_spec.sh" should be exist End -It 'has spec file for scripts/nix-cache-warmup.sh' -The path "spec/nix_cache_warmup_spec.sh" should be exist -End - It 'has spec file for scripts/update-gitalias.sh' The path "spec/update_gitalias_spec.sh" should be exist End @@ -443,7 +439,6 @@ scripts/check-nix-inline-scripts.sh scripts/find-built-iso.sh scripts/fishtape-wrapper.sh scripts/llm-update.sh -scripts/nix-cache-warmup.sh scripts/sync-codex-security.sh scripts/sync-rtk-rewrite.sh scripts/update-gitalias.sh diff --git a/spec/nix_cache_warmup_spec.sh b/spec/nix_cache_warmup_spec.sh deleted file mode 100644 index d9d22d134..000000000 --- a/spec/nix_cache_warmup_spec.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash -# shellcheck disable=SC2329,SC2034,SC2016 - -Describe 'scripts/nix-cache-warmup.sh' -SCRIPT="$PWD/scripts/nix-cache-warmup.sh" - -Describe 'script properties' -It 'uses sh shebang' -When run bash -c "head -1 '$SCRIPT'" -The output should include '#!/bin/sh' -End - -It 'uses strict mode' -When run bash -c "head -5 '$SCRIPT'" -The output should include 'set -e' -End -End - -Describe 'github token handling' -It 'checks GITHUB_TOKEN env var' -When run bash -c "grep 'GITHUB_TOKEN' '$SCRIPT'" -The output should include 'GITHUB_TOKEN' -End - -It 'checks GITHUB_TOKEN_FILE env var' -When run bash -c "grep 'GITHUB_TOKEN_FILE' '$SCRIPT'" -The output should include 'GITHUB_TOKEN_FILE' -End - -It 'sets access-tokens in NIX_CONFIG' -When run bash -c "grep 'access-tokens' '$SCRIPT'" -The output should include 'access-tokens' -End - -It 'unsets token variable after use' -When run bash -c "grep 'unset nix_github_token' '$SCRIPT'" -The output should include 'unset nix_github_token' -End -End - -Describe 'nix availability check' -It 'checks if nix command exists' -When run bash -c "grep 'command -v nix' '$SCRIPT'" -The output should include 'command -v nix' -End - -It 'skips gracefully when nix is unavailable' -When run bash -c "grep 'skipping cache warmup' '$SCRIPT'" -The output should include 'skipping cache warmup' -End -End - -Describe 'flake metadata' -It 'runs nix flake metadata' -When run bash -c "grep 'nix flake metadata' '$SCRIPT'" -The output should include 'nix flake metadata' -End - -It 'uses --no-write-lock-file flag' -When run bash -c "grep 'no-write-lock-file' '$SCRIPT'" -The output should include '--no-write-lock-file' -End -End - -Describe 'repo directory argument' -It 'defaults repo_dir to current directory' -When run bash -c "grep 'repo_dir=\${1:-.}' '$SCRIPT'" -The output should include 'repo_dir=${1:-.}' -End -End - -End