1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-11 11:47:03 +03:00

Switching from nixpkgs-mozilla overlay to rust-overlay

This commit is contained in:
Rok Garbas 2022-01-17 12:53:18 +01:00
parent 9826d59d90
commit dba0dbf90c
No known key found for this signature in database
GPG Key ID: A0E01EF44C27BF00
7 changed files with 83 additions and 178 deletions

View File

@ -1,60 +0,0 @@
name: "Update Rust channels"
on:
schedule:
- cron: '1 1 * * *'
jobs:
update-rust-channels:
strategy:
# Run in sequence to prevent `git push` overlaps
max-parallel: 1
matrix:
rust_channel:
- stable
- beta
- nightly
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- name: Checking out the repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Installing Nix
uses: cachix/install-nix-action@v14.1
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
- name: Setup Cachix
uses: cachix/cachix-action@v10
with:
name: nickel
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Update `${{ matrix.rust_channel }}` channel
run: |
bash ./scripts/update_channel.sh ${{ matrix.rust_channel }}
- name: Build Nickel against `${{ matrix.rust_channel }}` Rust channel
run: |
nix build ./#checks.x86_64-linux.nickel-against-${{ matrix.rust_channel }}-rust-channel
- name: Commit `scripts/channel_${{ matrix.rust_channel }}.toml`
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Update `${{ matrix.rust_channel }}` Rust channel [ci skip]'
branch: 'master'
file_pattern: scripts/channel_${{ matrix.rust_channel }}.toml
# See https://github.community/t/github-actions-bot-email-address/17204/6
commit_user_name: github-actions[bot]
commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com
commit_author: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
if: github.repository == 'tweag/nickel'

View File

@ -15,6 +15,21 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_2": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"import-cargo": { "import-cargo": {
"locked": { "locked": {
"lastModified": 1594305518, "lastModified": 1594305518,
@ -45,38 +60,20 @@
"type": "indirect" "type": "indirect"
} }
}, },
"nixpkgs-mozilla": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1630405024,
"narHash": "sha256-DvYmScld4IOj8DdIF4RI8B2POAD7BVgajdUviWpBhgM=",
"owner": "nickel-lang",
"repo": "nixpkgs-mozilla",
"rev": "38af8eb25905bcece8c1adc5d80e3f26f5e533f8",
"type": "github"
},
"original": {
"owner": "nickel-lang",
"ref": "flake",
"repo": "nixpkgs-mozilla",
"type": "github"
}
},
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1630248577, "lastModified": 1637453606,
"narHash": "sha256-9d/yq96TTrnF7qjA6wPYk+rYjWAXwfUmwk3qewezSeg=", "narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "8d8a28b47b7c41aeb4ad01a2bd8b7d26986c3512", "rev": "8afc4e543663ca0a6a4f496262cd05233737e732",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixpkgs-unstable",
"type": "indirect" "repo": "nixpkgs",
"type": "github"
} }
}, },
"root": { "root": {
@ -84,7 +81,26 @@
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"import-cargo": "import-cargo", "import-cargo": "import-cargo",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-mozilla": "nixpkgs-mozilla" "rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1642301007,
"narHash": "sha256-YKs/KV8Rdv8K33RidbjH78nZeMDqKUCwsdq8bow7Ogc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "9c426beb3820ca3ede6349c664eb461ae4603565",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
} }
} }
}, },

View File

