Skip to content

Commit

Permalink
Use TOML serializer from nixpkgs
Browse files Browse the repository at this point in the history
Closes #263
  • Loading branch information
Patryk27 committed Jul 14, 2023
1 parent c87d6c1 commit 1568234
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 163 deletions.
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
4 changes: 2 additions & 2 deletions builtins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
, writeText
, runCommandLocal
, remarshal
, formats
}:

rec
{
toTOML = import ./to-toml.nix { inherit lib; };
writeTOML = name: attrs: writeText name (toTOML attrs);
writeTOML = (formats.toml { }).generate;

readTOML = usePure: f:
if usePure then
Expand Down
139 changes: 0 additions & 139 deletions builtins/to-toml.nix

This file was deleted.

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
30 changes: 21 additions & 9 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 @@ -65,10 +65,10 @@
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6c2318e451fc0eaf338fb461d9bfcc99869de758",
"sha256": "1djwkvjnn26v0xw1swwh7dgmi0yl0b1kb8kansrdwk0jhhqbl7zq",
"rev": "1df733d83081fe79c109b066c90badece6b8d8b1",
"sha256": "1m3s4xv35jilrmbv8hj9gzpbcqgb8vb0iqhzcm1261x8b1hiylvj",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/6c2318e451fc0eaf338fb461d9bfcc99869de758.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/1df733d83081fe79c109b066c90badece6b8d8b1.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-21.05": {
Expand Down Expand Up @@ -119,6 +119,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
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
33 changes: 33 additions & 0 deletions test/slow/probe-rs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ 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
pkgs.runCommand "probe-rs-test"
{
buildInputs = [ app ];
} "rtthost --help && touch $out"

0 comments on commit 1568234

Please sign in to comment.