diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index 5b28b2dcb398..28388ba685d8 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -40,6 +40,24 @@ Used with Git. Expects `url` to a Git repo, `rev`, and `sha256`. `rev` in this c Additionally the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout. +If only parts of the repository are needed, `sparseCheckout` can be used. This will prevent git from fetching unnecessary blobs from server, see [git sparse-checkout](https://git-scm.com/docs/git-sparse-checkout) and [git clone --filter](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---filterltfilter-specgt) for more infomation: + +```nix +{ stdenv, fetchgit }: + +stdenv.mkDerivation { + name = "hello"; + src = fetchgit { + url = "https://..."; + sparseCheckout = '' + path/to/be/included + another/path + ''; + sha256 = "0000000000000000000000000000000000000000000000000000"; + }; +} +``` + ## `fetchfossil` {#fetchfossil} Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `sha256`. diff --git a/doc/languages-frameworks/ocaml.section.md b/doc/languages-frameworks/ocaml.section.md index d266a032268c..47035551d418 100644 --- a/doc/languages-frameworks/ocaml.section.md +++ b/doc/languages-frameworks/ocaml.section.md @@ -32,9 +32,9 @@ Given that most of the OCaml ecosystem is now built with dune, nixpkgs includes Here is a simple package example. -- It defines an (optional) attribute `minimalOCamlVersion` that will be used to - throw a descriptive evaluation error if building with an older OCaml is - attempted. +- It defines an (optional) attribute `minimalOCamlVersion` (see note below) + that will be used to throw a descriptive evaluation error if building with + an older OCaml is attempted. - It uses the `fetchFromGitHub` fetcher to get its source. @@ -117,3 +117,11 @@ buildDunePackage rec { }; } ``` + +Note about `minimalOCamlVersion`. A deprecated version of this argument was +spelled `minimumOCamlVersion`; setting the old attribute wrongly modifies the +derivation hash and is therefore inappropriate. As a technical dept, currently +packaged libraries may still use the old spelling: maintainers are invited to +fix this when updating packages. Massive renaming is strongly discouraged as it +would be challenging to review, difficult to test, and will cause unnecessary +rebuild. diff --git a/lib/default.nix b/lib/default.nix index 2dfe62e82a8b..268422538803 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -122,8 +122,9 @@ let mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule mkAliasOptionModule mkDerivedConfig doRename; inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions - mergeDefaultOption mergeOneOption mergeEqualOption getValues - getFiles optionAttrSetToDocList optionAttrSetToDocList' + mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption + getValues getFiles + optionAttrSetToDocList optionAttrSetToDocList' scrubOptionValue literalExpression literalExample literalDocBook showOption showFiles unknownModule mkOption; inherit (self.types) isType setType defaultTypeMerge defaultFunctor diff --git a/lib/options.nix b/lib/options.nix index 794ca5e33942..627aac24d2fb 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -172,11 +172,13 @@ rec { else if all isInt list && all (x: x == head list) list then head list else throw "Cannot merge definitions of `${showOption loc}'. Definition values:${showDefs defs}"; - mergeOneOption = loc: defs: - if defs == [] then abort "This case should never happen." - else if length defs != 1 then - throw "The unique option `${showOption loc}' is defined multiple times. Definition values:${showDefs defs}" - else (head defs).value; + mergeOneOption = mergeUniqueOption { message = ""; }; + + mergeUniqueOption = { message }: loc: defs: + if length defs == 1 + then (head defs).value + else assert length defs > 1; + throw "The option `${showOption loc}' is defined multiple times.\n${message}\nDefinition values:${showDefs defs}"; /* "Merge" option definitions by checking that they all have the same value. */ mergeEqualOption = loc: defs: diff --git a/lib/types.nix b/lib/types.nix index cc3ac5fdf6fb..f2f9b2bca985 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -32,7 +32,6 @@ let last length tail - unique ; inherit (lib.attrsets) attrNames @@ -48,6 +47,7 @@ let mergeDefaultOption mergeEqualOption mergeOneOption + mergeUniqueOption showFiles showOption ; @@ -470,6 +470,18 @@ rec { nestedTypes.elemType = elemType; }; + unique = { message }: type: mkOptionType rec { + name = "unique"; + inherit (type) description check; + merge = mergeUniqueOption { inherit message; }; + emptyValue = type.emptyValue; + getSubOptions = type.getSubOptions; + getSubModules = type.getSubModules; + substSubModules = m: uniq (type.substSubModules m); + functor = (defaultFunctor name) // { wrapped = type; }; + nestedTypes.elemType = type; + }; + # Null or value of ... nullOr = elemType: mkOptionType rec { name = "nullOr"; @@ -599,6 +611,7 @@ rec { # A value from a set of allowed ones. enum = values: let + inherit (lib.lists) unique; show = v: if builtins.isString v then ''"${v}"'' else if builtins.isInt v then builtins.toString v diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 78833d144b3a..6ae60956ae97 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -3545,7 +3545,7 @@ name = "Leo Maroni"; }; emmanuelrosa = { - email = "emmanuel_rosa@aol.com"; + email = "emmanuelrosa@protonmail.com"; matrix = "@emmanuelrosa:matrix.org"; github = "emmanuelrosa"; githubId = 13485450; @@ -5984,6 +5984,13 @@ githubId = 107689; name = "Josh Holland"; }; + jsierles = { + email = "joshua@hey.com"; + matrix = "@jsierles:matrix.org"; + name = "Joshua Sierles"; + github = "jsierles"; + githubId = 82; + }; jtcoolen = { email = "jtcoolen@pm.me"; name = "Julien Coolen"; @@ -6061,6 +6068,16 @@ githubId = 2396926; name = "Justin Woo"; }; + jvanbruegge = { + email = "supermanitu@gmail.com"; + github = "jvanbruegge"; + githubId = 1529052; + name = "Jan van Brügge"; + keys = [{ + longkeyid = "rsa4096/0x366572BE7D6C78A2"; + fingerprint = "3513 5CE5 77AD 711F 3825 9A99 3665 72BE 7D6C 78A2"; + }]; + }; jwatt = { email = "jwatt@broken.watch"; github = "jjwatt"; @@ -8588,6 +8605,12 @@ githubId = 7845120; name = "Alex Martens"; }; + nialov = { + email = "nikolasovaskainen@gmail.com"; + github = "nialov"; + githubId = 47318483; + name = "Nikolas Ovaskainen"; + }; nikitavoloboev = { email = "nikita.voloboev@gmail.com"; github = "nikitavoloboev"; @@ -12043,7 +12066,7 @@ name = "Tiago Castro"; }; tilcreator = { - name = "Tilman Jackel"; + name = "TilCreator"; email = "contact.nixos@tc-j.de"; matrix = "@tilcreator:matrix.org"; github = "TilCreator"; diff --git a/nixos/doc/manual/development/option-types.section.md b/nixos/doc/manual/development/option-types.section.md index ed557206659f..56ffa8e9d79c 100644 --- a/nixos/doc/manual/development/option-types.section.md +++ b/nixos/doc/manual/development/option-types.section.md @@ -250,6 +250,12 @@ Composed types are types that take a type as parameter. `listOf : Ensures that type *`t`* cannot be merged. It is used to ensure option definitions are declared only once. +`types.unique` `{ message = m }` *`t`* + +: Ensures that type *`t`* cannot be merged. Prints the message *`m`*, after + the line `The option