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
lib.trivial: add a new importJSON function #13552
Conversation
Why is this in lib.modules? |
(Off-topic.) Hmm, it's a shame that the nix language doesn't have the composition operator. I've seen quite a lot situations where I would use it. Here it doesn't simplify much, |
Probably |
@shlevy fixed |
This is meant to be used by packages who often re-generate their inputs. Producing valid JSON is easier than nix, and also garantees it's purity.
Let's also replace |
@domenkozar done. I don't see any users of buildMaven ? |
lib.trivial: add a new importJSON function
(OT) @vcunat @zimbatm Was missing this, too. Even having |
Off-topic. TL;DR: composition of functions is a nice thing, but currently I can't see enough use cases in nixpkgs to be worth of action. (If it was, I would open an issue, but this way I didn't know where to post instead.) Composition is associative and it's useful in some programming styles (e.g. in shells). We can't have a similar (infix) operator without changing nix, I think, but we could use lists, as you suggest: let # to fix highlighting
applyList = fold (f: g: x: f (g x)) (x: x);
# so instead of haskell's: fun call 1 . fun call 2 . fun call 3 $ point
# we might use applyList [ (fun call 1) (fun call 2) (fun call 3) ] point
# that would give
importJSON = applyList [ builtins.fromJSON builtins.readFile ];
# instead of
importJSON = path: builtins.fromJSON (builtins.readFile path);
# maybe better use case, but a completely singular one
top-level = fix' ( applyList (map extends [ customOverrides stdenvOverrides /*...*/ ]) (self: {}) )
# ^ it's likely I've got some bug on this line |
+1, but I’d like to have the base (and conceptually nicer) case as well and then define the more specific function with it (fold over And of course there is a naming question. I think |
I haven't thought much about the name, as I could find almost no places to use it. |
compose f1 compose f2 compose f3 f4 == f1 . f2 . f3 . f4 # NOT true
|
Another option would be to have something like: { composeFun = f: g:
if isFunction g then
y: composeFun (x: g (f x)) y
else
f;
importJSON = x: assert !(isFunction x);
composeFun builtins.readFile builtins.fromJSON x; Unfortunately, this is not as nice as the |
My last post doesn't hold. I misplaced one parenthesis. |
No, please no. Just no. |
Things done:
nix-build --option build-use-chroot true
or nix.useChroot on NixOS)This is meant to be used by packages who often re-generate their outputs.
Producing valid JSON is easier than nix, and also garantees it's purity.