Skip to content

Commit

Permalink
nix: simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rycee committed Dec 6, 2024
1 parent 63eb786 commit d00c6f6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 94 deletions.
16 changes: 6 additions & 10 deletions tests/modules/misc/nix/empty-settings.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{ config, lib, pkgs, ... }:

with lib;
{ config, ... }:

{
config = {
nix = { package = config.lib.test.mkStubPackage { }; };
nix = { package = config.lib.test.mkStubPackage { }; };

nmt.script = ''
assertPathNotExists home-files/.config/nix
assertPathNotExists home-files/.nix-defexpr/50-home-manager
'';
};
nmt.script = ''
assertPathNotExists home-files/.config/nix
assertPathNotExists home-files/.nix-defexpr/50-home-manager
'';
}
28 changes: 13 additions & 15 deletions tests/modules/misc/nix/example-channels-xdg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ let
}
'';
in {
config = {
nix = {
package = config.lib.test.mkStubPackage {
version = lib.getVersion pkgs.nixVersions.stable;
};
channels.example = exampleChannel;
settings.use-xdg-base-directories = true;
nix = {
package = config.lib.test.mkStubPackage {
version = lib.getVersion pkgs.nixVersions.stable;
};

nmt.script = ''
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/home/hm-user/.local/state/nix/defexpr/50-home-manager''${NIX_PATH:+:$NIX_PATH}"'
assertFileContent \
home-files/.local/state/nix/defexpr/50-home-manager/example/default.nix \
${exampleChannel}/default.nix
'';
channels.example = exampleChannel;
settings.use-xdg-base-directories = true;
};

nmt.script = ''
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/home/hm-user/.local/state/nix/defexpr/50-home-manager''${NIX_PATH:+:$NIX_PATH}"'
assertFileContent \
home-files/.local/state/nix/defexpr/50-home-manager/example/default.nix \
${exampleChannel}/default.nix
'';
}
24 changes: 11 additions & 13 deletions tests/modules/misc/nix/example-channels.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ let
}
'';
in {
config = {
nix = {
package = config.lib.test.mkStubPackage { };
channels.example = exampleChannel;
};

nmt.script = ''
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/home/hm-user/.nix-defexpr/50-home-manager''${NIX_PATH:+:$NIX_PATH}"'
assertFileContent \
home-files/.nix-defexpr/50-home-manager/example/default.nix \
${exampleChannel}/default.nix
'';
nix = {
package = config.lib.test.mkStubPackage { };
channels.example = exampleChannel;
};

nmt.script = ''
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/home/hm-user/.nix-defexpr/50-home-manager''${NIX_PATH:+:$NIX_PATH}"'
assertFileContent \
home-files/.nix-defexpr/50-home-manager/example/default.nix \
${exampleChannel}/default.nix
'';
}
32 changes: 14 additions & 18 deletions tests/modules/misc/nix/example-registry.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
{ config, lib, pkgs, ... }:

with lib;
{ ... }:

{
config = {
nix = {
registry = {
nixpkgs = {
to = {
type = "github";
owner = "my-org";
repo = "my-nixpkgs";
};
nix = {
registry = {
nixpkgs = {
to = {
type = "github";
owner = "my-org";
repo = "my-nixpkgs";
};
};
};

nmt.script = ''
assertFileContent \
home-files/.config/nix/registry.json \
${./example-registry-expected.json}
'';
};

nmt.script = ''
assertFileContent \
home-files/.config/nix/registry.json \
${./example-registry-expected.json}
'';
}
50 changes: 23 additions & 27 deletions tests/modules/misc/nix/example-settings.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
{ config, lib, pkgs, ... }:

with lib;

{
config = {
nix = {
package = config.lib.test.mkStubPackage {
version = lib.getVersion pkgs.nixVersions.stable;
buildScript = ''
target=$out/bin/nix
mkdir -p "$(dirname "$target")"
nix = {
package = config.lib.test.mkStubPackage {
version = lib.getVersion pkgs.nixVersions.stable;
buildScript = ''
target=$out/bin/nix
mkdir -p "$(dirname "$target")"
echo -n "true" > "$target"
echo -n "true" > "$target"
chmod +x "$target"
'';
};
chmod +x "$target"
'';
};

nixPath = [ "/a" "/b/c" ];
nixPath = [ "/a" "/b/c" ];

settings = {
use-sandbox = true;
show-trace = true;
system-features = [ "big-parallel" "kvm" "recursive-nix" ];
};
settings = {
use-sandbox = true;
show-trace = true;
system-features = [ "big-parallel" "kvm" "recursive-nix" ];
};
};

nmt.script = ''
assertFileContent \
home-files/.config/nix/nix.conf \
${./example-settings-expected.conf}
nmt.script = ''
assertFileContent \
home-files/.config/nix/nix.conf \
${./example-settings-expected.conf}
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/a:/b/c''${NIX_PATH:+:$NIX_PATH}"'
'';
};
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/a:/b/c''${NIX_PATH:+:$NIX_PATH}"'
'';
}
20 changes: 9 additions & 11 deletions tests/modules/misc/nix/keep-old-nix-path.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{ config, ... }:

{
config = {
nix = {
package = config.lib.test.mkStubPackage { };
nixPath = [ "/a" "/b/c" ];
keepOldNixPath = false;
};

nmt.script = ''
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/a:/b/c"'
'';
nix = {
package = config.lib.test.mkStubPackage { };
nixPath = [ "/a" "/b/c" ];
keepOldNixPath = false;
};

nmt.script = ''
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
'export NIX_PATH="/a:/b/c"'
'';
}

0 comments on commit d00c6f6

Please sign in to comment.