diff --git a/flake.lock b/flake.lock index 2158d87..5e0cc97 100644 --- a/flake.lock +++ b/flake.lock @@ -90,11 +90,11 @@ "pruned-racket-catalog": "pruned-racket-catalog" }, "locked": { - "lastModified": 1675238477, - "narHash": "sha256-LM5GDNjLcmgZVQEeANWAOO09KppwGaYEzJBjYmuSwys=", + "lastModified": 1676992344, + "narHash": "sha256-TEn5kEi/jL9Dt6O+ZZ7kQwnlAgEv0r4VgQZnav/cfV4=", "owner": "nix-community", "repo": "dream2nix", - "rev": "f61d9311e224a2c5f6691f8f8d7411e7284650fb", + "rev": "db72710500a80bdf4589b6807d2491a4a0dae3ad", "type": "github" }, "original": { @@ -144,14 +144,17 @@ }, "flake-parts": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": [ + "dream2nix", + "nixpkgs" + ] }, "locked": { - "lastModified": 1668450977, - "narHash": "sha256-cfLhMhnvXn6x1vPm+Jow3RiFAUSCw/l1utktCw5rVA4=", + "lastModified": 1675933616, + "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "d591857e9d7dd9ddbfba0ea02b43b927c3c0f1fa", + "rev": "47478a4a003e745402acf63be7f9a092d51b83d7", "type": "github" }, "original": { @@ -305,31 +308,13 @@ "type": "indirect" } }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1665349835, - "narHash": "sha256-UK4urM3iN80UXQ7EaOappDzcisYIuEURFRoGQ/yPkug=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "34c5293a71ffdb2fe054eb5288adc1882c1eb0b1", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "nixpkgs-master": { "locked": { - "lastModified": 1677161649, - "narHash": "sha256-ypilUl4lX0VCZUxpnq650SzVvcI2cwQmuhhTVWJ3af0=", + "lastModified": 1677165478, + "narHash": "sha256-bWABTj9vlT26d3zpI+NQmuOwcXAzwJGNIgdgPfsnyk8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e3040b367c667525b614204d510ae0d09c59c8e0", + "rev": "21d1c5425c1c0f4b4ae6203086951164920d9fab", "type": "github" }, "original": { diff --git a/website/components/preview/preview.tsx b/website/components/preview/preview.tsx index e8a6f84..005d081 100644 --- a/website/components/preview/preview.tsx +++ b/website/components/preview/preview.tsx @@ -28,7 +28,7 @@ interface PreviewProps { export const Preview = (props: PreviewProps) => { const { docItem, handleClose, closeComponent = undefined } = props; - const { name, description, category, example, fn_type, id } = docItem; + const { name, description, category, example, fn_type, id, line } = docItem; const theme = useTheme(); const prefix = category.split(/([\/.])/gm).at(4) || "builtins"; @@ -120,7 +120,7 @@ export const Preview = (props: PreviewProps) => { href={`https://github.com/NixOS/nixpkgs/blob/master/${category.replace( "./", "" - )}`} + )}#L${line}`} > {"github:NixOS/nixpkgs/" + category.replace("./", "")} diff --git a/website/models/nix.ts b/website/models/nix.ts index a854d1c..0d50944 100644 --- a/website/models/nix.ts +++ b/website/models/nix.ts @@ -16,6 +16,7 @@ export type DocItem = { fn_type?: null | string; description?: null | string | string[]; example?: null | string | string[]; + line?: null | number; }; export type MetaData = DocItem[]; \ No newline at end of file diff --git a/website/queries/byQuery.ts b/website/queries/byQuery.ts index 6a165a8..18e6895 100644 --- a/website/queries/byQuery.ts +++ b/website/queries/byQuery.ts @@ -6,7 +6,7 @@ export const byQuery = const term = rawTerm.toLowerCase(); return data.reduce((results: (DocItem & {relevance: number})[], docItem: DocItem)=>{ const matchesOn = Object.keys(docItem).filter(key=>{ - const rawValue = docItem[key as keyof DocItem]; + const rawValue = String(docItem[key as keyof DocItem]); if(rawValue === null || rawValue === undefined){ return false; } @@ -31,6 +31,7 @@ const getRelevance = (matchesOn: (keyof DocItem)[]): number => { category: 3, example: 2, description: 1, + line: 1, } return matchesOn.reduce((count,key)=>{ return count + relevanceMap[key] diff --git a/website/queries/byType.ts b/website/queries/byType.ts index a2ea212..13e7373 100644 --- a/website/queries/byType.ts +++ b/website/queries/byType.ts @@ -12,6 +12,9 @@ export const byType = ({ name, fn_type }) => { if (fn_type) { const parsedType = getTypes(name, fn_type); + // if(name === "derivation"){ + // console.log({name,parsedType,fn_type}); + // } return ( parsedType.args.includes(from) && parsedType.types.includes(to) ); diff --git a/website/scripts/data/builtins.types.json b/website/scripts/data/builtins.types.json index 869815d..edec254 100644 --- a/website/scripts/data/builtins.types.json +++ b/website/scripts/data/builtins.types.json @@ -23,6 +23,9 @@ "fn_type": "concatStringsSep :: String -> [String] -> String" }, "deepSeq": { "fn_type": "deepSeq :: a -> b -> b" }, + "derivation": { + "fn_type": "let \n Derivation :: {\n all :: [ Derivation ];\n builder :: String;\n drvAttrs :: {\n builder = String; \n name = String;\n outputs = [ output :: String ]; \n system = String;\n ${additionalArgs} :: String;\n }\n drvPath :: String;\n name :: String;\n outPath :: String;\n outputName :: String;\n outputs :: [ output :: String ];\n system :: String;\n type :: \"derivation\";\n ${output} :: Derivation;\n ${additionalArgs} :: String;\n };\nin\n builtins.derivation :: {\n name :: String;\n outputs :: [ output :: String ] ? [ \"out\" ];\n builder :: String;\n system :: String;\n ${additionalArgs} :: String;\n } -> Derivation" + }, "dirOf": { "fn_type": "dirOf :: String -> String" }, "div": { "fn_type": "div :: Number -> Number -> Number" }, "elem": { "fn_type": "elem :: a -> [b] -> Bool" }, diff --git a/website/scripts/data/derivation-doc.txt b/website/scripts/data/derivation-doc.txt new file mode 100644 index 0000000..5ac661b --- /dev/null +++ b/website/scripts/data/derivation-doc.txt @@ -0,0 +1 @@ +# Derivations\n\nThe most important built-in function is `derivation`, which is used to\ndescribe a single derivation (a build task). It takes as input a set,\nthe attributes of which specify the inputs of the build.\n\n - There must be an attribute named [`system`]{#attr-system} whose value must be a\n string specifying a Nix system type, such as `\"i686-linux\"` or\n `\"x86_64-darwin\"`. (To figure out your system type, run `nix -vv\n --version`.) The build can only be performed on a machine and\n operating system matching the system type. (Nix can automatically\n [forward builds for other\n platforms](../advanced-topics/distributed-builds.md) by forwarding\n them to other machines.)\n\n - There must be an attribute named `name` whose value must be a\n string. This is used as a symbolic name for the package by\n `nix-env`, and it is appended to the output paths of the derivation.\n\n - There must be an attribute named `builder` that identifies the\n program that is executed to perform the build. It can be either a\n derivation or a source (a local file reference, e.g.,\n `./builder.sh`).\n\n - Every attribute is passed as an environment variable to the builder.\n Attribute values are translated to environment variables as follows:\n \n - Strings and numbers are just passed verbatim.\n \n - A *path* (e.g., `../foo/sources.tar`) causes the referenced file\n to be copied to the store; its location in the store is put in\n the environment variable. The idea is that all sources should\n reside in the Nix store, since all inputs to a derivation should\n reside in the Nix store.\n \n - A *derivation* causes that derivation to be built prior to the\n present derivation; its default output path is put in the\n environment variable.\n \n - Lists of the previous types are also allowed. They are simply\n concatenated, separated by spaces.\n \n - `true` is passed as the string `1`, `false` and `null` are\n passed as an empty string.\n\n - The optional attribute `args` specifies command-line arguments to be\n passed to the builder. It should be a list.\n\n - The optional attribute `outputs` specifies a list of symbolic\n outputs of the derivation. By default, a derivation produces a\n single output path, denoted as `out`. However, derivations can\n produce multiple output paths. This is useful because it allows\n outputs to be downloaded or garbage-collected separately. For\n instance, imagine a library package that provides a dynamic library,\n header files, and documentation. A program that links against the\n library doesn’t need the header files and documentation at runtime,\n and it doesn’t need the documentation at build time. Thus, the\n library package could specify:\n \n ```nix\n outputs = [ \"lib\" \"headers\" \"doc\" ];\n ```\n \n This will cause Nix to pass environment variables `lib`, `headers`\n and `doc` to the builder containing the intended store paths of each\n output. The builder would typically do something like\n \n ```bash\n ./configure \\n --libdir=$lib/lib \\n --includedir=$headers/include \\n --docdir=$doc/share/doc\n ```\n \n for an Autoconf-style package. You can refer to each output of a\n derivation by selecting it as an attribute, e.g.\n \n ```nix\n buildInputs = [ pkg.lib pkg.headers ];\n ```\n \n The first element of `outputs` determines the *default output*.\n Thus, you could also write\n \n ```nix\n buildInputs = [ pkg pkg.headers ];\n ```\n \n since `pkg` is equivalent to `pkg.lib`.\n\nThe function `mkDerivation` in the Nixpkgs standard environment is a\nwrapper around `derivation` that adds a default value for `system` and\nalways uses Bash as the builder, to which the supplied builder is passed\nas a command-line argument. See the Nixpkgs manual for details.\n\nThe builder is executed as follows:\n\n - A temporary directory is created under the directory specified by\n `TMPDIR` (default `/tmp`) where the build will take place. The\n current directory is changed to this directory.\n\n - The environment is cleared and set to the derivation attributes, as\n specified above.\n\n - In addition, the following variables are set:\n \n - `NIX_BUILD_TOP` contains the path of the temporary directory for\n this build.\n \n - Also, `TMPDIR`, `TEMPDIR`, `TMP`, `TEMP` are set to point to the\n temporary directory. This is to prevent the builder from\n accidentally writing temporary files anywhere else. Doing so\n might cause interference by other processes.\n \n - `PATH` is set to `/path-not-set` to prevent shells from\n initialising it to their built-in default value.\n \n - `HOME` is set to `/homeless-shelter` to prevent programs from\n using `/etc/passwd` or the like to find the user's home\n directory, which could cause impurity. Usually, when `HOME` is\n set, it is used as the location of the home directory, even if\n it points to a non-existent path.\n \n - `NIX_STORE` is set to the path of the top-level Nix store\n directory (typically, `/nix/store`).\n \n - For each output declared in `outputs`, the corresponding\n environment variable is set to point to the intended path in the\n Nix store for that output. Each output path is a concatenation\n of the cryptographic hash of all build inputs, the `name`\n attribute and the output name. (The output name is omitted if\n it’s `out`.)\n\n - If an output path already exists, it is removed. Also, locks are\n acquired to prevent multiple Nix instances from performing the same\n build at the same time.\n\n - A log of the combined standard output and error is written to\n `/nix/var/log/nix`.\n\n - The builder is executed with the arguments specified by the\n attribute `args`. If it exits with exit code 0, it is considered to\n have succeeded.\n\n - The temporary directory is removed (unless the `-K` option was\n specified).\n\n - If the build was successful, Nix scans each output path for\n references to input paths by looking for the hash parts of the input\n paths. Since these are potential runtime dependencies, Nix registers\n them as dependencies of the output paths.\n\n - After the build, Nix sets the last-modified timestamp on all files\n in the build result to 1 (00:00:01 1/1/1970 UTC), sets the group to\n the default group, and sets the mode of the file to 0444 or 0555\n (i.e., read-only, with execute permission enabled if the file was\n originally executable). Note that possible `setuid` and `setgid`\n bits are cleared. Setuid and setgid programs are not currently\n supported by Nix. This is because the Nix archives used in\n deployment have no concept of ownership information, and because it\n makes the build result dependent on the user performing the build. \ No newline at end of file diff --git a/website/scripts/data/derivation-signature.txt b/website/scripts/data/derivation-signature.txt new file mode 100644 index 0000000..7cfc1bb --- /dev/null +++ b/website/scripts/data/derivation-signature.txt @@ -0,0 +1,29 @@ +let + Derivation :: { + all :: [ Derivation ]; + builder :: String; + drvAttrs :: { + builder = String; + name = String; + outputs = [ output :: String ]; + system = String; + ${additionalArgs} :: String; + } + drvPath :: String; + name :: String; + outPath :: String; + outputName :: String; + outputs :: [ output :: String ]; + system :: String; + type :: "derivation"; + ${output} :: Derivation; + ${additionalArgs} :: String; + }; +in + builtins.derivation :: { + name :: String; + outputs :: [ output :: String ] ? [ "out" ]; + builder :: String; + system :: String; + ${additionalArgs} :: String; + } -> Derivation \ No newline at end of file diff --git a/website/scripts/data/derivation.json b/website/scripts/data/derivation.json new file mode 100644 index 0000000..b8423b7 --- /dev/null +++ b/website/scripts/data/derivation.json @@ -0,0 +1,7 @@ +{ + "derivation": { + "args": ["s"], + "arity": 1, + "doc": "# Derivations\n\nThe most important built-in function is `derivation`, which is used to\ndescribe a single derivation (a build task). It takes as input a set,\nthe attributes of which specify the inputs of the build.\n\n - There must be an attribute named [`system`]{#attr-system} whose value must be a\n string specifying a Nix system type, such as `\"i686-linux\"` or\n `\"x86_64-darwin\"`. (To figure out your system type, run `nix -vv\n --version`.) The build can only be performed on a machine and\n operating system matching the system type. (Nix can automatically\n [forward builds for other\n platforms](../advanced-topics/distributed-builds.md) by forwarding\n them to other machines.)\n\n - There must be an attribute named `name` whose value must be a\n string. This is used as a symbolic name for the package by\n `nix-env`, and it is appended to the output paths of the derivation.\n\n - There must be an attribute named `builder` that identifies the\n program that is executed to perform the build. It can be either a\n derivation or a source (a local file reference, e.g.,\n `./builder.sh`).\n\n - Every attribute is passed as an environment variable to the builder.\n Attribute values are translated to environment variables as follows:\n \n - Strings and numbers are just passed verbatim.\n \n - A *path* (e.g., `../foo/sources.tar`) causes the referenced file\n to be copied to the store; its location in the store is put in\n the environment variable. The idea is that all sources should\n reside in the Nix store, since all inputs to a derivation should\n reside in the Nix store.\n \n - A *derivation* causes that derivation to be built prior to the\n present derivation; its default output path is put in the\n environment variable.\n \n - Lists of the previous types are also allowed. They are simply\n concatenated, separated by spaces.\n \n - `true` is passed as the string `1`, `false` and `null` are\n passed as an empty string.\n\n - The optional attribute `args` specifies command-line arguments to be\n passed to the builder. It should be a list.\n\n - The optional attribute `outputs` specifies a list of symbolic\n outputs of the derivation. By default, a derivation produces a\n single output path, denoted as `out`. However, derivations can\n produce multiple output paths. This is useful because it allows\n outputs to be downloaded or garbage-collected separately. For\n instance, imagine a library package that provides a dynamic library,\n header files, and documentation. A program that links against the\n library doesn’t need the header files and documentation at runtime,\n and it doesn’t need the documentation at build time. Thus, the\n library package could specify:\n \n ```nix\n outputs = [ \"lib\" \"headers\" \"doc\" ];\n ```\n \n This will cause Nix to pass environment variables `lib`, `headers`\n and `doc` to the builder containing the intended store paths of each\n output. The builder would typically do something like\n \n ```bash\n ./configure \\n --libdir=$lib/lib \\n --includedir=$headers/include \\n --docdir=$doc/share/doc\n ```\n \n for an Autoconf-style package. You can refer to each output of a\n derivation by selecting it as an attribute, e.g.\n \n ```nix\n buildInputs = [ pkg.lib pkg.headers ];\n ```\n \n The first element of `outputs` determines the *default output*.\n Thus, you could also write\n \n ```nix\n buildInputs = [ pkg pkg.headers ];\n ```\n \n since `pkg` is equivalent to `pkg.lib`.\n\nThe function `mkDerivation` in the Nixpkgs standard environment is a\nwrapper around `derivation` that adds a default value for `system` and\nalways uses Bash as the builder, to which the supplied builder is passed\nas a command-line argument. See the Nixpkgs manual for details.\n\nThe builder is executed as follows:\n\n - A temporary directory is created under the directory specified by\n `TMPDIR` (default `/tmp`) where the build will take place. The\n current directory is changed to this directory.\n\n - The environment is cleared and set to the derivation attributes, as\n specified above.\n\n - In addition, the following variables are set:\n \n - `NIX_BUILD_TOP` contains the path of the temporary directory for\n this build.\n \n - Also, `TMPDIR`, `TEMPDIR`, `TMP`, `TEMP` are set to point to the\n temporary directory. This is to prevent the builder from\n accidentally writing temporary files anywhere else. Doing so\n might cause interference by other processes.\n \n - `PATH` is set to `/path-not-set` to prevent shells from\n initialising it to their built-in default value.\n \n - `HOME` is set to `/homeless-shelter` to prevent programs from\n using `/etc/passwd` or the like to find the user's home\n directory, which could cause impurity. Usually, when `HOME` is\n set, it is used as the location of the home directory, even if\n it points to a non-existent path.\n \n - `NIX_STORE` is set to the path of the top-level Nix store\n directory (typically, `/nix/store`).\n \n - For each output declared in `outputs`, the corresponding\n environment variable is set to point to the intended path in the\n Nix store for that output. Each output path is a concatenation\n of the cryptographic hash of all build inputs, the `name`\n attribute and the output name. (The output name is omitted if\n it’s `out`.)\n\n - If an output path already exists, it is removed. Also, locks are\n acquired to prevent multiple Nix instances from performing the same\n build at the same time.\n\n - A log of the combined standard output and error is written to\n `/nix/var/log/nix`.\n\n - The builder is executed with the arguments specified by the\n attribute `args`. If it exits with exit code 0, it is considered to\n have succeeded.\n\n - The temporary directory is removed (unless the `-K` option was\n specified).\n\n - If the build was successful, Nix scans each output path for\n references to input paths by looking for the hash parts of the input\n paths. Since these are potential runtime dependencies, Nix registers\n them as dependencies of the output paths.\n\n - After the build, Nix sets the last-modified timestamp on all files\n in the build result to 1 (00:00:01 1/1/1970 UTC), sets the group to\n the default group, and sets the mode of the file to 0444 or 0555\n (i.e., read-only, with execute permission enabled if the file was\n originally executable). Note that possible `setuid` and `setgid`\n bits are cleared. Setuid and setgid programs are not currently\n supported by Nix. This is because the Nix archives used in\n deployment have no concept of ownership information, and because it\n makes the build result dependent on the user performing the build." + } +}