Code Monkey home page Code Monkey logo

nix-1p's Issues

Parenthesis are used without defining their use and meaning in the Nix language

Parenthesis ( ) are used in the example here:

({ a ? 1, b }@args: args.a) { b = 1; }

But their syntactical use and meaning in the Nix language has not been defined.

In the Nix language, parentheses are primarily used to group expressions, control the order of evaluation, and encapsulate language elements to disambiguate their boundaries within larger expressions.

[Edit] This usage does not fall into my previous definition:

inherit (otherAttrs) email; # equivalent to `email = otherAttrs.email`;

Should a statement about parenthesis include the syntax that can be used for "inherit"?

Also ( ) can be used to control the scope of the "with" statement:

in with attrs; (/* this is the scope of the `with` */)

Can ( ) be used to control the scope of variables in general? (visibility / lifetime scope?)

Pedantry corner: import isn't a keyword

https://github.com/tazjin/nix-1p#import--nix_path--entry claims that import is a keyword. As far as I'm aware, it's just a built-in function: both the nixos/nix and rnix parsers parse it as a normal identifier, and I'm not aware of it being magic in any way that other built-in functions aren't.

(Another confusing thing, on a more meta level: this document is republished in the tvl monorepo at https://code.tvl.fyi/about/nix/nix-1p, which makes the instruction to "file an issue" with no further detail rather confusing.)

Clarify the description of "callPackage"

With reference to:

nix-1p/README.md

Lines 578 to 580 in 1cf10d3

The `callPackage` function looks at the expected arguments (via
`builtins.functionArgs`) and passes the appropriate keys from the set in which
it is defined as the values for each corresponding argument.

Looking specifically at the phrase "the set in which it is defined" it isn't clear:

  1. What is "it"? (the callpackage function?)

  2. Which set is being described?

The callpackage function does not appear to be defined as part of a set in this example:

nix-1p/README.md

Lines 572 to 575 in 1cf10d3

{ pkgs ? import <nixpkgs> {} }:
let my-funky-program = pkgs.callPackage ./my-funky-program.nix {};
in # ... something happens with my-funky-program

Semicolons are used without defining their use and meaning in the Nix language

Semicolons ";" are first used in the example here:

let attrs = { a = 15; b = builtins.throw "Oh no!"; };

But their syntactical use and meaning in the Nix language has not been defined.

I cannot confirm if this is completely accurate, but according to ChatGPT:
"In the Nix language, semicolons are used to terminate expressions within attribute sets, function arguments, and let bindings. They signify the end of one statement and the separation from the next, ensuring clear demarcation of different elements within these constructs."

Language usage of the "?" character

The first occurrence of the "?" character is in the table of language operators. As an operator, the "?" usage is defined as:
set ? attribute Test whether attribute set contains an attribute

The second occurrence of "?" is used is for the example code:
{ name, age ? 42 }: "${name} is ${toString age} years old"

I found this confusing because this usage does not agree with the operator definition.

Since the "?" character can also be used to define default values in function parameter declarations, please add a comment, note, or definition of that usage.

overrideAttrs only works if the attribute is already populated

if you try

someProgram.overrideAttrs(old: {
    configureFlags = old.configureFlags ++ ["--mimic-threaten-tag"];
})

configureFlags has to be populated, if it's empty overriderAttrs can't append to an empty list

nix repl
:l <nixpkgs>

nix-repl> cowsay.configureFlags
[ ]

cowsay.overrideAttrs(old: { configureFlags = old.configureFlags ++  ["--dummy"]; })


error: attribute 'configureFlags' missing

       at «string»:1:45:

            1| cow.overrideAttrs(old: { configureFlags = old.configureFlags ++  ["--dummy"]; })
             |                                             ^
            2|

however

nix-repl> cowsay.outputs                                                           
[ "out" "man" ]

cowsay.overrideAttrs(old: { outputs = old.outputs ++  ["--dummy"]; })
«derivation /nix/store/0fva8szi6s2cz838l9ag9xayd583mxay-cowsay-3.04.drv»

so i think this is a quirk with overrideAttrs

however is easily fixed with

:b  hello.overrideAttrs(old: { configureFlags = ["--dummy"]; }) 

error: builder for '/nix/store/k5y89y29rgkrwapvak19giwbhkpncabv-hello-2.10.drv' failed with exit code 1;
       last 9 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz
       > source root is hello-2.10
       > setting SOURCE_DATE_EPOCH to timestamp 1416139241 of file hello-2.10/ChangeLog
       > patching sources
       > configuring
       > configure flags: --disable-dependency-tracking --prefix=/nix/store/133si7nj0lpg8bf0hwgpi7wbq8nmzbla-hello-2.10 --dummyaaa
       > configure: error: unrecognized option: `--dummyaaa'
       > Try `./configure --help' for more information
       For full logs, run 'nix log /nix/store/k5y89y29rgkrwapvak19giwbhkpncabv-hello-2.10.drv'.

bizzare huh! i presume the there is no 'old.configureFlags', because it's empty :-) .... quirky?

Confusing what the scope of `with` is.

In https://github.com/tazjin/nix-1p#with-statements

For me, it was a bit confusing what kind of thing with is. What I understood from the current explanation in my own words:

with <attr> is an expression which can precede an expression to put all members of into its scope:

nix-repl> let x = 7; attr = {a = 5;}; in x + (with attr; a)
12

However from my experiments with the repl, it only looks like an expression (because it is followed by ;), but it is not.

Adding examples (or additional explanation) for the merge operator .

Lines 129 - 132 the merge operator.

| `left // right`      | Merge `left` & `right` attribute sets, with the right set taking precedence |

Make sure to understand the `//`-operator, as it is used quite a lot and is
probably the least familiar one.

The note says to focus on the merge operator and to make sure to understand it but no real examples are provided nor is merge discussed in the rest of the document.

Is there a way we could add a solid example or two, or perhaps an additional section explaining how/why to use merge.

I think I understand it but feel explaining the operator more would be very helpful. Especially after making a point of adding the note stating to make sure to understand it. Also searching for // is a pain.

The nix docs don't really explain merge either.

{ x = 1; y = 2; } // { z = 3; }

Merge two sets (attributes in the right-hand set taking precedence)

Thanks!

Provide a statement about how whitespace is interpreted in Nix code.

In code formatting, is whitespace meaningful?
Does the syntax depend on line breaks in any way?

For example, the first time functions are introduced, the full declaration is on one line:

name: "Hello ${name}"

Later an example function declaration takes up 3 lines with a blank line in between:

nix-1p/README.md

Lines 562 to 564 in 1cf10d3

{ stdenv, libsvg }:
stdenv.mkDerivation { ... }

ChatGPT:
"In the Nix language, whitespace is generally used to separate tokens but does not have a significant impact on the interpretation of code beyond this. Unlike some programming languages where indentation or the presence of whitespace can alter the behavior of the code, Nix treats extra spaces, line breaks, and indentation as non-semantic, primarily for improving code readability and organization."

"Everything in Nix is an expression, meaning that every directive returns some kind of data."

"Everything in Nix is an expression"
There are parts of the language that are not expressions. For example, "Let" could be described as a "keyword" since it is a predefined reserved word in the Nix language. Although "Let" is "in Nix", it isn't an expression by itself. There are syntactical elements which are also part of Nix, but they are not expressions. For example "[" is a valid part of the Nix language, but not an expression by itself. In the Nix repl, if I type "Let" (and then enter) or "[" (and then enter) I get error messages.

"meaning that every directive returns some kind of data."
What is a "directive"?

Concerning the Overview: Clarification about the non-Sequential Nature of Nix

Hey there,

first of all, thanks for compiling this introduction. It's very clear and on-point and quickly brings you up-to-speed with the basics of the language. But since you asked to file an issue if something wasn't perfectly clear, I thought I mention this rather minor point.

In the Overview you clarify in what sense Nix was functional. I think there are two statements that seem contradictory:

  • "It has no concept of sequential steps being executed, any dependency between operations is established by depending on data from previous operations."
  • "Evaluating a Nix expression yields a single data structure, it does not execute a sequence of operations."

I think it's not obvious in what sense there can be previous operations if there is no sequence of operations.

Like I've said, it's a minor point and the main purpose of the document is probably to give an introduction to the syntax and semantics of the language, but I still thought it was worth mentioning.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.