1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-03 22:57:11 +03:00
nickel/flake.nix

734 lines
28 KiB
Nix
Raw Normal View History

2020-07-03 15:22:21 +03:00
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
};
nix-input = {
url = "github:nixos/nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-compat.follows = "pre-commit-hooks/flake-compat";
};
};
};
2020-07-03 15:22:21 +03:00
nixConfig = {
2022-08-01 16:51:45 +03:00
extra-substituters = [ "https://tweag-nickel.cachix.org" ];
extra-trusted-public-keys = [ "tweag-nickel.cachix.org-1:GIthuiK4LRgnW64ALYEoioVUQBWs0jexyoYVeLDBwRA=" ];
};
outputs =
{ self
, nixpkgs
, flake-utils
, pre-commit-hooks
, rust-overlay
, crane
, nix-input
}:
2020-07-03 15:22:21 +03:00
let
2021-01-15 16:23:16 +03:00
SYSTEMS = [
2021-09-13 22:20:54 +03:00
"aarch64-darwin"
"aarch64-linux"
2021-01-15 16:23:16 +03:00
"x86_64-darwin"
2021-09-13 22:20:54 +03:00
"x86_64-linux"
2021-01-15 16:23:16 +03:00
];
RUST_CHANNELS = [
"stable"
"beta"
];
forEachRustChannel = fn: builtins.listToAttrs (builtins.map fn RUST_CHANNELS);
2022-01-15 00:47:05 +03:00
cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);
2022-01-15 00:47:05 +03:00
inherit (cargoTOML.workspace.package) version;
2022-01-17 01:17:41 +03:00
in
flake-utils.lib.eachSystem SYSTEMS (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
# gnulib tests in diffutils fail for musl arm64, cf. https://github.com/NixOS/nixpkgs/pull/241281
(final: prev: {
diffutils =
if !(final.stdenv.hostPlatform.isMusl && final.stdenv.hostPlatform.isAarch64) then
prev.diffutils
else
prev.diffutils.overrideAttrs (old: {
postPatch = ''
sed -i 's:gnulib-tests::g' Makefile.in
'';
});
})
];
config.allowUnfreePredicate = pkg: builtins.elem (pkg.pname or "") [ "terraform" ];
};
wasm-bindgen-cli =
let
wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package);
wasmBindgenVersion = assert builtins.length wasmBindgenCargoVersions == 1; builtins.elemAt wasmBindgenCargoVersions 0;
in
pkgs.wasm-bindgen-cli.override {
version = wasmBindgenVersion;
hash = "sha256-f/RK6s12ItqKJWJlA2WtOXtwX4Y0qa8bq/JHlLTAS3c=";
cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE=";
};
# Additional packages required to build Nickel on Darwin
systemSpecificPkgs =
if pkgs.stdenv.isDarwin then
[
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.libiconv
]
else
[ ];
mkRust =
let
inherit (pkgs.stdenv) hostPlatform;
inherit (pkgs.rust) toRustTarget;
in
{ rustProfile ? "minimal"
, rustExtensions ? [
"rust-src"
"rust-analysis"
"rustfmt"
"clippy"
]
, channel ? "stable"
, targets ? [ (toRustTarget hostPlatform) ]
++ pkgs.lib.optional (!hostPlatform.isMacOS) (toRustTarget pkgs.pkgsMusl.stdenv.hostPlatform)
}:
if channel == "nightly" then
pkgs.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.${rustProfile}.override {
extensions = rustExtensions;
inherit targets;
})
else
pkgs.rust-bin.${channel}.latest.${rustProfile}.override {
extensions = rustExtensions;
inherit targets;
};
# A note on check_format: the way we invoke rustfmt here works locally but fails on CI.
# Since the formatting is checked on CI anyway - as part of the rustfmt check - we
# disable rustfmt in the pre-commit hook when running checks, but enable it when
# running in a dev shell.
pre-commit-builder = { rust ? mkRust { }, checkFormat ? false }: pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
nixpkgs-fmt = {
enable = true;
# Excluded because they are generated by Node2nix
excludes = [
"lsp/vscode-extension/default.nix"
"lsp/vscode-extension/node-env.nix"
"lsp/vscode-extension/node-packages.nix"
];
};
rustfmt = {
enable = checkFormat;
entry = pkgs.lib.mkForce "${rust}/bin/cargo-fmt fmt -- --check --color always";
};
markdownlint = {
enable = true;
excludes = [
"notes/(.+)\\.md$"
"^RELEASES\\.md$"
];
};
# We could use Topiary here, but the Topiary version pulled from Nix
# and the one baked in Nickel could differ. It's saner that what we
# check in the CI is matching exactly the formatting performed by the
# `nickel` binary of this repo.
nickel-format = {
name = "nickel-format";
description = "The nickel formatter";
entry = "${pkgs.lib.getExe self.packages."${system}".default} format";
types = [ "text" ];
enable = true;
# Some tests are currently failing the idempotency check, and
# formatting is less important there. We at least want the examples
# as well as the stdlib to be properly formatted.
files = "\\.ncl$";
excludes = [
"/tests/(.+)\\.ncl$"
];
};
};
};
# Customize source filtering for Crane as Nickel uses non-standard-Rust
# files like `*.lalrpop`.
filterNickelSrc = filterCargoSources:
let
mkFilter = regexp: path: _type: builtins.match regexp path != null;
lalrpopFilter = mkFilter ".*lalrpop$";
nclFilter = mkFilter ".*ncl$";
txtFilter = mkFilter ".*txt$";
snapFilter = mkFilter ".*snap$";
scmFilter = mkFilter ".*scm$";
mdFilter = mkFilter ".*md$"; # include markdown files for checking snippets in the documentation
cxxFilter = mkFilter ".*(cc|hh)$";
importsFilter = mkFilter ".*/core/tests/integration/inputs/imports/imported/.*$"; # include all files that are imported in tests
infraFilter = mkFilter ".*/infra/.*$";
in
pkgs.lib.cleanSourceWith {
src = pkgs.lib.cleanSource ./.;
# Combine our custom filters with the default one from Crane
# See https://github.com/ipetkov/crane/blob/master/docs/API.md#libfiltercargosources
filter = path: type:
builtins.any (filter: filter path type) [
lalrpopFilter
nclFilter
txtFilter
snapFilter
scmFilter
mdFilter
cxxFilter
filterCargoSources
importsFilter
] && !(builtins.any (filter: filter path type) [
infraFilter
]);
};
# if we directly set the revision, it would invalidate the cache on every commit.
# instead we set a static dummy hash and edit the binary in a separate (fast) derivation.
dummyRev = "DUMMYREV_THIS_SHOULD_NOT_APPEAR_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
# pad a string with the tail of another string
padWith = pad: str:
str +
builtins.substring
(builtins.stringLength str)
(builtins.stringLength pad)
pad;
# We want `nickel --version` and `nls --version` to print the git revision
# that nickel was compiled from. However, putting self.shortRev in a
# derivation invalidates the cache on any change, even if otherwise the
# derivation is identical. To mitigate this, we pass an unchanging string
# as the revision in `NICKEL_NIX_BUILD_REV`, and then have a small wrapper
# that replaces that string in the output binary. On every new commit this
# fast derivation will have to be rebuilt, but the slow compilation of
# rust code will only happen on more substantial changes. This is only
# needed for binaries that actually make use of this information (the
# cli and the language server).
fixupGitRevision = pkg: pkgs.stdenv.mkDerivation {
pname = pkg.pname + "-rev-fixup";
inherit (pkg) version meta;
src = pkg;
buildInputs = [ pkgs.bbe ]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.autoSignDarwinBinariesHook ];
phases = [ "fixupPhase" ];
fixupPhase = ''
runHook preFixup
mkdir -p $out/bin
for srcBin in $src/bin/*; do
outBin="$out/bin/$(basename $srcBin)"
# [dirty] must have 7 characters to match dummyRev (hard coded in
# nickel-lang-cli and nickel-lang-lsp)
# we have to pad them out to the same length as dummyRev so they fit
# in the same spot in the binary
bbe -e 's/${dummyRev}/${padWith dummyRev (self.shortRev or "[dirty]")}/' \
$srcBin > $outBin
chmod +x $outBin
done
runHook postFixup
'';
};
# `crane.lib.${system}` is now deprecated, we must use
# `(crane.mkLib nixpkgs.legacyPackages.${system})` instead. Since we
# only ever use `crane.lib.${system}.overrideToolchain` in this flake, we
# expose that function as a top-level function`.
craneOverrideToolchain =
(crane.mkLib pkgs).overrideToolchain;
# Given a rust toolchain, provide Nickel's Rust dependencies, Nickel, as
# well as rust tools (like clippy)
mkCraneArtifacts = { rust ? mkRust { }, noRunBench ? false }:
let
craneLib = craneOverrideToolchain rust;
# suffixes get added via pnameSuffix
pname = "nickel-lang";
# Customize source filtering as Nickel uses non-standard-Rust files like `*.lalrpop`.
src = filterNickelSrc craneLib.filterCargoSources;
2023-01-14 18:03:32 +03:00
# set of cargo args common to all builds
cargoBuildExtraArgs = "--frozen --offline";
# Build *just* the cargo dependencies, so we can reuse all of that work (e.g. via cachix) when running in CI
cargoArtifactsDeps = craneLib.buildDepsOnly {
inherit pname src;
cargoExtraArgs = "${cargoBuildExtraArgs} --all-features";
# If we build all the packages at once, feature unification takes
# over and we get libraries with different sets of features than
# we would get building them separately. Meaning that when we
# later build them separately, it won't hit the cache. So instead,
# we need to build each package separately when we are collecting
# dependencies.
cargoBuildCommand = "cargoWorkspace build";
cargoTestCommand = "cargoWorkspace test";
cargoCheckCommand = "cargoWorkspace check";
preBuild = ''
cargoWorkspace() {
command=$(shift)
for packageDir in $(${pkgs.yq}/bin/tomlq -r '.workspace.members[]' Cargo.toml); do
(
cd $packageDir
pwd
cargoWithProfile $command "$@"
)
done
}
'';
# pyo3 needs a Python interpreter in the build environment
# https://pyo3.rs/v0.17.3/building_and_distribution#configuring-the-python-version
nativeBuildInputs = with pkgs; [ pkg-config python3 ];
buildInputs =
# SEE: https://github.com/NixOS/nix/issues/9107
let
disableChecksOnDarwin =
pkgList: builtins.map
(pkg: pkg.overrideAttrs (_: pkgs.lib.optionalAttrs (system == "x86_64-darwin") {
doCheck = false;
}))
pkgList;
in
disableChecksOnDarwin [
nix-input.packages.${system}.nix
# When updating to latest Nix, we'll need to use the following
# additional output. For now, we pinned `nix-input` to a
# previous tag, where the outputs are still grouped in the
# default package, so we leave them commented out.
# nix-input.packages.${system}.nix-store
# nix-input.packages.${system}.nix-expr
# nix-input.packages.${system}.nix-flake
# nix-input.packages.${system}.nix-cmd
]
++ [
pkgs.boost # implicit dependency of nix
];
# seems to be needed for consumer cargoArtifacts to be able to use
# zstd mode properly
installCargoArtifactsMode = "use-zstd";
2022-01-17 01:17:41 +03:00
};
2021-08-31 12:05:36 +03:00
env = {
NICKEL_NIX_BUILD_REV = dummyRev;
};
buildPackage = { pnameSuffix, cargoPackage ? "${pname}${pnameSuffix}", extraBuildArgs ? "", extraArgs ? { } }:
craneLib.buildPackage ({
2023-01-14 18:03:32 +03:00
inherit
pname
pnameSuffix
2023-01-14 18:03:32 +03:00
src
version
cargoArtifacts;
2023-01-14 18:03:32 +03:00
cargoExtraArgs = "${cargoBuildExtraArgs} ${extraBuildArgs} --package ${cargoPackage}";
} // extraArgs);
# In addition to external dependencies, we build the lalrpop file in a
# separate derivation because it's expensive to build but needs to be
# rebuilt infrequently.
cargoArtifacts = buildPackage {
pnameSuffix = "-core-lalrpop";
cargoPackage = "${pname}-core";
extraArgs = {
cargoArtifacts = cargoArtifactsDeps;
src = craneLib.mkDummySrc {
inherit src;
# after stubbing out, reset things back just enough for lalrpop build
extraDummyScript = ''
mkdir -p $out/core/src/parser
cp ${./core/build.rs} $out/core/build.rs
cp ${./core/src/parser/grammar.lalrpop} $out/core/src/parser/grammar.lalrpop
# package.build gets set to a dummy file. reset it to use local build.rs
# tomlq -i broken (https://github.com/kislyuk/yq/issues/130 not in nixpkgs yet)
${pkgs.yq}/bin/tomlq -t 'del(.package.build)' $out/core/Cargo.toml > tmp
mv tmp $out/core/Cargo.toml
'';
};
# the point of this is to cache lalrpop compilation
doInstallCargoArtifacts = true;
# we need the target/ directory to be writable
installCargoArtifactsMode = "use-zstd";
};
};
2023-01-14 18:03:32 +03:00
in
rec {
inherit cargoArtifacts cargoArtifactsDeps;
nickel-lang-core = buildPackage { pnameSuffix = "-core"; };
nickel-lang-cli = fixupGitRevision (buildPackage {
pnameSuffix = "-cli";
extraArgs = {
inherit env;
meta.mainProgram = "nickel";
};
});
nickel-lang-lsp = fixupGitRevision (buildPackage {
pnameSuffix = "-lsp";
extraArgs = {
inherit env;
meta.mainProgram = "nls";
};
});
# Static building isn't really possible on MacOS because the system call ABIs aren't stable.
nickel-static =
if pkgs.stdenv.hostPlatform.isMacOS
then nickel-lang-cli
else
# To build Nickel and its dependencies statically we use the musl
# libc and clang with libc++ to build C and C++ dependencies. We
# tried building with libstdc++ but without success.
fixupGitRevision
(buildPackage {
cargoPackage = "nickel-lang-cli";
pnameSuffix = "-static";
extraArgs = {
inherit env;
CARGO_BUILD_TARGET = pkgs.rust.toRustTarget pkgs.pkgsMusl.stdenv.hostPlatform;
# For some reason, the rust build doesn't pick up the paths
flake.lock: Update (#1733) * flake.lock: Update Flake lock file updates: • Updated input 'crane': 'github:ipetkov/crane/6849911446e18e520970cc6b7a691e64ee90d649' (2023-11-09) → 'github:ipetkov/crane/27025ab71bdca30e7ed0a16c88fd74c5970fc7f5' (2024-05-09) • Updated input 'flake-utils': 'github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384' (2023-09-12) → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11) • Updated input 'nix-input': 'github:nixos/nix/1d86bb4f70ee5c2d06810f21bf7cd057ed46712c' (2023-11-17) → 'github:nixos/nix/87ab3c0ea4e6f85e7b902050365bb75cf2836fbb' (2024-05-10) • Added input 'nix-input/flake-parts': 'github:hercules-ci/flake-parts/9126214d0a59633752a136528f5f3b9aa8565b7d' (2024-04-01) • Added input 'nix-input/flake-parts/nixpkgs-lib': follows 'nix-input/nixpkgs' • Added input 'nix-input/libgit2': 'github:libgit2/libgit2/45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5' (2023-10-18) • Removed input 'nix-input/lowdown-src' • Updated input 'nix-input/nixpkgs': 'github:NixOS/nixpkgs/9eb24edd6a0027fed010ccfe300a9734d029983c' (2023-11-01) → 'github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e' (2024-02-28) • Added input 'nix-input/pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/40e6053ecb65fcbf12863338a6dcefb3f55f1bf8' (2024-04-12) • Added input 'nix-input/pre-commit-hooks/flake-compat': follows 'nix-input' • Added input 'nix-input/pre-commit-hooks/flake-utils': 'github:numtide/flake-utils/5aed5285a952e0b949eb3ba02c12fa4fcfef535f' (2022-11-02) • Added input 'nix-input/pre-commit-hooks/gitignore': follows 'nix-input' • Added input 'nix-input/pre-commit-hooks/nixpkgs': follows 'nix-input/nixpkgs' • Added input 'nix-input/pre-commit-hooks/nixpkgs-stable': follows 'nix-input/nixpkgs' • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/bf744fe90419885eefced41b3e5ae442d732712d' (2023-11-14) → 'github:NixOS/nixpkgs/f1010e0469db743d14519a1efd37e23f8513d714' (2024-05-09) • Updated input 'pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/e558068cba67b23b4fbc5537173dbb43748a17e8' (2023-11-15) → 'github:cachix/pre-commit-hooks.nix/2849da033884f54822af194400f8dff435ada242' (2024-04-30) • Updated input 'pre-commit-hooks/flake-compat': 'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17) → 'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04) • Updated input 'pre-commit-hooks/gitignore': 'github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73' (2022-08-14) → 'github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394' (2024-02-28) • Updated input 'pre-commit-hooks/nixpkgs-stable': 'github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373' (2023-06-03) → 'github:NixOS/nixpkgs/614b4613980a522ba49f0d194531beddbb7220d3' (2024-03-17) • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/e3ebc177291f5de627d6dfbac817b4a661b15d1c' (2023-11-17) → 'github:oxalica/rust-overlay/8eb8671512cb0c72c748058506e50c54fb5d8e2b' (2024-05-11) • Updated input 'topiary': 'github:tweag/topiary/79b93527d9bd59533f9a79fe490567963193fafd' (2023-10-23) → 'github:tweag/topiary/82a94a9f57104b89d4316afaeeab271cc51f7698' (2024-04-09) • Updated input 'topiary/advisory-db': 'github:rustsec/advisory-db/5ceeefcbbabf4b510ef8ede121d6dc57d1a1f7f8' (2023-07-08) → 'github:rustsec/advisory-db/0bc9a77248be5cb5f2b51fe6aba8ba451d74c6bb' (2024-04-03) • Updated input 'topiary/crane': 'github:ipetkov/crane/8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e' (2023-07-07) → 'github:ipetkov/crane/06a9ff255c1681299a87191c2725d9d579f28b82' (2024-04-03) • Removed input 'topiary/crane/flake-compat' • Removed input 'topiary/crane/flake-utils' • Removed input 'topiary/crane/flake-utils/systems' • Removed input 'topiary/crane/rust-overlay' • Removed input 'topiary/crane/rust-overlay/flake-utils' • Removed input 'topiary/crane/rust-overlay/nixpkgs' • Updated input 'topiary/flake-utils': 'github:numtide/flake-utils/dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7' (2023-06-25) → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11) • Updated input 'topiary/nix-filter': 'github:numtide/nix-filter/d90c75e8319d0dd9be67d933d8eb9d0894ec9174' (2023-06-19) → 'github:numtide/nix-filter/3342559a24e85fc164b295c3444e8a139924675b' (2024-03-11) • Updated input 'topiary/rust-overlay': 'github:oxalica/rust-overlay/d7181bb2237035df17cab9295c95f987f5c527e6' (2023-07-11) → 'github:oxalica/rust-overlay/20e7895d1873cc64c14a9f024a8e04f5824bed28' (2024-04-04) • Updated input 'topiary/rust-overlay/flake-utils': 'github:numtide/flake-utils/cfacdce06f30d2b68473a46042957675eebb3401' (2023-04-11) → 'github:numtide/flake-utils/1ef2e671c3b0c19053962c07dbda38332dcebf26' (2024-01-15) • Updated input 'topiary/rust-overlay/nixpkgs': 'github:NixOS/nixpkgs/96ba1c52e54e74c3197f4d43026b3f3d92e83ff9' (2023-04-13) → 'github:NixOS/nixpkgs/90f456026d284c22b3e3497be980b2e47d0b28ac' (2024-01-29) * Update flake lock + fix consequences After a flake lock update, some errors needed fixes: - Updated Topiary input and formatted Nickel files - Merging manual: remove line number-dependent part of the error - Upgrade markdownlint config file to schema change - Fix flake.nix * Update flake.nix --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-18 11:13:26 +03:00
# to `libcxx`. So we specify them explicitly.
#
flake.lock: Update (#1733) * flake.lock: Update Flake lock file updates: • Updated input 'crane': 'github:ipetkov/crane/6849911446e18e520970cc6b7a691e64ee90d649' (2023-11-09) → 'github:ipetkov/crane/27025ab71bdca30e7ed0a16c88fd74c5970fc7f5' (2024-05-09) • Updated input 'flake-utils': 'github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384' (2023-09-12) → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11) • Updated input 'nix-input': 'github:nixos/nix/1d86bb4f70ee5c2d06810f21bf7cd057ed46712c' (2023-11-17) → 'github:nixos/nix/87ab3c0ea4e6f85e7b902050365bb75cf2836fbb' (2024-05-10) • Added input 'nix-input/flake-parts': 'github:hercules-ci/flake-parts/9126214d0a59633752a136528f5f3b9aa8565b7d' (2024-04-01) • Added input 'nix-input/flake-parts/nixpkgs-lib': follows 'nix-input/nixpkgs' • Added input 'nix-input/libgit2': 'github:libgit2/libgit2/45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5' (2023-10-18) • Removed input 'nix-input/lowdown-src' • Updated input 'nix-input/nixpkgs': 'github:NixOS/nixpkgs/9eb24edd6a0027fed010ccfe300a9734d029983c' (2023-11-01) → 'github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e' (2024-02-28) • Added input 'nix-input/pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/40e6053ecb65fcbf12863338a6dcefb3f55f1bf8' (2024-04-12) • Added input 'nix-input/pre-commit-hooks/flake-compat': follows 'nix-input' • Added input 'nix-input/pre-commit-hooks/flake-utils': 'github:numtide/flake-utils/5aed5285a952e0b949eb3ba02c12fa4fcfef535f' (2022-11-02) • Added input 'nix-input/pre-commit-hooks/gitignore': follows 'nix-input' • Added input 'nix-input/pre-commit-hooks/nixpkgs': follows 'nix-input/nixpkgs' • Added input 'nix-input/pre-commit-hooks/nixpkgs-stable': follows 'nix-input/nixpkgs' • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/bf744fe90419885eefced41b3e5ae442d732712d' (2023-11-14) → 'github:NixOS/nixpkgs/f1010e0469db743d14519a1efd37e23f8513d714' (2024-05-09) • Updated input 'pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/e558068cba67b23b4fbc5537173dbb43748a17e8' (2023-11-15) → 'github:cachix/pre-commit-hooks.nix/2849da033884f54822af194400f8dff435ada242' (2024-04-30) • Updated input 'pre-commit-hooks/flake-compat': 'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17) → 'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04) • Updated input 'pre-commit-hooks/gitignore': 'github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73' (2022-08-14) → 'github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394' (2024-02-28) • Updated input 'pre-commit-hooks/nixpkgs-stable': 'github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373' (2023-06-03) → 'github:NixOS/nixpkgs/614b4613980a522ba49f0d194531beddbb7220d3' (2024-03-17) • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/e3ebc177291f5de627d6dfbac817b4a661b15d1c' (2023-11-17) → 'github:oxalica/rust-overlay/8eb8671512cb0c72c748058506e50c54fb5d8e2b' (2024-05-11) • Updated input 'topiary': 'github:tweag/topiary/79b93527d9bd59533f9a79fe490567963193fafd' (2023-10-23) → 'github:tweag/topiary/82a94a9f57104b89d4316afaeeab271cc51f7698' (2024-04-09) • Updated input 'topiary/advisory-db': 'github:rustsec/advisory-db/5ceeefcbbabf4b510ef8ede121d6dc57d1a1f7f8' (2023-07-08) → 'github:rustsec/advisory-db/0bc9a77248be5cb5f2b51fe6aba8ba451d74c6bb' (2024-04-03) • Updated input 'topiary/crane': 'github:ipetkov/crane/8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e' (2023-07-07) → 'github:ipetkov/crane/06a9ff255c1681299a87191c2725d9d579f28b82' (2024-04-03) • Removed input 'topiary/crane/flake-compat' • Removed input 'topiary/crane/flake-utils' • Removed input 'topiary/crane/flake-utils/systems' • Removed input 'topiary/crane/rust-overlay' • Removed input 'topiary/crane/rust-overlay/flake-utils' • Removed input 'topiary/crane/rust-overlay/nixpkgs' • Updated input 'topiary/flake-utils': 'github:numtide/flake-utils/dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7' (2023-06-25) → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11) • Updated input 'topiary/nix-filter': 'github:numtide/nix-filter/d90c75e8319d0dd9be67d933d8eb9d0894ec9174' (2023-06-19) → 'github:numtide/nix-filter/3342559a24e85fc164b295c3444e8a139924675b' (2024-03-11) • Updated input 'topiary/rust-overlay': 'github:oxalica/rust-overlay/d7181bb2237035df17cab9295c95f987f5c527e6' (2023-07-11) → 'github:oxalica/rust-overlay/20e7895d1873cc64c14a9f024a8e04f5824bed28' (2024-04-04) • Updated input 'topiary/rust-overlay/flake-utils': 'github:numtide/flake-utils/cfacdce06f30d2b68473a46042957675eebb3401' (2023-04-11) → 'github:numtide/flake-utils/1ef2e671c3b0c19053962c07dbda38332dcebf26' (2024-01-15) • Updated input 'topiary/rust-overlay/nixpkgs': 'github:NixOS/nixpkgs/96ba1c52e54e74c3197f4d43026b3f3d92e83ff9' (2023-04-13) → 'github:NixOS/nixpkgs/90f456026d284c22b3e3497be980b2e47d0b28ac' (2024-01-29) * Update flake lock + fix consequences After a flake lock update, some errors needed fixes: - Updated Topiary input and formatted Nickel files - Merging manual: remove line number-dependent part of the error - Upgrade markdownlint config file to schema change - Fix flake.nix * Update flake.nix --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-18 11:13:26 +03:00
# We also explicitly add `libc` because of
# https://github.com/rust-lang/rust/issues/89626.
RUSTFLAGS = "-L${pkgs.pkgsMusl.llvmPackages.libcxx}/lib -lstatic=c++abi -C link-arg=-lc";
# Explain to `cc-rs` that it should use the `libcxx` C++
# standard library, and a static version of it, when building
# C++ libraries. The `cc-rs` crate is typically used in
# upstream build.rs scripts.
CXXSTDLIB = "static=c++";
stdenv = pkgs.pkgsMusl.libcxxStdenv;
doCheck = false;
meta.mainProgram = "nickel";
};
});
2023-02-13 11:59:06 +03:00
benchmarks = craneLib.mkCargoDerivation {
inherit pname src version cargoArtifacts env;
2023-02-13 11:59:06 +03:00
pnameSuffix = "-bench";
2023-02-13 11:59:06 +03:00
buildPhaseCargoCommand = ''
cargo bench -p nickel-lang-core ${pkgs.lib.optionalString noRunBench "--no-run"}
'';
2023-02-13 11:59:06 +03:00
doInstallCargoArtifacts = false;
};
# Check that documentation builds without warnings or errors
checkRustDoc = craneLib.cargoDoc {
inherit pname src version cargoArtifacts env;
inherit (cargoArtifactsDeps) nativeBuildInputs buildInputs;
RUSTDOCFLAGS = "-D warnings";
cargoExtraArgs = "${cargoBuildExtraArgs} --workspace --all-features";
doInstallCargoArtifacts = false;
};
rustfmt = craneLib.cargoFmt {
# Notice that unlike other Crane derivations, we do not pass `cargoArtifacts` to `cargoFmt`, because it does not need access to dependencies to format the code.
inherit pname src;
2022-01-17 01:17:41 +03:00
cargoExtraArgs = "--all";
2022-01-17 01:17:41 +03:00
# `-- --check` is automatically prepended by Crane
rustFmtExtraArgs = "--color always";
};
2022-01-17 01:17:41 +03:00
clippy = craneLib.cargoClippy {
inherit pname src cargoArtifacts env;
inherit (cargoArtifactsDeps) nativeBuildInputs buildInputs;
2023-01-14 18:03:32 +03:00
cargoExtraArgs = cargoBuildExtraArgs;
cargoClippyExtraArgs = "--all-features --all-targets --workspace -- --deny warnings --allow clippy::new-without-default --allow clippy::match_like_matches_macro";
};
};
2021-08-31 12:05:36 +03:00
makeDevShell = { rust }: pkgs.mkShell {
# Get deps needed to build. Get them from cargoArtifactsDeps so we build
# the minimal amount possible to get there. It is a waste of time to
# build the cargoArtifacts, because cargo won't use them anyways.
inputsFrom = [ (mkCraneArtifacts { inherit rust; }).cargoArtifactsDeps ];
buildInputs = [
pkgs.rust-analyzer
pkgs.cargo-insta
pkgs.nixpkgs-fmt
pkgs.nodejs
pkgs.yarn
pkgs.yarn2nix
pkgs.nodePackages.markdownlint-cli
2023-01-08 21:45:01 +03:00
pkgs.python3
];
shellHook = (pre-commit-builder { inherit rust; checkFormat = true; }).shellHook + ''
echo "=== Nickel development shell ==="
echo "Info: Git hooks can be installed using \`pre-commit install\`"
'';
RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
};
# Profile is passed to `wasm-pack`, and is either "dev" (with debug
# symbols and no optimization), "release" (with optimization and without
# debug symbols) or "profiling". Right now only dev and release are used:
# - release for the production build
# - dev for checks, as the code isn't optimized, and WASM optimization
# takes time
buildNickelWasm =
{ rust ? mkRust { targets = [ "wasm32-unknown-unknown" ]; }
, profile ? "release"
}:
let
# Build the various Crane artifacts (dependencies, packages, rustfmt, clippy) for a given Rust toolchain
craneLib = craneOverrideToolchain rust;
2021-09-27 18:02:07 +03:00
# suffixes get added via pnameSuffix
pname = "nickel-lang-wasm";
# Customize source filtering as Nickel uses non-standard-Rust files like `*.lalrpop`.
src = filterNickelSrc craneLib.filterCargoSources;
2021-09-27 18:02:07 +03:00
cargoExtraArgs = "-p nickel-wasm-repl --target wasm32-unknown-unknown --frozen --offline";
2022-12-25 14:17:39 +03:00
# * --mode no-install prevents wasm-pack from trying to download and
# vendor tools like wasm-bindgen, wasm-opt, etc. but use the one
# provided by Nix
# * --no-default-features disable some default features of Nickel that
2022-12-25 14:17:39 +03:00
# aren't useful for the WASM REPL (and possibly incompatible with
# WASM build)
wasmPackExtraArgs = "--${profile} --mode no-install -- --no-default-features --frozen --offline";
# Build *just* the cargo dependencies, so we can reuse all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly {
inherit pname src cargoExtraArgs;
doCheck = false;
};
in
craneLib.mkCargoDerivation {
inherit pname cargoArtifacts src;
buildPhaseCargoCommand = ''
WASM_PACK_CACHE=.wasm-pack-cache wasm-pack build wasm-repl ${wasmPackExtraArgs}
'';
2021-12-10 14:07:47 +03:00
# nickel-lang.org expects an interface `nickel-repl.wasm`, hence the
# `ln`
installPhaseCommand = ''
mkdir -p $out
cp -r wasm-repl/pkg $out/nickel-repl
ln -s $out/nickel-repl/nickel_wasm_repl_bg.wasm $out/nickel-repl/nickel_repl.wasm
'';
nativeBuildInputs = [
rust
pkgs.wasm-pack
wasm-bindgen-cli
pkgs.binaryen
# Used to include the git revision in the Nickel binary, for `--version`
pkgs.git
] ++ systemSpecificPkgs;
};
2021-09-27 18:02:07 +03:00
buildDocker = nickel: pkgs.dockerTools.buildLayeredImage {
name = "nickel";
tag = version;
contents = [
nickel
];
config = {
Entrypoint = pkgs.lib.getExe nickel;
# Labels that are recognized by GHCR
# See https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#labelling-container-images
Labels = {
"org.opencontainers.image.source" = "https://github.com/tweag/nickel";
"org.opencontainers.image.description" = "Nickel: better configuration for less";
"org.opencontainers.image.licenses" = "MIT";
};
};
};
2021-09-27 18:02:07 +03:00
# Build the Nickel VSCode extension
vscodeExtension = pkgs.mkYarnPackage {
pname = "vscode-nickel";
src = pkgs.lib.cleanSource ./lsp/vscode-extension;
buildPhase = ''
# yarn tries to create a .yarn file in $HOME. There's probably a
# better way to fix this but setting HOME to TMPDIR works for now.
export HOME="$TMPDIR"
cd deps/vscode-nickel
yarn --offline compile
yarn --offline vsce package --yarn -o $pname.vsix
'';
installPhase = ''
mkdir $out
mv $pname.vsix $out
'';
distPhase = "true";
};
# Copy the markdown user manual to $out.
userManual = pkgs.stdenv.mkDerivation {
name = "nickel-user-manual-${version}";
src = ./doc/manual;
installPhase = ''
mkdir -p $out
2022-06-21 20:32:33 +03:00
cp -r ./ $out
'';
};
# Generate the stdlib documentation from `nickel doc` as `format`.
stdlibDoc = format:
let
extension =
{
"markdown" = "md";
}."${format}" or format;
in
pkgs.stdenv.mkDerivation {
name = "nickel-stdlib-doc-${format}-${version}";
src = ./core/stdlib;
installPhase = ''
mkdir -p $out
for file in $(ls *.ncl | grep -v 'internals.ncl')
do
module=$(basename $file .ncl)
${pkgs.lib.getExe self.packages."${system}".default} doc --format "${format}" "$module.ncl" \
--output "$out/$module.${extension}"
done
'';
};
infraShell = nickel:
let
terraform = pkgs.terraform.withPlugins (p: with p; [
archive
aws
github
]);
ec2-region = "eu-north-1";
ec2-ami = (import "${nixpkgs}/nixos/modules/virtualisation/amazon-ec2-amis.nix").latest.${ec2-region}.aarch64-linux.hvm-ebs;
run-terraform = pkgs.writeShellScriptBin "run-terraform" ''
set -e
${pkgs.lib.getExe nickel} export --output main.tf.json <<EOF
((import "main.ncl") & {
region = "${ec2-region}",
nixos-ami = "${ec2-ami}",
}).config
EOF
${terraform}/bin/terraform "$@"
'';
update-infra = pkgs.writeShellScriptBin "update-infra" ''
set -e
${run-terraform}/bin/run-terraform init
GITHUB_TOKEN="$(${pkgs.gh}/bin/gh auth token)" ${run-terraform}/bin/run-terraform apply
'';
in
pkgs.mkShell {
buildInputs = [ terraform run-terraform update-infra ];
};
in
rec {
packages = {
inherit (mkCraneArtifacts { })
nickel-lang-core
nickel-lang-cli
benchmarks
nickel-lang-lsp
cargoArtifacts;
default = pkgs.buildEnv {
name = "nickel";
paths = [ packages.nickel-lang-cli packages.nickel-lang-lsp ];
meta.mainProgram = "nickel";
};
nickelWasm = buildNickelWasm { };
dockerImage = buildDocker packages.nickel-lang-cli; # TODO: docker image should be a passthru
inherit vscodeExtension;
inherit userManual;
stdlibMarkdown = stdlibDoc "markdown";
stdlibJson = stdlibDoc "json";
} // pkgs.lib.optionalAttrs (!pkgs.stdenv.hostPlatform.isDarwin) {
inherit (mkCraneArtifacts { }) nickel-static;
# Use the statically linked binary for the docker image if we're not on MacOS.
dockerImage = buildDocker packages.nickel-static;
};
2021-09-27 18:02:07 +03:00
2022-12-23 12:57:27 +03:00
apps = {
default = {
type = "app";
program = pkgs.lib.getExe packages.nickel-lang-cli;
2022-12-23 12:57:27 +03:00
};
};
devShells = (forEachRustChannel (channel: {
name = channel;
value = makeDevShell { rust = mkRust { inherit channel; rustProfile = "default"; targets = [ "wasm32-unknown-unknown" ]; }; };
})) // {
default = devShells.stable;
infra = infraShell packages.nickel-lang-cli;
};
checks = {
inherit (mkCraneArtifacts { noRunBench = true; })
benchmarks
clippy
checkRustDoc
nickel-lang-lsp
nickel-lang-cli
nickel-lang-core
rustfmt;
# There's a tradeoff here: "release" build is in theory longer than
# "dev", but it hits the cache on dependencies so in practice it is
# shorter. Another option would be to compile a dev dependencies version
# of cargoArtifacts. But that almost doubles the cache space.
nickelWasm = buildNickelWasm { profile = "release"; };
2022-11-21 14:56:42 +03:00
inherit vscodeExtension;
pre-commit = pre-commit-builder { };
};
}
2022-01-17 01:17:41 +03:00
);
2020-07-03 15:22:21 +03:00
}