Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TOML serializer from nixpkgs #300

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/fast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ jobs:
linux:
strategy:
matrix:
nixpkgs: [ nixpkgs, nixpkgs-21.05, nixpkgs-21.11 ]
runs-on: ubuntu-20.04
nixpkgs: [ nixpkgs, nixpkgs-21.05, nixpkgs-22.05, nixpkgs-23.05 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v16
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: "Run tests"
run: './script/test --fast --nixpkgs "$nixpkgs" '
env:
nixpkgs: ${{ matrix.nixpkgs }}
darwin:
runs-on: macos-10.15
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v16
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: "Run tests"
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ jobs:
linux:
strategy:
matrix:
nixpkgs: [ nixpkgs, nixpkgs-21.05, nixpkgs-21.11 ]
runs-on: ubuntu-20.04
nixpkgs: [ nixpkgs, nixpkgs-21.05, nixpkgs-22.05, nixpkgs-23.05 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v16
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: "Run tests"
run: './script/test --nixpkgs "$nixpkgs" '
env:
nixpkgs: ${{ matrix.nixpkgs }}
darwin:
runs-on: macos-10.15
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v16
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: "Run tests"
Expand Down
7 changes: 4 additions & 3 deletions build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
, writeText
, runCommandLocal
, remarshal
, formats
, crateDependencies
, zstd
, fetchurl
Expand All @@ -72,7 +73,7 @@
let
builtinz =
builtins // import ./builtins
{ inherit lib writeText remarshal runCommandLocal; };
{ inherit lib writeText remarshal runCommandLocal formats; };

drvAttrs = {
name = "${pname}-${version}";
Expand All @@ -87,7 +88,7 @@ let

# The cargo config with source replacement. Replaces both crates.io crates
# and git dependencies.
cargoconfig = builtinz.toTOML {
cargoconfig = builtinz.writeTOML "config" {
source = {
crates-io = { replace-with = "nix-sources"; };
nix-sources = {
Expand Down Expand Up @@ -235,7 +236,7 @@ let
export CARGO_HOME=''${CARGO_HOME:-$PWD/.cargo-home}
mkdir -p $CARGO_HOME

echo "$cargoconfig" > $CARGO_HOME/config
cp "$cargoconfig" $CARGO_HOME/config

runHook postConfigure
'';
Expand Down
44 changes: 42 additions & 2 deletions builtins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,52 @@
, writeText
, runCommandLocal
, remarshal
, formats
}:

rec
{
toTOML = import ./to-toml.nix { inherit lib; };
writeTOML = name: attrs: writeText name (toTOML attrs);
# Serializes given attrset into a TOML file.
#
# Usage:
# writeTOML path attrset
#
# On newer nixpkgs, this function invokes `lib.formats.toml` that nowadays
# handles all TOML documents properly.
#
# On older nixpkgs, where that serializer doesn't work correctly¹, we rely on
# a custom implementation (with its own tiny shortcomings²).
#
# TODO remove our custom serializer after nixpkgs v23 becomes more widely
# adopted
#
# ¹ e.g. cases like `[targets."cfg(\"something\")"]` are translated badly
# ² https://github.com/nix-community/naersk/issues/263
writeTOML =
let
our-impl =
let
to-toml = import ./to-toml.nix {
inherit lib;
};

in
name: value:
runCommandLocal name {
value = to-toml value;
passAsFile = [ "value" ];
} ''
cp "$valuePath" "$out"
cat "$out"
'';

nixpkgs-impl = (formats.toml { }).generate;

in
if builtins.compareVersions lib.version "22.11" <= 0 then
our-impl
else
nixpkgs-impl;

readTOML = usePure: f:
if usePure then
Expand Down
5 changes: 3 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, lib
, lndir
, remarshal
, formats
, rsync
, runCommandLocal
, rustc
Expand All @@ -15,10 +16,10 @@
}@defaultBuildAttrs:

let
libb = import ./lib.nix { inherit lib writeText runCommandLocal remarshal; };
libb = import ./lib.nix { inherit lib writeText runCommandLocal remarshal formats; };

builtinz = builtins // import ./builtins
{ inherit lib writeText remarshal runCommandLocal; };
{ inherit lib writeText remarshal runCommandLocal formats; };

mkConfig = arg:
import ./config.nix { inherit lib arg libb builtinz; };
Expand Down
9 changes: 4 additions & 5 deletions lib.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib, writeText, runCommandLocal, remarshal }:
{ lib, writeText, runCommandLocal, remarshal, formats }:
let
builtinz =
builtins // import ./builtins
{ inherit lib writeText remarshal runCommandLocal; };
{ inherit lib writeText remarshal runCommandLocal formats; };
in
rec
{
Expand Down Expand Up @@ -121,14 +121,13 @@ rec

# A very minimal 'src' which makes cargo happy nonetheless
dummySrc =
{ cargoconfig # string
{ cargoconfig # path
, cargotomls # list
, cargolock # attrset
, copySources # list of paths that should be copied to the output
, copySourcesFrom # path from which to copy ${copySources}
}:
let
config = writeText "config" cargoconfig;
cargolock' = builtinz.writeTOML "Cargo.lock" cargolock;

fixupCargoToml = cargotoml:
Expand All @@ -154,7 +153,7 @@ rec
{ inherit copySources copySourcesFrom cargotomlss; }
''
mkdir -p $out/.cargo
${lib.optionalString (! isNull cargoconfig) "cp ${config} $out/.cargo/config"}
${lib.optionalString (! isNull cargoconfig) "cp ${cargoconfig} $out/.cargo/config"}
cp ${cargolock'} $out/Cargo.lock

for tuple in $cargotomlss; do
Expand Down
54 changes: 39 additions & 15 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"agent-rs": {
"branch": "paulliu/add-cargo-lock",
"branch": "main",
"description": "A collection of libraries and tools for building software around the Internet Computer, in Rust.",
"homepage": "https://sdk.dfinity.org/",
"owner": "ninegua",
"homepage": "",
"owner": "dfinity",
"repo": "agent-rs",
"rev": "4a22e590516bc79ec3c75a320f7941e7762ea098",
"sha256": "0sacddc34nlfgldqghlwchgzjki177h5dsgpmdv70cm8hfy0sg7l",
"rev": "6d923cbc918852ef5bfaeb08e63c86580aa80ffe",
"sha256": "12y28nmv9af8sj55s998wydy08h32gvxr9dbhfxhfilxdairh0a2",
"type": "tarball",
"url": "https://github.com/ninegua/agent-rs/archive/4a22e590516bc79ec3c75a320f7941e7762ea098.tar.gz",
"url": "https://github.com/dfinity/agent-rs/archive/6d923cbc918852ef5bfaeb08e63c86580aa80ffe.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"fenix": {
Expand Down Expand Up @@ -60,15 +60,15 @@
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "master",
"branch": "nixpkgs-unstable",
Patryk27 marked this conversation as resolved.
Show resolved Hide resolved
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6c2318e451fc0eaf338fb461d9bfcc99869de758",
"sha256": "1djwkvjnn26v0xw1swwh7dgmi0yl0b1kb8kansrdwk0jhhqbl7zq",
"rev": "d2b52322f35597c62abf56de91b0236746b2a03d",
"sha256": "1zrqry4m22rbscazxbcqf5ym7ckm6v7pvxpsml23whc1gjf2hkk3",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/6c2318e451fc0eaf338fb461d9bfcc99869de758.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/d2b52322f35597c62abf56de91b0236746b2a03d.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-21.05": {
Expand All @@ -83,16 +83,28 @@
"url": "https://github.com/NixOS/nixpkgs/archive/6d684ea3adef590a2174f2723134e1ea377272d2.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-21.11": {
"branch": "release-21.11",
"nixpkgs-22.05": {
"branch": "release-22.05",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "380be19fbd2d9079f677978361792cb25e8a3635",
"sha256": "154x9swf494mqwi4z8nbq2f0sp8pwp4fvx51lqzindjfbb9yxxv5",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/380be19fbd2d9079f677978361792cb25e8a3635.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-23.05": {
"branch": "release-23.05",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "432864f33c84af53192d4b23ee5871697e57f094",
"sha256": "0sqmasma9qin7nhfzv50d1la1mi1yazn7gx2lrxi9j61i9j8l3zm",
"rev": "b81af66deb21f73a70c67e5ea189568af53b1e8c",
"sha256": "172i5kzn8qja3k0rz9wfj86fgbw2ivc68yw3ra8g86byqc1rcw1m",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/432864f33c84af53192d4b23ee5871697e57f094.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/b81af66deb21f73a70c67e5ea189568af53b1e8c.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-mozilla": {
Expand All @@ -119,6 +131,18 @@
"url": "https://github.com/nushell/nushell/archive/85bfdca578157072e51e6972d370cfe63b0fda77.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"probe-rs": {
"branch": "master",
"description": "A debugging toolset and library for debugging embedded ARM and RISC-V targets on a separate host",
"homepage": "https://probe.rs",
"owner": "probe-rs",
"repo": "probe-rs",
"rev": "51fa324aef9f7c413988a3d18052b1bbc278a4c5",
"sha256": "0zb9s80hsz83ngjngs9cllp7gf8xq9jz0m3lwdhf08x3cp3bj6fd",
"type": "tarball",
"url": "https://github.com/probe-rs/probe-rs/archive/51fa324aef9f7c413988a3d18052b1bbc278a4c5.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ripgrep-all": {
"branch": "master",
"description": "rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.",
Expand Down
22 changes: 19 additions & 3 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@
let
sources = import ../nix/sources.nix;

pkgs = import ../nix {
inherit system nixpkgs;
};
pkgs =
let
pkgs' = import ../nix {
inherit system nixpkgs;
};

older-pkgs = import ../nix {
inherit system;

nixpkgs = "nixpkgs-21.05";
};

in
pkgs' // {
# Some of our tests use dynamically-built Git repositories that fail extra
# security checks introduced in newer Git versions - so for the time being
# let's pin our test-Git to an older version.
git = older-pkgs.git;
};

naersk = pkgs.callPackage ../default.nix {
inherit (pkgs.rustPackages) cargo rustc;
Expand Down
15 changes: 14 additions & 1 deletion test/slow/agent-rs/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{ sources, naersk, pkgs, ... }:
{ sources, pkgs, ... }:
let
fenix = import sources.fenix { };

toolchain = fenix.fromToolchainFile {
file = "${sources.agent-rs}/rust-toolchain.toml";
sha256 = "sha256-DzNEaW724O8/B8844tt5AVHmSjSQ3cmzlU4BP90oRlY=";
};

naersk = pkgs.callPackage ../../../default.nix {
cargo = toolchain;
rustc = toolchain;
};

in
naersk.buildPackage {
src = sources.agent-rs;

Expand Down
1 change: 1 addition & 0 deletions test/slow/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ args: {
agent-rs = import ./agent-rs args;
lorri = import ./lorri args;
nushell = import ./nushell args;
probe-rs = import ./probe-rs args;
ripgrep-all = import ./ripgrep-all args;
rustlings = import ./rustlings args;
talent-plan = import ./talent-plan args;
Expand Down
40 changes: 40 additions & 0 deletions test/slow/probe-rs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ sources, pkgs, ... }:
let
fenix = import sources.fenix { };

toolchain = (fenix.toolchainOf {
channel = "nightly";
date = "2023-07-01";
sha256 = "sha256-pWd4tAHP4QWGC3CKWZzDjzYANxATC6CGRmKuP2ZZv5k=";
}).toolchain;

naersk = pkgs.callPackage ../../../default.nix {
cargo = toolchain;
rustc = toolchain;
};

app = naersk.buildPackage {
src = sources.probe-rs;

buildInputs = with pkgs; [
pkg-config
libusb1
openssl
] ++ lib.optionals stdenv.isDarwin [
darwin.DarwinTools
darwin.apple_sdk.frameworks.AppKit
];
};

in
if builtins.compareVersions pkgs.lib.version "22.11" <= 0 then
# Executing this test requires nixpkgs > 22.11 due to changes to the TOML
# serialization function.
#
# See `writeTOML` in this repository for more details.
true
else
pkgs.runCommand "probe-rs-test"
{
buildInputs = [ app ];
} "rtthost --help && touch $out"
Loading