@ -1,7 +1,7 @@
{ {
inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs-mozilla.url = "github:nickel-lang/nixpkgs-mozilla/flake"; inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.import-cargo.url = "github:edolstra/import-cargo"; inputs.import-cargo.url = "github:edolstra/import-cargo";
nixConfig = { nixConfig = {
@ -12,7 +12,7 @@
outputs = { self outputs = { self
, nixpkgs , nixpkgs
, flake-utils , flake-utils
, nixpkgs-mozilla , rust-overlay
, import-cargo , import-cargo
}: }:
let let
@ -23,15 +23,12 @@
"x86_64-linux" "x86_64-linux"
]; ];
RUST_CHANNELS = readRustChannels [ RUST_CHANNELS = [
"stable" "stable"
"beta" "beta"
"nightly" "nightly"
]; ];
readRustChannel = c: builtins.fromTOML (builtins.readFile (./. + "/scripts/channel_${c}.toml"));
readRustChannels = cs: builtins.listToAttrs (map (c: { name = c; value = readRustChannel c; }) cs);
cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml); cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml);
WasmBindgenCargoVersion = cargoTOML.dependencies.wasm-bindgen.version; WasmBindgenCargoVersion = cargoTOML.dependencies.wasm-bindgen.version;
WasmBindgenVersion = builtins.substring 1 (builtins.stringLength WasmBindgenCargoVersion) WasmBindgenCargoVersion; WasmBindgenVersion = builtins.substring 1 (builtins.stringLength WasmBindgenCargoVersion) WasmBindgenCargoVersion;
@ -67,7 +64,10 @@
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ customOverlay nixpkgs-mozilla.overlays.rust ]; overlays = [
(import rust-overlay)
customOverlay
];
}; };
cargoHome = (import-cargo.builders.importCargo { cargoHome = (import-cargo.builders.importCargo {
@ -75,24 +75,6 @@
inherit pkgs; inherit pkgs;
}).cargoHome; }).cargoHome;
rustPlatform =
builtins.listToAttrs
(builtins.map
(channel:
let
manifestFile = builtins.fetchurl {
url = pkgs.lib.rustLib.manifest_v2_url RUST_CHANNELS.${channel};
sha256 = RUST_CHANNELS.${channel}.sha256;
};
in { name = channel;
value = pkgs.lib.rustLib.fromManifestFile manifestFile {
inherit (pkgs) lib stdenv fetchurl patchelf;
};
}
)
(builtins.attrNames RUST_CHANNELS)
);
# Additional packages required for some systems to build Nickel # Additional packages required for some systems to build Nickel
missingSysPkgs = missingSysPkgs =
if pkgs.stdenv.isDarwin then if pkgs.stdenv.isDarwin then
@ -108,15 +90,20 @@
, checkFmt ? false , checkFmt ? false
}: }:
let let
rustProfile =
if isShell then "default"
else "minimal";
rust = rust =
rustPlatform.${channel}.rust.override { if channel == "nightly" then
extensions = if isShell then [ pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.${rustProfile}.override {
"rust-src" extensions = [ "rustfmt-preview" ];
"rust-analysis" })
"rustfmt-preview" else
"clippy-preview" pkgs.rust-bin.${channel}.latest.${rustProfile}.override {
] else []; extensions = [ "rustfmt-preview" ];
}; };
in pkgs.stdenv.mkDerivation { in pkgs.stdenv.mkDerivation {
name = "nickel-${version}"; name = "nickel-${version}";
@ -149,31 +136,37 @@
cargo install --frozen --offline --path lsp/nls --root $out cargo install --frozen --offline --path lsp/nls --root $out
rm $out/.crates.toml rm $out/.crates.toml
''; '';
passhtru.rust = rust;
}; };
buildNickelWASM = { channel ? "stable" buildNickelWASM = { channel ? "stable"
, optimize ? true , optimize ? true
}: }:
let let
rust = rustPlatform.${channel}.rust.override({ rust =
targets = ["wasm32-unknown-unknown"]; if channel == "nightly" then
}); pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override {
targets = ["wasm32-unknown-unknown"];
})
else
pkgs.rust-bin.${channel}.latest.minimal.override {
targets = ["wasm32-unknown-unknown"];
};
in pkgs.stdenv.mkDerivation { in pkgs.stdenv.mkDerivation {
name = "nickel-wasm-${version}"; name = "nickel-wasm-${version}";
src = self;
nativeBuildInputs = [ pkgs.jq ];
buildInputs = buildInputs =
[ [ rust
rust
pkgs.wasm-pack pkgs.wasm-pack
pkgs.wasm-bindgen-cli pkgs.wasm-bindgen-cli
pkgs.binaryen pkgs.binaryen
cargoHome cargoHome
] ] ++ missingSysPkgs;
++ missingSysPkgs;
nativeBuildInputs = [pkgs.jq];
src = self;
preBuild = preBuild =
'' ''
@ -273,12 +266,10 @@
buildDevShell = { channel ? "stable" }: buildDevShell = { channel ? "stable" }:
let let
nickel = buildNickel { isShell = true; }; nickel = buildNickel { isShell = true; };
rust = rustPlatform.${channel}.rust.override({
extensions = [ "rustfmt-preview" ];
});
rustFormatHook = pkgs.writeShellScriptBin "check-rust-format-hook" rustFormatHook = pkgs.writeShellScriptBin "check-rust-format-hook"
'' ''
${rust}/bin/cargo fmt -- --check ${nickel.rust}/bin/cargo fmt -- --check
RESULT=$? RESULT=$?
[ $RESULT != 0 ] && echo "Please run \`cargo fmt\` before" [ $RESULT != 0 ] && echo "Please run \`cargo fmt\` before"
exit $RESULT exit $RESULT
@ -374,8 +365,7 @@
builtins.listToAttrs builtins.listToAttrs
(builtins.map (channel: { name = channel; (builtins.map (channel: { name = channel;
value = buildDevShell { inherit channel; }; value = buildDevShell { inherit channel; };
}) }) RUST_CHANNELS
(builtins.attrNames RUST_CHANNELS)
); );
devShell = devShells.stable; devShell = devShells.stable;
@ -389,8 +379,7 @@
(builtins.map (channel: let checkFmt = channel == "stable"; (builtins.map (channel: let checkFmt = channel == "stable";
in { name = "nickel-against-${channel}-rust-channel"; in { name = "nickel-against-${channel}-rust-channel";
value = buildNickel { inherit channel checkFmt; }; value = buildNickel { inherit channel checkFmt; };
}) }) RUST_CHANNELS));
(builtins.attrNames RUST_CHANNELS)));
} }
); );
} }

