-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test nixpkgs_package is invalidated on a change in Nix files
This test runs Bazel in the Bazel sandbox to ensure some dependencies are well tracked at the workspace level. So, we create a workspace, build it, then change the content of some workspace files and check if a rebuild of this workspace take into account these changes. This is a regression test for the issue #113.
- Loading branch information
Showing
10 changed files
with
95 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
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
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
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 @@ | ||
filegroup(name = "srcs", srcs = glob(["**"]), visibility = ["//visibility:public"]) |
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,6 @@ | ||
{ ... }: | ||
let | ||
# To not predict from where the nix command is executed, we replace | ||
# with sed the import path with an absolute path. | ||
pkgs = import REPLACE-WITH-ABSPATH { }; | ||
in import ./hello.nix { inherit pkgs; } |
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,5 @@ | ||
{ pkgs }: | ||
|
||
{ | ||
hello = pkgs.writeShellScriptBin "hello" "echo hello-1"; | ||
} |
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,5 @@ | ||
{ pkgs }: | ||
|
||
{ | ||
hello = pkgs.writeShellScriptBin "hello" "echo hello-2"; | ||
} |
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,6 @@ | ||
genrule( | ||
name = "hello-output", | ||
outs = ["hello-output.txt"], | ||
cmd = "$(execpath @hello//:bin) > \"$@\"", | ||
tools = [ "@hello//:bin" ] | ||
) |
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,19 @@ | ||
workspace(name = "io_tweag_rules_nixpkgs") | ||
|
||
load( | ||
"//nixpkgs:nixpkgs.bzl", | ||
"nixpkgs_local_repository", | ||
"nixpkgs_package", | ||
) | ||
|
||
nixpkgs_local_repository( | ||
name = "nixpkgs", | ||
nix_file = "//:default.nix", | ||
nix_file_deps = [ "//:hello.nix" ], | ||
) | ||
|
||
nixpkgs_package( | ||
name = "hello", | ||
attribute_path = "hello", | ||
repository = "@nixpkgs", | ||
) |
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,36 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
ln -s tests/invalid_nixpkgs_package/workspace.bazel WORKSPACE | ||
ln -s tests/invalid_nixpkgs_package/nested-build.bazel BUILD | ||
ln -s tests/invalid_nixpkgs_package/default.nix default.nix | ||
|
||
# We need to provide a nixpkgs to create an output store path which is | ||
# a folder (because nixpkgs_package requires the output store path to | ||
# be a directory). | ||
# | ||
# It would be much more simple to use the mkdir bash builtin because | ||
# we could create the output store path without having to import | ||
# nixpkgs. However, the mkdir bash builtin is segfaulting:/ | ||
sed "s;REPLACE-WITH-ABSPATH;$(pwd)/external/remote_nixpkgs;" -i default.nix | ||
|
||
# First we build the :hello-output target with the content of | ||
# hello-1.nix in hello.nix. Building this deriviation creates a file | ||
# containing "hello-1". | ||
cp tests/invalid_nixpkgs_package/hello-1.nix hello.nix | ||
bazel build //:hello-output | ||
if [[ $(cat bazel-bin/hello-output.txt) != "hello-1" ]]; then | ||
exit 1 | ||
fi | ||
|
||
# Then, we override the content of the hello.nix file to ensure Bazel | ||
# rebuilds the :hello-output target when a Nix files is modified. The | ||
# hello.nix file now builds a derivation creating a file with content | ||
# "hello-2". | ||
cp tests/invalid_nixpkgs_package/hello-2.nix hello.nix | ||
bazel build //:hello-output | ||
content=$(cat bazel-bin/hello-output.txt) | ||
if [[ $content != "hello-2" ]]; then | ||
echo 'error: the content of bazel-bin/hello-output.txt must be hello-2 instead of' "$content" | ||
exit 1 | ||
fi |