-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaction.yml
104 lines (97 loc) · 4.13 KB
/
action.yml
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
name: "direnv-nix"
description: "Use a nix based direnv environment"
inputs:
nix-cache-prefix:
description: "Prefix for nix store cache key"
required: false
default: "nix-store"
install-nix:
description: "Include nix installation; disable if you installed it before"
required: false
default: "true"
cache-store:
description: "Cache nix store"
required: false
default: "true"
export-all-vars:
description: "Export all ENV vars direnv would touch, not just the PATH"
required: false
default: "true"
nix_install_url:
description: "Installation URL that will contain a script to install Nix."
required: false
default: "https://nixos.org/nix/install"
nix_path:
description: "If installing nix, Set NIX_PATH environment variable."
required: false
default: "nixpkgs=channel:nixos-unstable"
extra_nix_config:
description: "If installing nix, Set NIX_PATH environment variable."
required: false
default: |
sandbox = false
runs:
using: "composite"
steps:
# cache nix store https://github.com/cachix/install-nix-action/issues/56#issuecomment-1240991760
- name: "Cache Nix store"
uses: actions/[email protected]
if: ${{ inputs.cache-store == 'true' }}
id: nix-cache
with:
path: /tmp/nixcache
key: ${{ format('{0}-{1}-{2}', runner.os, inputs.nix-cache-prefix, hashFiles('**/*.nix', '**/flake.lock')) }}
restore-keys: |
${{ format('{0}-{1}', runner.os, inputs.nix-cache-prefix) }}
- uses: cachix/install-nix-action@v20
if: ${{ inputs.install-nix == 'true' }}
with:
nix_path: ${{ inputs.nix_path }}
install_url: ${{ inputs.nix_install_url }}
extra_nix_config: ${{ inputs.extra_nix_config }}
- name: "Import Nix store cache"
shell: bash
if: ${{ inputs.cache-store == 'true' && steps.nix-cache.outputs.cache-hit == 'true' }}
run: |
echo "::group::Nix store import"
nix-store --import < /tmp/nixcache
echo "::endgroup::"
- name: "Setup Nix Environment"
shell: bash
run: |
echo "::group::Nix Environment setup"
nix-env --install --attr direnv nix-direnv -f '<nixpkgs>'
echo "source $HOME/.nix-profile/share/nix-direnv/direnvrc" >> $HOME/.direnvrc
direnv allow .
direnv exec / direnv export json > /tmp/direnv.out
echo "::endgroup::"
- name: "Export Env vars and Path"
uses: actions/github-script@v6
with:
script: |
const fs = require('fs')
const direnvExport = JSON.parse(fs.readFileSync('/tmp/direnv.out'))
console.log(core.getInput('export-all-vars', { required: false }))
const shouldExportEnvVars = (core.getInput('export-all-vars', { required: false }) || 'true') === 'true';
core.startGroup('DirEnvOutput')
core.info(JSON.stringify(direnvExport))
core.info(JSON.stringify(shouldExportEnvVars))
core.endGroup()
core.startGroup('export debug')
Object.keys(direnvExport).forEach(function (name) {
const value = direnvExport[name];
if (name === 'PATH') {
core.addPath(value);
} else if (shouldExportEnvVars) {
core.info({name, value})
core.exportVariable(name, value);
}
});
core.endGroup()
- name: "Export Nix store cache"
shell: bash
if: ${{ inputs.cache-store == 'true' && steps.nix-cache.outputs.cache-hit != 'true' }}
run: |
echo "::group::Nix store export"
nix-store --export $(find /nix/store -maxdepth 1 -name '*-*') > /tmp/nixcache
echo "::endgroup::"