This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
forked from nixbuild/nix-quick-install-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
151 lines (150 loc) · 6.12 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
name: Lix Quick Install
description: Install Lix on GitHub Actions faster than you can refresh your browser[1]
author: F. Emerson
inputs:
lix-version:
description: |
The version of Lix that should be installed.
If not specified, the latest stable Lix release is used. Note that each
release of action-lix-quick-install has a specific set of supported
Lix versions, which do not change. You can check what Lix versions are
supported by the version of action-lix-quick-install you're using by
going to https://github.com/fabrictest/action-lix-quick-install/releases.
required: false
nix-conf:
description: |
If set, this configuration is written to $XDG_CONFIG_HOME/nix/nix.conf,
which is read by Lix.
See https://docs.lix.systems/manual/lix/stable/command-ref/conf-file.html for
information on what settings that are available. Make sure the settings
you define are supported by the Lix version you're using.
required: false
github-token:
description: |
Configure Lix to use the specified token when fetching from GitHub.
Defaults to `github.token`.
default: ${{ github.token }}
lix-on-tmpfs:
description: |
Installs /nix on a tmpfs mount. This can make Lix operations faster, but
you risk running out of memory if your Lix store grows too big. Only
enable this if you're absolutely sure the size of your Lix store (and
database, logs etc) will be considerably less than the available memory.
This option does nothing on MacOS runners.
default: false
lix-store-base-url:
description: |
Internal.
required: false
runs:
using: composite
steps:
- name: Do preflight checks
shell: bash
run: |
#
test ! -e /nix -o -w /nix || {
printf "::error::failed to set up Lix: /nix exists but isn't writable\n"
exit 1
}
- name: Resolve variables
id: vars
shell: bash
run: |
#
test -n "$LIX_VERSION" || unset LIX_VERSION
{
test -e /nix || printf install-nix-dir=1\\n
xargs printf our-version=%s\\n <"$GITHUB_ACTION_PATH"/VERSION
xargs printf lix-version=%s\\n <<<"${LIX_VERSION:-$LIX_DEFAULT_VERSION}"
} >>"$GITHUB_OUTPUT"
env:
LIX_VERSION: ${{ inputs.lix-version }}
# renovate: datasource=github-tags depName=lix-project/lix
LIX_DEFAULT_VERSION: 2.91.1
- name: Mount `/nix` (Linux)
if: ${{ steps.vars.outputs.install-nix-dir && runner.os == 'Linux' }}
shell: bash
run: |
#
sudo install -d -o "$USER" /nix
${{
inputs.lix-on-tmpfs &&
'sudo mount -t tmpfs -o "size=90%,mode=0755,uid=$UID,gid=$(id -g)" tmpfs /nix' ||
''
}}
- name: Mount `/nix` (macOS)
if: ${{ steps.vars.outputs.install-nix-dir && runner.os == 'macOS' }}
shell: bash
run: |
#
sudo tee -a /etc/synthetic.conf ${{ runner.debug && '' || '>/dev/null' }} <<"EOF"
nix
run private/var/run
EOF
sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t ${{ runner.debug && '' || '>/dev/null 2>&1' }} || :
test -L /run || {
printf "::error::failed to set up Lix: apfs.util couldn't symlink /run\n"
exit 1
}
root_disk=$(stat -f %Sd /)
sudo diskutil apfs addVolume "${root_disk%s[0-9]*}" APFS nix -mountpoint /nix ${{ runner.debug && '' || '>/dev/null 2>&1' }}
sudo mdutil -i off /nix ${{ runner.debug && '' || '>/dev/null 2>&1' }}
sudo chown "$USER" /nix ${{ runner.debug && '' || '>/dev/null 2>&1' }}
- name: Fetch `/nix` archive
shell: bash
run: |
#
rm -rf /nix/var/action-lix-quick-install
${{
startsWith(inputs.lix-store-base-url, 'file://') &&
'<"${lix_archive_url#*://}"' ||
'curl --fail --location --retry-connrefused --silent --show-error --retry 3 "$lix_archive_url" |'
}} ${{ runner.os == 'macOS' && 'gtar' || 'tar' }} --auto-compress --extract --skip-old-files --directory=/nix --strip-components=1
env:
lix_archive_url: >-
${{
format('{0}/lix-{1}-{2}-{3}.tar.zstd',
inputs.lix-store-base-url || format('{0}/{1}/releases/download/v{2}', github.server_url, github.action_repository, steps.vars.outputs.our-version),
steps.vars.outputs.lix-version,
(runner.arch == 'ARM64' && 'aarch64') || (runner.arch == 'X64' && 'x86_64') || runner.arch,
(runner.os == 'Linux' && 'linux') || (runner.os == 'macOS' && 'darwin') || runner.os
)
}}
- name: Synthesize `nix.conf`
shell: bash
run: |
#
: "${XDG_CONFIG_HOME:=$HOME/.config}"
mkdir -p "$XDG_CONFIG_HOME/nix/$GITHUB_REPOSITORY"
${{ runner.debug && 'tee' || 'cat >' }} "$XDG_CONFIG_HOME/nix/nix.conf" <<EOF
accept-flake-config = true
access-tokens = ${GITHUB_SERVER_URL#*://}=$GITHUB_TOKEN
experimental-features = nix-command flakes
include $XDG_CONFIG_HOME/nix/$GITHUB_REPOSITORY/nix.conf
EOF
${{ runner.debug && 'tee' || 'cat >' }} "$XDG_CONFIG_HOME/nix/$GITHUB_REPOSITORY/nix.conf" <<EOF
$nix_conf
EOF
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
nix_conf: ${{ inputs.nix-conf }}
- name: Install Lix
shell: bash
run: |
#
CDPATH='' cd "$(readlink /nix/var/action-lix-quick-install/lix)"
./bin/nix-store --load-db </nix/var/action-lix-quick-install/registration
MANPATH='' . ./etc/profile.d/nix.sh
: "${NIX_SSL_CERT_FILE:=$(test ! -e /etc/ssl/cert.pem || printf /etc/ssl/cert.pem)}"
./bin/nix-env --install "$PWD"
printf %s/.nix-profile/bin\\n "$HOME" >>"$GITHUB_PATH"
${{ runner.debug && 'tee -a' || 'cat >>' }} "$GITHUB_ENV" <<EOF
NIX_PROFILES=/nix/var/nix/profiles/default $HOME/.nix-profile
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
NIX_SSL_CERT_FILE=$NIX_SSL_CERT_FILE
EOF
branding:
icon: package
color: purple