Skip to content

Commit

Permalink
Handle nix symbolic strings on Nix side
Browse files Browse the repository at this point in the history
This allows us to shortcut usage of NixString in many places.
We could probably get rid of NixString entirely as well, but it needs
more consideration.

Part of #58.
  • Loading branch information
YorikSar committed Sep 29, 2023
1 parent aad5869 commit 136b6be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions lib/contracts.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ let predicate | doc "Various predicates used to define contracts"
std.is_record x
&& std.record.has_field type_field x
&& x."%{type_field}" == "nixInput",
is_nix_symbolic_string = fun value =>
std.is_record value
&& std.record.has_field "tag" value
&& value.tag == 'SymbolicString
&& std.record.has_field "prefix" value
&& value.prefix == 'nix,
is_nix_string = fun value =>
std.is_record value
&& std.record.has_field type_field value
Expand Down Expand Up @@ -150,18 +156,14 @@ from the Nix world) or a derivation defined in Nickel.
= fun label value =>
# A contract must always be idempotent (be a no-op if applied a second
# time), so we accept something that is already a NixString
if predicate.is_nix_string value then
if predicate.is_nix_string value || predicate.is_nix_symbolic_string value then
value
# We accept a single string fragment (a plain string, a derivation or a
# Nix path). We normalize it by wrapping it as a one-element array
# Nix path). We normalize it by wrapping it into symbolic string
else if predicate.is_string_fragment value then
mk_nix_string [std.contract.apply NixStringFragment label value]
nix-s%"%{std.contract.apply NixStringFragment label value}"%
else
# TODO: it's for debugging, but we should remove the serializing at some
# point.
let label = std.contract.label.append_note (std.serialize 'Json value) label in
let { fragments, .. } = std.contract.apply NixSymbolicString label value in
mk_nix_string fragments,
std.contract.apply NixSymbolicString label value,

NixDerivation
| doc m%"
Expand Down
2 changes: 1 addition & 1 deletion lib/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
value.nix_drv);
in
derivation prepared
else if organistType == "nixString"
else if organistType == "nixString" || (organistType == "" && value.tag or "" == "SymbolicString" && value.prefix or "" == "nix")
then builtins.concatStringsSep "" (builtins.map importFromNickel_ value.fragments)
else if organistType == "nixPath"
then baseDir + "/${value.path}"
Expand Down

0 comments on commit 136b6be

Please sign in to comment.