696 Commits

Author SHA1 Message Date
Ethan Carter Edwards
2c2686cbbe lib.meta.getDarwinApp: init, add tests
This is useful for nix-darwin system.defaults.dock.persistent-apps

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
2026-09-20 17:17:38 -04:00
Ethan Carter Edwards
7246360b7d lib.meta.getDarwinApp': init, add tests
This is useful for nix-darwin system.defaults.dock.persistent-apps

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
2026-09-20 17:16:41 -04:00
Samuel Ainsworth
17be3e0800 lib/fileset/internal.nix: introduce lib.lists.commonPrefixLength (#507639) 2026-09-17 21:52:01 +00:00
Ryan Hendrickson
418b436480 lib.escapeShellArg: handle paths (#556219) 2026-09-15 17:03:22 +00:00
Robert Hensing
bc9263e560 lib.modules.mapAttrsOfSubmodule: init (#561282) 2026-09-14 23:33:23 +00:00
Robert Hensing
d773de213a types.path.check: Avoid derivation instantiation (#540399) 2026-09-13 17:03:09 +00:00
Robert Hensing
94072f9db5 lib/tests: make sure types.pathWith does not instantiate
See previous commit.
2026-09-13 18:56:27 +02:00
Robert Hensing
4e28ca5700 lib.types.nullOr: implement v2 check & merge (#525519) 2026-09-11 12:15:55 +00:00
Robert Hensing
c70d9ffe53 lib.modules.mapAttrsOfSubmodule: init 2026-09-08 16:19:46 +02:00
Ryan Hendrickson
c5ba1a0b3a lib.escapeShellArg: handle paths
Path values should be copied into the store if they're going to be used
in a shell script. In other words, `"my-command ${arg}"` and
`"my-command ${lib.escapeShellArg arg}"` should always do the same thing
if `arg` is a path; it should not be the case that the first is safe and
the second results in an out-of-store reference.
2026-08-24 20:10:20 -04:00
Shahar "Dawn" Or
703a4f5e00 lib.isFunction: failing test for non-function __functor
This test errors trying to call the non-function `__functor`.
2026-08-14 23:54:03 +07:00
Shahar "Dawn" Or
77f6b3a664 lib.isFunction: add tests 2026-08-14 23:42:47 +07:00
zowoq
5623c90edc lib/tests/misc: use x86_64-freebsd instead of x86_64-darwin (#535512) 2026-07-11 02:37:35 +00:00
nixpkgs-ci[bot]
0e1056cb37 Merge master into staging-next 2026-07-02 14:28:02 +00:00
Matt Sturgeon
c00644f728 Module system types.attrTag implement declaration info in options (#531031) 2026-07-02 12:38:20 +00:00
nixpkgs-ci[bot]
d8a7dfa41f Merge master into staging-next 2026-06-30 00:44:58 +00:00
Jörg Thalheim
7d940ca082 nixVersions.nix_2_28: remove
Nix 2.28 was the last release packaged with the monolithic
common-meson.nix expression and is no longer maintained upstream.
Drop it together with the now-unused common-meson.nix and nix-perl.nix
helpers and the storeDir/stateDir/confDir plumbing that only fed
that code path.
2026-06-28 20:50:31 +03:00
Emily
af8b1be8bb lib/tests/misc: use x86_64-freebsd instead of x86_64-darwin 2026-06-26 07:58:16 +01:00
nixpkgs-ci[bot]
546a6c9639 Merge staging-next into staging 2026-06-23 18:43:49 +00:00
Eman Resu
f3e6fa555f lib.attrsets.concatMapAttrs: add test for handling duplicates 2026-06-21 18:04:34 -04:00
Emily
bd83232593 lib/systems/doubles: drop x86_64-darwin
This ensures that `lib.platforms.darwin` doesn’t include
`x86_64-darwin` and that the unsupported platform check will trigger
even once the bespoke deprecation error is removed. It doesn’t break
`lib.systems.elaborate "x86_64-darwin"`.
2026-06-21 19:37:17 +01:00
Eman Resu
add81e270c lib.systems.doubles: only typecheck in CI 2026-06-20 17:05:35 -04:00
d18g
495906d50a lib.types: types.attrTag declaration info
Closes #303082
2026-06-18 15:23:42 +03:00
Johannes Kirschbauer
0cb9aa055c lib/types: remove functor.wrapped after deprecation phase of 2 full releases 2026-06-10 21:24:53 +02:00
Matt Sturgeon
9eccc1e269 lib.types.nullOr: implement v2 check & merge
Eman helped test and mitigate the performance impact, as `nullOr` is a
surprisingly hot-path in NixOS and Nixpkgs.

Co-authored-by: Eman Resu <78693624+quatquatt@users.noreply.github.com>
2026-05-29 21:30:46 +01:00
Matt Sturgeon
4a0627b1a3 lib/tests/modules.sh: Test types.nullOr mixed value error 2026-05-29 11:17:16 +01:00
adisbladis
59d55cbaa3 lib.sources.sourceByGlobs: init function
Adds a source filtering function inspired by [doublestar](https://github.com/bmatcuk/doublestar).

This has been in used in a few private repositories since the last ~6 months with success.

- Testing

This was originally tested with the nix-unit testsuite:
```
let
  inherit (import ./internal.nix) mkSourceFilter mkMatcher;
in
{
  mkMatcher = {
    empty = {
      testMatch = {
        expr = mkMatcher "" "" "regular";
        expected = true;
      };

      testNoMatch = {
        expr = mkMatcher "" "foo" "regular";
        expected = false;
      };
    };

    simple = {
      testMatch = {
        expr = mkMatcher "foo" "foo" "regular";
        expected = true;
      };

      testNoMatch = {
        expr = mkMatcher "foo" "bar" "regular";
        expected = false;
      };
    };

    singleStar = {
      testMatch = {
        expr = mkMatcher "*.js" "foo.js" "regular";
        expected = true;
      };

      testNoMatch = {
        expr = mkMatcher "*.js" "foo.py" "regular";
        expected = false;
      };
    };

    doubleStar = {
      testMatch = {
        expr = mkMatcher "foo/**/bar" "foo/baz/bar" "regular";
        expected = true;
      };

      testNoMatch = {
        expr = mkMatcher "foo/**/bar" "foo/bar/baz" "regular";
        expected = false;
      };

      testMultiMatch = {
        expr = mkMatcher "foo/**/bar" "foo/baz/xyz/bar" "regular";
        expected = true;
      };

      testMultiMatchDoubleGlob = {
        expr = mkMatcher "foo/**/**/bar" "foo/baz/xyz/bar" "regular";
        expected = true;
      };

      testInfixMatch = {
        expr = mkMatcher "foo/**/qux/**/bar" "foo/baz/qux/baz/bar" "regular";
        expected = true;
      };

      testInfixNoMatch = {
        expr = mkMatcher "foo/**/xyz/**/bar" "foo/baz/qux/baz/bar" "regular";
        expected = false;
      };

      # Technically a partial match
      testInfixDirMatch = {
        expr = mkMatcher "foo/**/xyz/**/bar" "foo/baz/qux/baz/bar" "directory";
        expected = true;
      };
    };
  };

  mkSourceFilter = {
    testSourceFilter = {
      expr = mkSourceFilter ./fixtures [
        "bar/*.js"
      ] "bar/bar.js" "regular";
      expected = true;
    };
  };
}
```
but it was dropped in this nixpkgs contribution as the structure of nixpkgs lib testing is too primitive to incorp this without more extensive refactoring than I'd like at the momment.

- Performance

It's hard to benchmark this against anything else meaningful except [globsset](https://github.com/pdtpartners/globset), which has a very similar API.

`sourceByGlobs` avoids performance pitfalls by:

  - Using `builtins.filterSource`

      This is more performant than the fileset API.
      The downside compared to the fileset API is that any directory which matches the filter will be added to the build, even if it's empty.

  - Match paths component by component

      By splitting each pattern into a token per / separator.
      This is much faster in Nix than the doublestar algorithm.

- Globset source

```json
{
    "cpuTime": 0.8585879802703857,
    "envs": {
        "bytes": 148252864,
        "elements": 11899843,
        "number": 6631765
    },
    "gc": {
        "heapSize": 402915328,
        "totalBytes": 671288560
    },
    "list": {
        "bytes": 3358664,
        "concats": 28658,
        "elements": 419833
    },
    "nrAvoided": 11562713,
    "nrFunctionCalls": 4816963,
    "nrLookups": 4316209,
    "nrOpUpdateValuesCopied": 5686407,
    "nrOpUpdates": 464060,
    "nrPrimOpCalls": 2966970,
    "nrThunks": 7796186,
    "sets": {
        "bytes": 196404672,
        "elements": 10837802,
        "number": 1437490
    },
    "sizes": {
        "Attr": 16,
        "Bindings": 16,
        "Env": 8,
        "Value": 24
    },
    "symbols": {
        "bytes": 340652,
        "number": 32026
    },
    "values": {
        "bytes": 207367440,
        "number": 8640310
    }
}
```

- Glob-filter source

```json
{
    "cpuTime": 0.3904629945755005,
    "envs": {
        "bytes": 13263440,
        "elements": 1005877,
        "number": 652053
    },
    "gc": {
        "heapSize": 402915328,
        "totalBytes": 146914896
    },
    "list": {
        "bytes": 3032168,
        "concats": 5899,
        "elements": 379021
    },
    "nrAvoided": 1666598,
    "nrFunctionCalls": 484399,
    "nrLookups": 112698,
    "nrOpUpdateValuesCopied": 3432135,
    "nrOpUpdates": 13426,
    "nrPrimOpCalls": 1041954,
    "nrThunks": 1205792,
    "sets": {
        "bytes": 64304800,
        "elements": 3978167,
        "number": 40883
    },
    "sizes": {
        "Attr": 16,
        "Bindings": 16,
        "Env": 8,
        "Value": 24
    },
    "symbols": {
        "bytes": 285306,
        "number": 28864
    },
    "values": {
        "bytes": 42963240,
        "number": 1790135
    }
}
```
2026-05-26 21:48:59 +12:00
Johannes Kirschbauer
ae142b5738 types.attrListWith: review fixes
- Improve extractItem error messages: distinguish non-attrset elements
  from multi-key attrsets, and include the faulty definition via showDefs.
- Use isType instead of raw _type access for order detection.
- Disable type merging (typeMerge = t: null) instead of providing a
  functor-based merge. Add test confirming duplicate declarations fail.
2026-05-24 15:32:04 +02:00
Robert Hensing
8aa6e3dbb9 types.attrListWith: add valueMeta.definitions 2026-05-24 15:32:04 +02:00
Robert Hensing
e29bf2412b lib.modules.mapDefinitionValue: init 2026-05-24 15:32:04 +02:00
Robert Hensing
f1b62fdc4e types.attrListWith: add asAttrs
This allows the type's return value to be accessed more easily.

Motivating use case:
- Built-in module provides CLI functionality by declaring
  an `attrListWith { asAttrs = true; }`, extracting the ordered list
  from `valueMeta` for the purpose of creating the `argv`.
- User modules can read the command line's flags directly without
  having to parse the list of attrs.
2026-05-24 15:07:05 +02:00
Robert Hensing
43d998e6c0 types.attrListOf: init
This adds a type for name-value mappings that preserve ordering.

Motivating use case: command line flags for package modules /
wrappers / modular services.
The option value can be transformed into a command line in the
correct order.
Additionally, a convenience readOnly option could be provided
to give easy introspection access to the values in an ad hoc
manner.
2026-05-24 15:07:02 +02:00
Mix
cadca751c4 lib.systems.equals: fix euqality on re-elaborated platform 2026-05-17 02:14:48 +08:00
Emily
036199b38a lib.systems.equals: only filter functions once (#513844) 2026-05-13 00:56:58 +00:00
Michael Daniels
18e82c4591 lib: remove unused let bindings and args@{} uses 2026-04-30 18:43:56 -04:00
Johannes Kirschbauer
5c9f6077a7 lib/concatLines: add test for empty list 2026-04-28 10:08:32 +02:00
Eman Resu
0f0f29fcf1 lib/systems: store version of elaborated system without functions 2026-04-26 23:56:51 -04:00
Ben Siraphob
0fcb031c25 lib/systems: add SH4 (SuperH) cross-compilation target
Add sh4 CPU type (32-bit, little-endian, family "sh"), isSh4 predicate,
"sh4-linux" system double, cross-compilation example (sh4-unknown-linux-gnu),
linuxArch mapping to "sh", and test entry.
2026-04-20 13:02:20 -07:00
Robert Hensing
77b5864637 lib.modules: submodule emptyValue must evaluate sub-option defaults
`emptyValue` for `types.submodule` was `{ value = { }; }`, i.e. none
of the type-declared options or their defaults.

Previously submodules without defs would simply fail for lack of a default,
but since PR #500104 repurposed `emptyValue` as the fallback when no
definitions exist, submodule options without an explicit `default = { }`
(new additions) silently lost their sub-option defaults
(e.g. `requiredFeatures.devnet` in the nixos-test-driver, #511413).

Main change: `emptyValue`: `{ }` -> `{ value = base.config; }`

Additionally, skip `emptyValue`-based default rendering in docs for
types with submodules, because their sub-options are already documented
individually, and forcing evaluation here can break on modules with
invalid or incomplete definitions.
2026-04-19 20:52:33 +01:00
jopejoe1
dbdb37908f lib/tests: add tests for lib.licenses 2026-04-19 12:22:11 +02:00
Alyssa Ross
4cd3a0ec79 lib/systems: add ARC cross-compilation target (#510160) 2026-04-15 15:51:26 +00:00
Ben Siraphob
6152e8cbfa lib/systems: add ARC (Synopsys DesignWare ARC) cross-compilation support
Add arc CPU type (32-bit, little-endian, family "arc"), isArc
predicate, arc-linux double, arc cross example with
arc-unknown-linux-gnu triple, and release-cross job.

ARC has glibc support and uses the "arc" Linux kernel arch, which
matches the CPU name so no explicit linuxArch mapping is needed.
2026-04-14 13:51:11 -07:00
Johannes Kirschbauer
dbe18bc16d lib.types.defaultTypeMerge: Fix for functors with no wrapped attr (#476219) 2026-04-14 07:15:44 +00:00
Robert Hensing
8d4e372952 lib.types: add types.option (#499945) 2026-04-08 13:41:10 +00:00
Samuel Ainsworth
45f2fdec4a lib/fileset/internal.nix: nixfmt 2026-04-07 11:50:34 -04:00
Samuel Ainsworth
9a70ebfb14 lib/fileset/internal.nix: introduce lib.lists.commonPrefixLength
Extracts the existing length-computation logic from `commonPrefix` into
its own function so callers that only need the length can avoid the
intermediate list allocation. `commonPrefix` is reimplemented in terms
of the new function. Updates the two TODOs in `lib/fileset/internal.nix`
that were waiting for this.
2026-04-07 11:42:49 -04:00
Robert Hensing
17c056fa24 lib.types.optionDeclaration: test error 2026-04-03 10:53:47 +02:00
cinereal
7334dd9096 lib.types: add types.option
Signed-off-by: cinereal <cinereal@riseup.net>
2026-04-02 12:10:29 +02:00
Robert Hensing
ff011b00be lib/modules: Improve errors involving pushDownProperties (#502117) 2026-04-01 16:00:01 +00:00
Timothy Gallion
f32c37b88c lib.types.defaultTypeMerge: Fix for functors with no wrapped attr
Downstream types that want to use `lib.types.defaultTypeMerge` must include
`wrapped` even though it is deprecated or the internal
`wrappedDeprecationMessage`. This is caused by accessing the
`wrapped` attr in `lib.types.defaultTypeMerge`. The logic should first check
if the attr exists and then if it does check if it is null.
2026-03-29 15:14:00 -04:00