-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
364 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
on: push | ||
|
||
name: CI/CD | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./ | ||
with: | ||
nix_archives_url: https://github.com/nixbuild/nix-quick-install-action/releases/download/v0 | ||
nix_version: 3.0pre20200829_f156513 | ||
nix_conf: experimental-features = nix-command flakes | ||
- name: Build nix archives | ||
id: build-nix-archives | ||
run: | | ||
nix build .#nix-archives | ||
echo "::set-output name=result::$(readlink result)" | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: nix-archives | ||
path: ${{ steps.build-nix-archives.outputs.result }}/ | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
strategy: | ||
matrix: | ||
nix_version: | ||
- 3.0pre20200829_f156513 | ||
- 2.3.7 | ||
- 2.2.2 | ||
- 2.1.3 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/download-artifact@v2 | ||
id: nix-archives | ||
with: | ||
name: nix-archives | ||
- uses: ./ | ||
with: | ||
nix_archives_url: file://${{steps.nix-archives.outputs.download-path}} | ||
nix_version: ${{ matrix.nix_version }} | ||
- name: Test nix | ||
run: nix-build --version | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
needs: [build, test] | ||
if: github.ref == 'refs/heads/master' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/download-artifact@v2 | ||
id: nix-archives | ||
with: | ||
name: nix-archives | ||
- uses: ./ | ||
with: | ||
nix_archives_url: file://${{steps.nix-archives.outputs.download-path}} | ||
nix_version: 3.0pre20200829_f156513 | ||
nix_conf: experimental-features = nix-command flakes | ||
- name: Build release script | ||
run: nix build .#release | ||
- name: Release if needed | ||
run: ./result/bin/release ${{steps.nix-archives.outputs.download-path}} ./RELEASE | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,29 @@ | ||
# nix-quick-install-action | ||
# Nix Quick Install Action | ||
|
||
This GitHub Action installs [Nix](https://nixos.org/nix/) in single-user mode. | ||
|
||
## Description | ||
|
||
To make the action as quick as possible, the installation is minimal: no | ||
nix-daemon, no nix channels and no `NIX_PATH`. The nix store (`/nix/store`) is | ||
owned by the unprivileged runner user. The action has inputs for selecting which | ||
Nix version to use, and to specify `nix.conf` contents. | ||
|
||
The action provides you with a fully working Nix setup, but since no `NIX_PATH` | ||
or channels are setup you need to handle this on your own. Nix Flakes is great | ||
for this, and works perfectly with this action (see below). | ||
[niv](https://github.com/nmattia/niv) should also work fine, but has not been | ||
tested yet. | ||
|
||
If this action doesn't work out for your use case, you should look at the | ||
[Install Nix](https://github.com/marketplace/actions/install-nix) action. | ||
|
||
## Usage | ||
|
||
Coming soon | ||
|
||
## Inputs | ||
|
||
See [action.yml](action.yml) for documentation of the available inputs. | ||
Available Nix versions are listed in the [release | ||
notes](https://github.com/nixbuild/nix-quick-install-action/releases/latest). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Nix Quick Install | ||
description: Quickly installs Nix in unprivileged single-user mode | ||
author: Rickard Nilsson | ||
|
||
inputs: | ||
|
||
nix_version: | ||
required: true | ||
default: "2.3.7" | ||
description: | | ||
The version of Nix that should be installed | ||
If not specified, the latest stable Nix release is used. Note that each | ||
release of nix-quick-install-action has a specific set of supported | ||
Nix versions, which do not change. You can check what Nix versions are | ||
supported by the version of nix-quick-install-action you're using by | ||
going to https://github.com/nixbuild/nix-quick-install-action/releases | ||
nix_conf: | ||
required: false | ||
description: | | ||
If set, this configuration is written to a new file which is then added to | ||
the NIX_USER_CONF_FILES environment variable. You can also set that | ||
variable yourself to control the Nix configuration. | ||
nix_archives_url: | ||
required: false | ||
description: | | ||
Don't use. For bootstrapping purposes only. | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install Nix in single-user mode | ||
run: ${{ github.action_path }}/nix-quick-install.sh | ||
shell: bash | ||
env: | ||
RELEASE_FILE: ${{ github.action_path }}/RELEASE | ||
NIX_VERSION: ${{ inputs.nix_version }} | ||
NIX_CONF: ${{ inputs.nix_conf }} | ||
NIX_ARCHIVES_URL: ${{ inputs.nix_archives_url }} | ||
|
||
|
||
branding: | ||
icon: zap | ||
color: gray-dark |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
description = "nix-quick-install-action"; | ||
|
||
inputs = { | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
nixpkgs.url = "nixpkgs/nixos-unstable-small"; | ||
nixpkgs-nix-2_3_7.url = "nixpkgs/046427570ebe2726a2f21c3b51d84d29c86ebde5"; | ||
nixpkgs-nix-2_2_2.url = "nixpkgs/5399f34ad9481849720d14605ce87b81abe202e9"; | ||
nixpkgs-nix-2_2_2.flake = false; | ||
nixpkgs-nix-2_1_3.url = "nixpkgs/2c9265c95075170ad210ed5635ecffcd36db6b84"; | ||
nixpkgs-nix-2_1_3.flake = false; | ||
}; | ||
|
||
outputs = { | ||
self, flake-utils, nixpkgs, | ||
nixpkgs-nix-2_3_7, nixpkgs-nix-2_2_2, nixpkgs-nix-2_1_3 | ||
}: flake-utils.lib.eachSystem ["x86_64-linux"] (system: | ||
|
||
let | ||
|
||
inherit (nixpkgs) lib; | ||
|
||
pkgs = nixpkgs.legacyPackages.${system}; | ||
|
||
makeNixArchive = nix: | ||
pkgs.runCommand "nix-archive" { | ||
buildInputs = [ nix pkgs.gnutar pkgs.zstd ]; | ||
closureInfo = pkgs.closureInfo { rootPaths = [ nix ]; }; | ||
fileName = "nix-${nix.version}-${system}.tar.zstd"; | ||
inherit nix; | ||
} '' | ||
mkdir -p "$out" root/nix/var/nix | ||
NIX_STATE_DIR="$(pwd)/root/nix/var/nix" nix-store --load-db \ | ||
< $closureInfo/registration | ||
ln -s $nix/bin root/nix/bin | ||
tar -cvT $closureInfo/store-paths -C root . | zstd - -o "$out/$fileName" | ||
''; | ||
|
||
nixArchives = lib.listToAttrs (map (nix: lib.nameValuePair | ||
nix.version (makeNixArchive nix) | ||
) [ | ||
pkgs.nixUnstable | ||
nixpkgs-nix-2_3_7.legacyPackages.${system}.nix | ||
(import nixpkgs-nix-2_2_2 { inherit system; }).nix | ||
(import nixpkgs-nix-2_1_3 { inherit system; }).nix | ||
]); | ||
|
||
in rec { | ||
defaultApp = apps.release; | ||
|
||
apps.release= flake-utils.lib.mkApp { drv = packages.release; }; | ||
|
||
packages = { | ||
nix-archives = pkgs.buildEnv { | ||
name = "nix-archives"; | ||
paths = lib.attrValues nixArchives; | ||
}; | ||
release = pkgs.writeScriptBin "release" '' | ||
#!${pkgs.stdenv.shell} | ||
PATH="${lib.makeBinPath (with pkgs; [ | ||
coreutils gitMinimal github-cli | ||
])}" | ||
if [ "$GITHUB_ACTIONS" != "true" ]; then | ||
echo >&2 "not running in GitHub, exiting" | ||
exit 1 | ||
fi | ||
set -euo pipefail | ||
nix_archives="$1" | ||
release_file="$2" | ||
release="$(cat "$release_file")" | ||
prev_release="$(gh release list -L 1 | cut -f 3)" | ||
if [ "$release" = "$prev_release" ]; then | ||
echo >&2 "Release tag not updated ($release)" | ||
exit | ||
else | ||
echo >&2 "New release: $prev_release -> $release" | ||
gh release create "$release" ${ | ||
lib.concatStringsSep " " (lib.mapAttrsToList (version: archive: | ||
''"$nix_archives/${archive.fileName}#nix-${version}-${system}"'' | ||
) nixArchives) | ||
} \ | ||
--title "$GITHUB_REPOSITORY@$release" \ | ||
--notes-file "${pkgs.writeText "notes" '' | ||
## Supported Nix Versions | ||
${lib.concatStringsSep "\n" ( | ||
map (v: "* ${v}") (lib.reverseList (lib.attrNames nixArchives)) | ||
)} | ||
''}" | ||
fi | ||
''; | ||
}; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
# Create user-writeable /nix | ||
sudo install -d -o "$USER" /nix | ||
|
||
# Fetch and unpack nix | ||
sys="x86_64-linux" # TODO auto detect | ||
rel="$(cat "$RELEASE_FILE")" | ||
url="${NIX_ARCHIVES_URL:-https://github.com/nixbuild/nix-quick-install-action/releases/download/$rel}/nix-$NIX_VERSION-$sys.tar.zstd" | ||
|
||
curl -sL --retry 3 --retry-connrefused "$url" | zstdcat | \ | ||
tar --no-overwrite-dir -xC / | ||
|
||
# Setup nix.conf | ||
if [ -n "$NIX_CONF" ]; then | ||
NIX_CONF_FILE="$(mktemp --tmpdir XXXX_nix.conf)" | ||
NIX_USER_CONF_FILES="$NIX_CONF_FILE${NIX_USER_CONF_FILES:+:}${NIX_USER_CONF_FILES:-}" | ||
echo "$NIX_CONF" > "$NIX_CONF_FILE" | ||
echo "::set-env name=NIX_USER_CONF_FILES::$NIX_USER_CONF_FILES" | ||
fi | ||
|
||
# Set PATH | ||
echo "::add-path::/nix/bin" |