···639 unmatchedDefns = [];
640 }
641 else if optionDecls != [] then
642- if all (x: x.options.type.name == "submodule") optionDecls
643 # Raw options can only be merged into submodules. Merging into
644 # attrsets might be nice, but ambiguous. Suppose we have
645 # attrset as a `attrsOf submodule`. User declares option
···639 unmatchedDefns = [];
640 }
641 else if optionDecls != [] then
642+ if all (x: x.options.type.name or null == "submodule") optionDecls
643 # Raw options can only be merged into submodules. Merging into
644 # attrsets might be nice, but ambiguous. Suppose we have
645 # attrset as a `attrsOf submodule`. User declares option
+49
lib/path/default.nix
···271 second argument: "${toString path2}" with root "${toString path2Deconstructed.root}"'';
272 joinRelPath components;
2730000000000000000000000000000000000000000000000274 /* Whether a value is a valid subpath string.
000275276 - The value is a string
277
···271 second argument: "${toString path2}" with root "${toString path2Deconstructed.root}"'';
272 joinRelPath components;
273274+ /*
275+ Split the filesystem root from a [path](https://nixos.org/manual/nix/stable/language/values.html#type-path).
276+ The result is an attribute set with these attributes:
277+ - `root`: The filesystem root of the path, meaning that this directory has no parent directory.
278+ - `subpath`: The [normalised subpath string](#function-library-lib.path.subpath.normalise) that when [appended](#function-library-lib.path.append) to `root` returns the original path.
279+280+ Laws:
281+ - [Appending](#function-library-lib.path.append) the `root` and `subpath` gives the original path:
282+283+ p ==
284+ append
285+ (splitRoot p).root
286+ (splitRoot p).subpath
287+288+ - Trying to get the parent directory of `root` using [`readDir`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-readDir) returns `root` itself:
289+290+ dirOf (splitRoot p).root == (splitRoot p).root
291+292+ Type:
293+ splitRoot :: Path -> { root :: Path, subpath :: String }
294+295+ Example:
296+ splitRoot /foo/bar
297+ => { root = /.; subpath = "./foo/bar"; }
298+299+ splitRoot /.
300+ => { root = /.; subpath = "./."; }
301+302+ # Nix neutralises `..` path components for all path values automatically
303+ splitRoot /foo/../bar
304+ => { root = /.; subpath = "./bar"; }
305+306+ splitRoot "/foo/bar"
307+ => <error>
308+ */
309+ splitRoot = path:
310+ assert assertMsg
311+ (isPath path)
312+ "lib.path.splitRoot: Argument is of type ${typeOf path}, but a path was expected";
313+ let
314+ deconstructed = deconstructPath path;
315+ in {
316+ root = deconstructed.root;
317+ subpath = joinRelPath deconstructed.components;
318+ };
319+320 /* Whether a value is a valid subpath string.
321+322+ A subpath string points to a specific file or directory within an absolute base directory.
323+ It is a stricter form of a relative path that excludes `..` components, since those could escape the base directory.
324325 - The value is a string
326
+18-1
lib/path/tests/unit.nix
···3{ libpath }:
4let
5 lib = import libpath;
6- inherit (lib.path) hasPrefix removePrefix append subpath;
78 cases = lib.runTests {
9 # Test examples from the lib.path.append documentation
···72 testRemovePrefixExample4 = {
73 expr = removePrefix /. /foo;
74 expected = "./foo";
0000000000000000075 };
7677 # Test examples from the lib.path.subpath.isValid documentation
···371 config.set \
372 ./declare-set.nix ./declare-enable-nested.nix
373374+# Check that that merging of option collisions doesn't depend on type being set
375+checkConfigError 'The option .group..*would be a parent of the following options, but its type .<no description>. does not support nested options.\n\s*- option.s. with prefix .group.enable..*' config.group.enable ./merge-typeless-option.nix
376+377# Test that types.optionType merges types correctly
378checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix
379checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix
···199 gnome.adwaita-icon-theme
200 gtk3.out # for gtk-launch program
201 onboard
0202 qgnomeplatform
203 sound-theme-freedesktop
204 xdg-user-dirs # Update user dirs as described in http://freedesktop.org/wiki/Software/xdg-user-dirs/
···199 gnome.adwaita-icon-theme
200 gtk3.out # for gtk-launch program
201 onboard
202+ orca # elementary/greeter#668
203 qgnomeplatform
204 sound-theme-freedesktop
205 xdg-user-dirs # Update user dirs as described in http://freedesktop.org/wiki/Software/xdg-user-dirs/
···18 # There appears to be a similar problem with metakernel's tests
19 doCheck = false;
2021- meta = with lib; {
22 description = "A Jupyter kernel for Octave.";
23 homepage = "https://github.com/Calysto/octave_kernel";
24- license = licenses.bsd3;
25- maintainers = with maintainers; [ thomasjm ];
26- platforms = platforms.all;
27 };
28}
···18 # There appears to be a similar problem with metakernel's tests
19 doCheck = false;
2021+ meta = {
22 description = "A Jupyter kernel for Octave.";
23 homepage = "https://github.com/Calysto/octave_kernel";
24+ license = lib.licenses.bsd3;
25+ maintainers = with lib.maintainers; [ thomasjm ];
26+ platforms = lib.platforms.all;
27 };
28}
···242243244 */
245- writeScriptBin = name: text: writeTextFile {inherit name text; executable = true; destination = "/bin/${name}";};
0000246247 /*
248 Similar to writeScript. Writes a Shell script and checks its syntax.
···374 # Pointless to do this on a remote machine.
375 preferLocalBuild = true;
376 allowSubstitutes = false;
000377 }
378 ''
379 n=$out/bin/$name
···242243244 */
245+ writeScriptBin = name: text: writeTextFile {
246+ inherit name text;
247+ executable = true;
248+ destination = "/bin/${name}";
249+ };
250251 /*
252 Similar to writeScript. Writes a Shell script and checks its syntax.
···378 # Pointless to do this on a remote machine.
379 preferLocalBuild = true;
380 allowSubstitutes = false;
381+ meta = {
382+ mainProgram = name;
383+ };
384 }
385 ''
386 n=$out/bin/$name
···1-{ writeTextFile }:
000000000002let
3 veryWeirdName = ''here's a name with some "bad" characters, like spaces and quotes'';
4-in writeTextFile {
5- name = "weird-names";
6- destination = "/etc/${veryWeirdName}";
7- text = ''passed!'';
8- checkPhase = ''
9- # intentionally hardcode everything here, to make sure
10- # Nix does not mess with file paths
00000000000000000000000001112- name="here's a name with some \"bad\" characters, like spaces and quotes"
13- fullPath="$out/etc/$name"
1415- if [ -f "$fullPath" ]; then
16- echo "[PASS] File exists!"
17- else
18- echo "[FAIL] File was not created at expected path!"
19- exit 1
20- fi
2122- content=$(<"$fullPath")
23- expected="passed!"
2425- if [ "$content" = "$expected" ]; then
26- echo "[PASS] Contents match!"
27- else
28- echo "[FAIL] File contents don't match!"
29- echo " Expected: $expected"
30- echo " Got: $content"
31- exit 2
32- fi
33- '';
034}
···1+/*
2+ To run:
3+4+ cd nixpkgs
5+ nix-build -A tests.trivial-builders.writeTextFile
6+7+ or to run an individual test case
8+9+ cd nixpkgs
10+ nix-build -A tests.trivial-builders.writeTextFile.foo
11+*/
12+{ lib, runCommand, runtimeShell, writeTextFile }:
13let
14 veryWeirdName = ''here's a name with some "bad" characters, like spaces and quotes'';
15+in
16+lib.recurseIntoAttrs {
17+18+ different-exe-name =
19+ let
20+ pkg = writeTextFile {
21+ name = "bar";
22+ destination = "/bin/foo";
23+ executable = true;
24+ text = ''
25+ #!${runtimeShell}
26+ echo hi
27+ '';
28+ };
29+ in
30+ assert pkg.meta.mainProgram == "foo";
31+ assert baseNameOf (lib.getExe pkg) == "foo";
32+ assert pkg.name == "bar";
33+ runCommand "test-writeTextFile-different-exe-name" {} ''
34+ PATH="${lib.makeBinPath [ pkg ]}:$PATH"
35+ x=$(foo)
36+ [[ "$x" == hi ]]
37+ touch $out
38+ '';
39+40+ weird-name = writeTextFile {
41+ name = "weird-names";
42+ destination = "/etc/${veryWeirdName}";
43+ text = ''passed!'';
44+ checkPhase = ''
45+ # intentionally hardcode everything here, to make sure
46+ # Nix does not mess with file paths
4748+ name="here's a name with some \"bad\" characters, like spaces and quotes"
49+ fullPath="$out/etc/$name"
5051+ if [ -f "$fullPath" ]; then
52+ echo "[PASS] File exists!"
53+ else
54+ echo "[FAIL] File was not created at expected path!"
55+ exit 1
56+ fi
5758+ content=$(<"$fullPath")
59+ expected="passed!"
6061+ if [ "$content" = "$expected" ]; then
62+ echo "[PASS] Contents match!"
63+ else
64+ echo "[FAIL] File contents don't match!"
65+ echo " Expected: $expected"
66+ echo " Got: $content"
67+ exit 2
68+ fi
69+ '';
70+ };
71}
···19 "-X main.version=${version}"
20 ];
2122- passthru.updateScript = nix-update-script {
23- attrPath = pname;
24- };
2526 meta = with lib; {
27 description = "A tool to simplify storing secrets that should be accessible in the shell environment in your git repo.";
···19 "-X main.version=${version}"
20 ];
2122+ passthru.updateScript = nix-update-script { };
002324 meta = with lib; {
25 description = "A tool to simplify storing secrets that should be accessible in the shell environment in your git repo.";