diff --git a/flake.nix b/flake.nix index d4ea761..c1e58af 100644 --- a/flake.nix +++ b/flake.nix @@ -153,13 +153,15 @@ }; packages = { - inherit (pkgs) nix-buildkite; + inherit (pkgs) nix-buildkite nix-buildkite-unwrapped; } // (pkgs.lib.optionalAttrs (system == "x86_64-linux") { inherit (pkgs) nix-buildkite-docker-image; }) // haskellNixFlake.packages; - checks = haskellNixFlake.checks; + checks = { + inherit (pkgs) nix-buildkite-tests; + } // haskellNixFlake.checks; apps = let @@ -246,6 +248,7 @@ nodejs-18_x nixpkgs-fmt + goldplate ]); shellHook = '' @@ -297,12 +300,41 @@ }; }; + nix-buildkite-unwrapped = nixBuildkiteFlake.packages."nix-buildkite-plugin:exe:nix-buildkite"; + + nix-buildkite = final.stdenv.mkDerivation { + name = "nix-buildkite"; + src = ./.; + nativeBuildInputs = [ + final.makeWrapper + ]; + installPhase = '' + mkdir -p $out/bin + makeWrapper ${nix-buildkite-unwrapped}/bin/nix-buildkite $out/bin/nix-buildkite \ + --suffix PATH : ${final.lib.makeBinPath [final.nix]} + ''; + + meta = with final.lib; { + description = "Create Buildkite pipelines from Nix attributes."; + homepage = "https://github.com/hackworthltd/nix-buildkite-plugin"; + license = licenses.bsd3; + platforms = platforms.all; + mainProgram = "nix-buildkite"; + }; + }; + + nix-buildkite-tests = final.callPackage ./nix/pkgs/nix-buildkite-tests { + src = ./tests; + }; in { + inherit nix-buildkite-unwrapped; + inherit nix-buildkite; inherit nix-buildkite-plugin; - - nix-buildkite = nixBuildkiteFlake.packages."nix-buildkite-plugin:exe:nix-buildkite"; inherit nix-buildkite-docker-image; + + inherit (final.haskellPackages) goldplate; + inherit nix-buildkite-tests; } ); diff --git a/nix/pkgs/nix-buildkite-tests/default.nix b/nix/pkgs/nix-buildkite-tests/default.nix new file mode 100644 index 0000000..af08c8c --- /dev/null +++ b/nix/pkgs/nix-buildkite-tests/default.nix @@ -0,0 +1,18 @@ +{ goldplate +, nix-buildkite +, runCommand +, src +}: +runCommand "nix-buildkite-tests" +{ + inherit src; + nativeBuildInputs = [ + goldplate + nix-buildkite + ]; +} '' + set -e + cd $src + goldplate -j2 --pretty-diff . + touch $out +'' diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..d145ead --- /dev/null +++ b/tests/default.nix @@ -0,0 +1 @@ +(import ./flake-compat.nix).defaultNix diff --git a/tests/flake-compat.nix b/tests/flake-compat.nix new file mode 100644 index 0000000..dab420b --- /dev/null +++ b/tests/flake-compat.nix @@ -0,0 +1,9 @@ +let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + inherit (lock.nodes.flake-compat.locked) owner repo rev narHash; + flake-compat = builtins.fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; +in +import flake-compat { src = ./.; } diff --git a/tests/flake.lock b/tests/flake.lock new file mode 100644 index 0000000..9a4c0c4 --- /dev/null +++ b/tests/flake.lock @@ -0,0 +1,359 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "ref": "v1.0.1", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1696343447, + "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "type": "github" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib_2" + }, + "locked": { + "lastModified": 1696343447, + "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "hacknix", + "pre-commit-hooks-nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore-nix": { + "flake": false, + "locked": { + "lastModified": 1694102001, + "narHash": "sha256-vky6VPK1n1od6vXbqzOXnekrQpTL4hbPAwUhT5J9c9E=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "9e21c80adf67ebcb077d75bd5e7d724d21eeafd6", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "hacknix": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-parts": "flake-parts_2", + "gitignore-nix": "gitignore-nix", + "nix-darwin": "nix-darwin", + "nixos-generators": "nixos-generators", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks-nix": "pre-commit-hooks-nix" + }, + "locked": { + "lastModified": 1696633938, + "narHash": "sha256-1eQH0S3G/eI3PTqxCw3hmLh6eOS0wQfBcsYp410Bvjc=", + "owner": "hackworthltd", + "repo": "hacknix", + "rev": "d4ac93da22f1d83e2a264b63c6f5d615e21e46b7", + "type": "github" + }, + "original": { + "owner": "hackworthltd", + "repo": "hacknix", + "rev": "d4ac93da22f1d83e2a264b63c6f5d615e21e46b7", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1696360011, + "narHash": "sha256-HpPv27qMuPou4acXcZ8Klm7Zt0Elv9dgDvSJaomWb9Y=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "8b6ea26d5d2e8359d06278364f41fbc4b903b28a", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixlib": { + "locked": { + "lastModified": 1693701915, + "narHash": "sha256-waHPLdDYUOHSEtMKKabcKIMhlUOHPOOPQ9UyFeEoovs=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "f5af57d3ef9947a70ac86e42695231ac1ad00c25", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixos-generators": { + "inputs": { + "nixlib": "nixlib", + "nixpkgs": [ + "hacknix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1696058303, + "narHash": "sha256-eNqKWpF5zG0SrgbbtljFOrRgFgRzCc4++TMFADBMLnc=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "150f38bd1e09e20987feacb1b0d5991357532fb5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-generators", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1687274257, + "narHash": "sha256-TutzPriQcZ8FghDhEolnHcYU2oHIG5XWF+/SUBNnAOE=", + "path": "/nix/store/22qgs3skscd9bmrxv9xv4q5d4wwm5ppx-source", + "rev": "2c9ecd1f0400076a4d6b2193ad468ff0a7e7fdc5", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib_2": { + "locked": { + "dir": "lib", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1685566663, + "narHash": "sha256-btHN1czJ6rzteeCuE/PNrdssqYD2nIA4w48miQAFloM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4ecab3273592f27479a583fb6d975d4aba3486fe", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks-nix": { + "inputs": { + "flake-compat": "flake-compat_3", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "hacknix", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1696516544, + "narHash": "sha256-8rKE8Je6twTNFRTGF63P9mE3lZIq917RAicdc4XJO80=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "66c352d33e0907239e4a69416334f64af2c685cc", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "hacknix": "hacknix", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/tests/flake.nix b/tests/flake.nix new file mode 100644 index 0000000..b3b6473 --- /dev/null +++ b/tests/flake.nix @@ -0,0 +1,53 @@ +{ + description = "A test flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/23.05"; + + flake-parts.url = "github:hercules-ci/flake-parts/c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4"; + flake-parts.inputs.nixpkgs.follows = "nixpkgs"; + + # We use this for some convenience functions only. + hacknix.url = "github:hackworthltd/hacknix/d4ac93da22f1d83e2a264b63c6f5d615e21e46b7"; + hacknix.inputs.nixpkgs.follows = "nixpkgs"; + + flake-compat.url = "github:edolstra/flake-compat/v1.0.1"; + flake-compat.flake = false; + }; + + outputs = inputs@ { flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; + + perSystem = { config, pkgs, system, ... }: + let + hello = pkgs.callPackage ./nix/pkgs/hello { }; + syntheticDeps = pkgs.symlinkJoin { + name = "synthetic-deps"; + paths = [ hello ]; + }; + in + { + packages = { + inherit hello syntheticDeps; + } + // (pkgs.lib.optionalAttrs (system == "x86_64-linux" || system == "aarch64-linux")) { + test-docker-image = pkgs.dockerTools.buildLayeredImage { + name = "test-docker-image"; + tag = "v1.0"; + contents = ([ + syntheticDeps + ]); + }; + }; + }; + + flake = { + hydraJobs = { + inherit (inputs.self) checks; + inherit (inputs.self) packages; + }; + ciJobs = inputs.hacknix.lib.flakes.recurseIntoHydraJobs inputs.self.hydraJobs; + }; + }; +} + diff --git a/tests/jobs-agent-tags.goldplate b/tests/jobs-agent-tags.goldplate new file mode 100644 index 0000000..d1faefa --- /dev/null +++ b/tests/jobs-agent-tags.goldplate @@ -0,0 +1,12 @@ +{ + "command": "nix-buildkite", + "environment": { + "AGENT_TAGS": "queue=foobar,os=linux" + }, + "arguments": ["jobs.nix"], + "asserts": [ + {"exit_code": 0}, + {"stdout": "${GOLDPLATE_NAME}.stdout"} + ] +} + diff --git a/tests/jobs-agent-tags.stdout b/tests/jobs-agent-tags.stdout new file mode 100644 index 0000000..e48ac61 --- /dev/null +++ b/tests/jobs-agent-tags.stdout @@ -0,0 +1 @@ +{"agents":{"os":"linux","queue":"foobar"},"steps":[{"command":"nix-store -r /nix/store/kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2.12.1.drv","depends_on":[],"key":"kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2_12_1","label":":darwin: aarch64-darwin:hello-2.12.1"},{"command":"nix-store -r /nix/store/zna38ypg3k9ahc0hdk1ykk5gxdxwrh30-synthetic-deps.drv","depends_on":["kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2_12_1"],"key":"zna38ypg3k9ahc0hdk1ykk5gxdxwrh30-synthetic-deps","label":":darwin: aarch64-darwin:synthetic-deps"},{"command":"nix-store -r /nix/store/94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2.12.1.drv","depends_on":[],"key":"94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1","label":":linux: aarch64-linux:hello-2.12.1"},{"command":"nix-store -r /nix/store/a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps.drv","depends_on":["94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1"],"key":"a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps","label":":linux: aarch64-linux:synthetic-deps"},{"command":"nix-store -r /nix/store/4xngvxjdd7fa3bqxzd6nwv6fh1hb4ry3-test-docker-image.tar.gz.drv","depends_on":["a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps","94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1"],"key":"4xngvxjdd7fa3bqxzd6nwv6fh1hb4ry3-test-docker-image_tar_gz","label":":linux: aarch64-linux:test-docker-image.tar.gz"},{"command":"nix-store -r /nix/store/zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2.12.1.drv","depends_on":[],"key":"zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1","label":":linux: x86_64-linux:hello-2.12.1"},{"command":"nix-store -r /nix/store/6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps.drv","depends_on":["zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1"],"key":"6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps","label":":linux: x86_64-linux:synthetic-deps"},{"command":"nix-store -r /nix/store/8kc33r36pvs3x6zm234drfzfpcm2pm4p-test-docker-image.tar.gz.drv","depends_on":["6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps","zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1"],"key":"8kc33r36pvs3x6zm234drfzfpcm2pm4p-test-docker-image_tar_gz","label":":linux: x86_64-linux:test-docker-image.tar.gz"}]} \ No newline at end of file diff --git a/tests/jobs-post-build-hook.goldplate b/tests/jobs-post-build-hook.goldplate new file mode 100644 index 0000000..ac1415b --- /dev/null +++ b/tests/jobs-post-build-hook.goldplate @@ -0,0 +1,12 @@ +{ + "command": "nix-buildkite", + "environment": { + "POST_BUILD_HOOK": "/nix/store/post-build-hook.sh" + }, + "arguments": ["jobs.nix"], + "asserts": [ + {"exit_code": 0}, + {"stdout": "${GOLDPLATE_NAME}.stdout"} + ] +} + diff --git a/tests/jobs-post-build-hook.stdout b/tests/jobs-post-build-hook.stdout new file mode 100644 index 0000000..b1e9adf --- /dev/null +++ b/tests/jobs-post-build-hook.stdout @@ -0,0 +1 @@ +{"agents":{},"steps":[{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2.12.1.drv","depends_on":[],"key":"kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2_12_1","label":":darwin: aarch64-darwin:hello-2.12.1"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/zna38ypg3k9ahc0hdk1ykk5gxdxwrh30-synthetic-deps.drv","depends_on":["kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2_12_1"],"key":"zna38ypg3k9ahc0hdk1ykk5gxdxwrh30-synthetic-deps","label":":darwin: aarch64-darwin:synthetic-deps"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2.12.1.drv","depends_on":[],"key":"94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1","label":":linux: aarch64-linux:hello-2.12.1"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps.drv","depends_on":["94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1"],"key":"a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps","label":":linux: aarch64-linux:synthetic-deps"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/4xngvxjdd7fa3bqxzd6nwv6fh1hb4ry3-test-docker-image.tar.gz.drv","depends_on":["a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps","94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1"],"key":"4xngvxjdd7fa3bqxzd6nwv6fh1hb4ry3-test-docker-image_tar_gz","label":":linux: aarch64-linux:test-docker-image.tar.gz"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2.12.1.drv","depends_on":[],"key":"zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1","label":":linux: x86_64-linux:hello-2.12.1"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps.drv","depends_on":["zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1"],"key":"6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps","label":":linux: x86_64-linux:synthetic-deps"},{"command":"nix-store --post-build-hook /nix/store/post-build-hook.sh -r /nix/store/8kc33r36pvs3x6zm234drfzfpcm2pm4p-test-docker-image.tar.gz.drv","depends_on":["6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps","zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1"],"key":"8kc33r36pvs3x6zm234drfzfpcm2pm4p-test-docker-image_tar_gz","label":":linux: x86_64-linux:test-docker-image.tar.gz"}]} \ No newline at end of file diff --git a/tests/jobs.goldplate b/tests/jobs.goldplate new file mode 100644 index 0000000..217d870 --- /dev/null +++ b/tests/jobs.goldplate @@ -0,0 +1,9 @@ +{ + "command": "nix-buildkite", + "arguments": ["jobs.nix"], + "asserts": [ + {"exit_code": 0}, + {"stdout": "${GOLDPLATE_NAME}.stdout"} + ] +} + diff --git a/tests/jobs.nix b/tests/jobs.nix new file mode 100644 index 0000000..a0187fa --- /dev/null +++ b/tests/jobs.nix @@ -0,0 +1,2 @@ +(import ./flake-compat.nix).defaultNix.ciJobs + diff --git a/tests/jobs.stdout b/tests/jobs.stdout new file mode 100644 index 0000000..36ad73d --- /dev/null +++ b/tests/jobs.stdout @@ -0,0 +1 @@ +{"agents":{},"steps":[{"command":"nix-store -r /nix/store/kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2.12.1.drv","depends_on":[],"key":"kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2_12_1","label":":darwin: aarch64-darwin:hello-2.12.1"},{"command":"nix-store -r /nix/store/zna38ypg3k9ahc0hdk1ykk5gxdxwrh30-synthetic-deps.drv","depends_on":["kb5m9n3npjrwb8a8my9k9pqz7qwq1l0r-hello-2_12_1"],"key":"zna38ypg3k9ahc0hdk1ykk5gxdxwrh30-synthetic-deps","label":":darwin: aarch64-darwin:synthetic-deps"},{"command":"nix-store -r /nix/store/94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2.12.1.drv","depends_on":[],"key":"94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1","label":":linux: aarch64-linux:hello-2.12.1"},{"command":"nix-store -r /nix/store/a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps.drv","depends_on":["94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1"],"key":"a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps","label":":linux: aarch64-linux:synthetic-deps"},{"command":"nix-store -r /nix/store/4xngvxjdd7fa3bqxzd6nwv6fh1hb4ry3-test-docker-image.tar.gz.drv","depends_on":["a691rhfnwbqx2q3jpj0hkbf8c47pjw4j-synthetic-deps","94mjmvv6cv9z6m8hil8r0s3b33glq23j-hello-2_12_1"],"key":"4xngvxjdd7fa3bqxzd6nwv6fh1hb4ry3-test-docker-image_tar_gz","label":":linux: aarch64-linux:test-docker-image.tar.gz"},{"command":"nix-store -r /nix/store/zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2.12.1.drv","depends_on":[],"key":"zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1","label":":linux: x86_64-linux:hello-2.12.1"},{"command":"nix-store -r /nix/store/6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps.drv","depends_on":["zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1"],"key":"6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps","label":":linux: x86_64-linux:synthetic-deps"},{"command":"nix-store -r /nix/store/8kc33r36pvs3x6zm234drfzfpcm2pm4p-test-docker-image.tar.gz.drv","depends_on":["6fh3frp0jqdnn4vi1ifdhxwzzx1igivi-synthetic-deps","zjh5kllay6a2ws4w46267i97lrnyya9l-hello-2_12_1"],"key":"8kc33r36pvs3x6zm234drfzfpcm2pm4p-test-docker-image_tar_gz","label":":linux: x86_64-linux:test-docker-image.tar.gz"}]} \ No newline at end of file diff --git a/tests/nix/pkgs/hello/default.nix b/tests/nix/pkgs/hello/default.nix new file mode 100644 index 0000000..f1b056f --- /dev/null +++ b/tests/nix/pkgs/hello/default.nix @@ -0,0 +1,46 @@ +{ callPackage +, lib +, stdenv +, fetchurl +, nixos +, testers +, hello +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "hello"; + version = "2.12.1"; + + src = fetchurl { + url = "mirror://gnu/hello/hello-${finalAttrs.version}.tar.gz"; + sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA="; + }; + + doCheck = true; + + passthru.tests = { + version = testers.testVersion { package = hello; }; + + invariant-under-noXlibs = + testers.testEqualDerivation + "hello must not be rebuilt when environment.noXlibs is set." + hello + (nixos { environment.noXlibs = true; }).pkgs.hello; + }; + + passthru.tests.run = callPackage ./test.nix { hello = finalAttrs.finalPackage; }; + + meta = with lib; { + description = "A program that produces a familiar, friendly greeting"; + longDescription = '' + GNU Hello is a program that prints "Hello, world!" when you run it. + It is fully customizable. + ''; + homepage = "https://www.gnu.org/software/hello/manual/"; + changelog = "https://git.savannah.gnu.org/cgit/hello.git/plain/NEWS?h=v${finalAttrs.version}"; + license = licenses.gpl3Plus; + maintainers = [ maintainers.eelco ]; + mainProgram = "hello"; + platforms = platforms.all; + }; +}) diff --git a/tests/nix/pkgs/hello/test.nix b/tests/nix/pkgs/hello/test.nix new file mode 100644 index 0000000..d882e6a --- /dev/null +++ b/tests/nix/pkgs/hello/test.nix @@ -0,0 +1,9 @@ +{ runCommand, hello }: + +runCommand "hello-test-run" +{ + nativeBuildInputs = [ hello ]; +} '' + diff -U3 --color=auto <(hello) <(echo 'Hello, world!') + touch $out +''