View File

@ -1,3 +0,0 @@
channel="beta"
date="2022-01-09"
sha256="sha256-J4PElelxqC8MVCyN6BCwJcXSdPJMoxtjgT6EuYFC6lo="

View File

@ -1,3 +0,0 @@
channel="nightly"
date="2022-01-13"
sha256="sha256-5LiUnOIBfJY2ktoAa3e5+QZ3S295OyyFUy3xHfu/kOQ="

View File

@ -1,3 +0,0 @@
channel="stable"
date="2022-01-13"
sha256="sha256-eQBpSmy9+oHfVyPs0Ea+GVZ0fvIatj6QVhNhYKOJ6Jk="

View File

@ -1,31 +0,0 @@
#!/usr/bin/env bash
HERE=$(dirname $0)
CHANNEL=$1
case $CHANNEL in
stable|beta|nightly)
;;
*)
echo "You need to select one of the following channels to update:"
echo " - stable"
echo " - beta"
echo " - nightly"
exit 1
;;
esac
echo "Downloading the latest '$CHANNEL' channel information ..."
curl "https://static.rust-lang.org/dist/channel-rust-$CHANNEL.toml" > $HERE/tmp.toml
CHANNEL_FILE=$HERE/channel_$CHANNEL.toml
CHANNEL_DATE=$(nix-instantiate --eval -E "(builtins.fromTOML (builtins.readFile $HERE/tmp.toml)).date")
CHANNEL_SHA=$(nix hash file $HERE/tmp.toml)
rm -f tmp.toml
echo "channel=\"$CHANNEL\"" > $CHANNEL_FILE
echo "date=$CHANNEL_DATE" >> $CHANNEL_FILE
echo "sha256=\"$CHANNEL_SHA\"" >> $CHANNEL_FILE
echo "Channel info written in $CHANNEL_FILE"