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

Handle nix symbolic strings on Nix side #153

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
27 changes: 3 additions & 24 deletions lib/contracts.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ 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_string = fun value =>
std.is_record value
&& std.record.has_field type_field value
&& value."%{type_field}" == "nixString",
is_nickel_derivation = fun x =>
std.is_record x
&& std.record.has_field type_field x
Expand All @@ -33,13 +29,6 @@ let predicate | doc "Various predicates used to define contracts"
}
in

let mk_nix_string = fun fs =>
{
"%{type_field}" = "nixString",
fragments = fs,
}
in

{
# Nix may require name, version, etc. to have a certain format, but we're not sure.
# TODO: refine those contracts
Expand Down Expand Up @@ -148,20 +137,10 @@ from the Nix world) or a derivation defined in Nickel.
`lib.import_file`), pure Nickel strings, and maybe more in the future.
"%%
= 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
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
else if predicate.is_string_fragment value then
mk_nix_string [std.contract.apply NixStringFragment label value]
if predicate.is_string_fragment value then
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
4 changes: 2 additions & 2 deletions lib/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
value.nix_drv);
in
derivation prepared
else if organistType == "nixString"
then builtins.concatStringsSep "" (builtins.map importFromNickel_ value.fragments)
else if organistType == "nixPath"
then baseDir + "/${value.path}"
else if organistType == "nixInput"
Expand All @@ -116,6 +114,8 @@
lib.getAttrFromPath chosenAttrPath flakeInputs
else if organistType == "nixPlaceholder"
then builtins.placeholder value.output
else if value.tag or "" == "SymbolicString" && value.prefix or "" == "nix"
then builtins.concatStringsSep "" (builtins.map importFromNickel_ value.fragments)
else builtins.mapAttrs (_: importFromNickel_) value
)
else if (type == "list")
Expand Down