{"id":18803458,"url":"https://github.com/rofrol/nix-for-javascript-developers","last_synced_at":"2025-04-13T18:34:30.434Z","repository":{"id":66526161,"uuid":"431434166","full_name":"rofrol/nix-for-javascript-developers","owner":"rofrol","description":"Nix language for Javascript developers","archived":false,"fork":false,"pushed_at":"2023-08-15T12:57:52.000Z","size":9,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T15:06:24.100Z","etag":null,"topics":["nix","nixos"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rofrol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-24T10:08:40.000Z","updated_at":"2024-09-26T11:11:06.000Z","dependencies_parsed_at":"2024-11-07T22:38:20.290Z","dependency_job_id":"1f4f2c92-5863-4ea8-a6a5-7bbbd0494e5f","html_url":"https://github.com/rofrol/nix-for-javascript-developers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rofrol%2Fnix-for-javascript-developers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rofrol%2Fnix-for-javascript-developers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rofrol%2Fnix-for-javascript-developers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rofrol%2Fnix-for-javascript-developers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rofrol","download_url":"https://codeload.github.com/rofrol/nix-for-javascript-developers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248761047,"owners_count":21157483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nix","nixos"],"created_at":"2024-11-07T22:35:13.824Z","updated_at":"2025-04-13T18:34:30.425Z","avatar_url":"https://github.com/rofrol.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"## How to run examples\n\nUse `nix eval --expr` instead of `nix-instantiate --eval --expr`:\n\n```bash\n$ nix-instantiate --eval --expr '(x: y: { a = x + \"-\" + y; }) \"a\" \"b\"'\n{ a = \u003cCODE\u003e; }\n$ nix eval --expr '(x: y: { a = x + \"-\" + y; }) \"a\" \"b\"'\n{ a = \"a-b\"; }\n```\n\nFor node you must use `console.log` unless it is already in the example.\n\n```bash\n$ node -e 'console.log(((x, y) =\u003e ({ a: x + \"-\" + y }))(\"a\", \"b\"))'\n{ a: 'a-b' }\n```\n\nIf you want to have `nix eval` available in nixos stable, you need to install unstable nix command as described in https://nixos.wiki/wiki/Flakes.\n\n\n## Examples\n\n| Nix | Javascript |\n| --- | --- |\n| `\"Hello world!\"` | `\"Hello world!\"` |\n| `2/3` | `require(\"path\").join(\"2\", \"3\")` |\n| `2/ 3` | `Math.ceil(2/3)` | |\n| `2/ 3.` | `2/3` |\n| `(a: { a = a; }) 2` | `(a =\u003e ({ a: a }))(2)` |\n| `(a: { inherit a; }) 2` | `(a =\u003e ({ a }))(2)` |\n| `(a: b: { a = a; b = b; }) 2 3` | `((a, b) =\u003e ({ a: a, b: b }))(2, 3)` |\n| `((a: b: { inherit a b; }) 2) 3` | `(a =\u003e b =\u003e ({ a, b }))(2)(3)` |\n| `({ a }: { inherit a; }) { a = 2; }` | `(({ a }) =\u003e ({ a }))({ a: 2 })` |\n| `({ a, b, ... }: { inherit a b; }) { a = 2; b = 3; c = 4; }` | `(({ a, b }) =\u003e ({ a, b }))({ a: 2, b: 3, c: 4 })` |\n| `(a: { c = a.b.c; }) { b = { c = 2; }; }` | `(a =\u003e ({ c: a.b.c }))({ b: { c: 2 } })` |\n| `(a: { inherit (a.b) c; }) { b = { c = 2; }; }` | `(a =\u003e ({ c: a.b.c }))({ b: { c: 2 } })` |\n| `({ a ? 2 }: a) {}` | `(({ a = 2 }) =\u003e a)({})` |\n| `let double = x: x*2; in double 3` | `const double = x =\u003e x*2; console.log(double(3));` |\n| `let mul = a: (b: a*b); in (mul 2) 3` | `const mul = a =\u003e b =\u003e  a*b; console.log(mul(2)(3));` |\n| `let x = 3; mul = a: (b: a*b); in (mul 2) 3` | `const x = 3, mul = a =\u003e b =\u003e  a*b; console.log(mul(x)(3));` |\n| `if true then 3 else 2` | `true ? 3: 2` |\n\n## Links\n\n- https://learnxinyminutes.com/docs/nix/\n- https://medium.com/@MrJamesFisher/nix-by-example-a0063a1a4c55\n- https://nixery.dev/nix-1p.html\n- https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-eval.html\n- https://nixos.wiki/wiki/Nix_command/eval\n- https://nixos.org/guides/nix-pills/functions-and-imports.html\n\n## Expression vs statement\n\nYou can read that Nix is Nix expression language.\n\n\u003eExpression: Something which evaluates to a value. Example: 1+2/x\n\u003e\n\u003eStatement: A line of code which does something. Example: GOTO 100\n\nOr another explanation:\n\nExpression -- from the New Oxford American Dictionary:\n\n\u003e expression: Mathematics a collection of symbols that jointly express a quantity : the expression for the circumference of a circle is 2πr.\n\nStatement from [Wikipedia](http://en.wikipedia.org/wiki/Python_(programming_language)#Statements_and_control_flow):\n\n\u003eIn computer programming a statement can be thought of as the smallest standalone element of an imperative programming language. A program is formed by a sequence of one or more statements. A statement will have internal components (e.g., expressions).\n\n- https://stackoverflow.com/questions/19132/expression-versus-statement/19224#19224\n- https://stackoverflow.com/questions/4728073/what-is-the-difference-between-an-expression-and-a-statement-in-python/4730559#4730559\n\n### Example\n\nBelow `const a` is a statement which consist of expression. [Conditional (ternary) operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) is an expression.\n\n```javascript\nconst a = true ? 1 : 0;\n```\n\n## JSON\n\nDescription from [Nickel](https://github.com/tweag/nickel), possible successor of Nix language:\n\n\u003eIts purpose is to automate the generation of static configuration files - think JSON, YAML, XML, or your favorite data representation language - that are then fed to another system. It is designed to have a simple, well-understood core: it is in essence JSON with functions.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frofrol%2Fnix-for-javascript-developers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frofrol%2Fnix-for-javascript-developers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frofrol%2Fnix-for-javascript-developers/lists"}