1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +01:00

tests: various minor cleanups

This commit is contained in:
Robert Helgesson 2023-05-13 00:08:12 +02:00
parent 19c509a6fa
commit eec2272999
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
41 changed files with 680 additions and 747 deletions

View file

@ -1,17 +1,13 @@
{ config, lib, ... }: { ... }:
with lib;
{ {
config = { home.file."executable" = {
home.file."executable" = { text = "";
text = ""; executable = true;
executable = true;
};
nmt.script = ''
assertFileExists home-files/executable
assertFileIsExecutable home-files/executable;
'';
}; };
nmt.script = ''
assertFileExists home-files/executable
assertFileIsExecutable home-files/executable;
'';
} }

View file

@ -1,19 +1,15 @@
{ config, lib, ... }: { ... }:
with lib;
{ {
config = { home.file.".hidden".source = ./.hidden;
home.file.".hidden".source = ./.hidden;
nmt.script = '' nmt.script = ''
assertFileExists home-files/.hidden; assertFileExists home-files/.hidden;
assertFileContent home-files/.hidden ${ assertFileContent home-files/.hidden ${
builtins.path { builtins.path {
path = ./.hidden; path = ./.hidden;
name = "expected"; name = "expected";
}
} }
''; }
}; '';
} }

View file

@ -1,29 +1,25 @@
{ config, lib, ... }: { config, ... }:
with lib;
let let
filePath = ./. + "/source with spaces!"; filePath = ./. + "/source with spaces!";
in { in {
config = { home.file."oos".source = config.lib.file.mkOutOfStoreSymlink filePath;
home.file."oos".source = config.lib.file.mkOutOfStoreSymlink filePath;
nmt.script = '' nmt.script = ''
assertLinkExists "home-files/oos" assertLinkExists "home-files/oos"
storePath="$(readlink $TESTED/home-files/oos)" storePath="$(readlink $TESTED/home-files/oos)"
if [[ ! -L $storePath ]]; then if [[ ! -L $storePath ]]; then
fail "Expected $storePath to be a symbolic link, but it was not." fail "Expected $storePath to be a symbolic link, but it was not."
fi fi
actual="$(readlink "$storePath")" actual="$(readlink "$storePath")"
expected="${toString filePath}" expected="${toString filePath}"
if [[ $actual != $expected ]]; then if [[ $actual != $expected ]]; then
fail "Symlink home-files/oos should point to $expected via the Nix store, but it actually points to $actual." fail "Symlink home-files/oos should point to $expected via the Nix store, but it actually points to $actual."
fi fi
''; '';
};
} }

View file

@ -1,20 +1,16 @@
{ config, lib, ... }: { ... }:
with lib;
{ {
config = { home.file."source with spaces!".source = ./. + "/source with spaces!";
home.file."source with spaces!".source = ./. + "/source with spaces!";
nmt.script = '' nmt.script = ''
assertFileExists 'home-files/source with spaces!'; assertFileExists 'home-files/source with spaces!';
assertFileContent 'home-files/source with spaces!' \ assertFileContent 'home-files/source with spaces!' \
${ ${
builtins.path { builtins.path {
path = ./. + "/source with spaces!"; path = ./. + "/source with spaces!";
name = "source-with-spaces-expected"; name = "source-with-spaces-expected";
}
} }
''; }
}; '';
} }

View file

@ -1,26 +1,24 @@
{ ... }: { ... }:
{ {
config = { home.file = {
home.file = { conflict1 = {
conflict1 = { text = "";
text = ""; target = "baz";
target = "baz"; };
}; conflict2 = {
conflict2 = { source = ./target-conflict.nix;
source = ./target-conflict.nix; target = "baz";
target = "baz";
};
}; };
test.asserts.assertions.expected = [''
Conflicting managed target files: baz
This may happen, for example, if you have a configuration similar to
home.file = {
conflict1 = { source = ./foo.nix; target = "baz"; };
conflict2 = { source = ./bar.nix; target = "baz"; };
}''];
}; };
test.asserts.assertions.expected = [''
Conflicting managed target files: baz
This may happen, for example, if you have a configuration similar to
home.file = {
conflict1 = { source = ./foo.nix; target = "baz"; };
conflict2 = { source = ./bar.nix; target = "baz"; };
}''];
} }

View file

@ -1,15 +1,11 @@
{ config, lib, pkgs, ... }: { ... }:
with lib;
{ {
config = { home.file."$HOME/$FOO/bar baz".text = "blah";
home.file."$HOME/$FOO/bar baz".text = "blah";
nmt.script = '' nmt.script = ''
assertFileExists 'home-files/$HOME/$FOO/bar baz'; assertFileExists 'home-files/$HOME/$FOO/bar baz';
assertFileContent 'home-files/$HOME/$FOO/bar baz' \ assertFileContent 'home-files/$HOME/$FOO/bar baz' \
${pkgs.writeText "expected" "blah"} ${builtins.toFile "expected" "blah"}
''; '';
};
} }

View file

@ -1,18 +1,14 @@
{ config, lib, ... }: { ... }:
with lib;
{ {
config = { home.file."using-text".text = ''
home.file."using-text".text = '' This is the
This is the expected text.
expected text. '';
'';
nmt.script = '' nmt.script = ''
assertFileExists home-files/using-text assertFileExists home-files/using-text
assertFileIsNotExecutable home-files/using-text assertFileIsNotExecutable home-files/using-text
assertFileContent home-files/using-text ${./text-expected.txt} assertFileContent home-files/using-text ${./text-expected.txt}
''; '';
};
} }

View file

@ -1,116 +1,116 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
let let
boolToString = bool: if bool then "true" else "false"; boolToString = bool: if bool then "true" else "false";
backups = config.programs.borgmatic.backups; backups = config.programs.borgmatic.backups;
in { in {
config = { programs.borgmatic = {
programs.borgmatic = { enable = true;
enable = true; backups = {
backups = { main = {
main = { location = {
location = { sourceDirectories = [ "/my-stuff-to-backup" ];
sourceDirectories = [ "/my-stuff-to-backup" ]; repositories = [ "/mnt/disk1" "/mnt/disk2" ];
repositories = [ "/mnt/disk1" "/mnt/disk2" ]; extraConfig = {
extraConfig = { one_file_system = true;
one_file_system = true; exclude_patterns = [ "*.swp" ];
exclude_patterns = [ "*.swp" ];
};
}; };
};
storage = { storage = {
encryptionPasscommand = "fetch-the-password.sh"; encryptionPasscommand = "fetch-the-password.sh";
extraConfig = { checkpoint_interval = 200; }; extraConfig = { checkpoint_interval = 200; };
}; };
retention = { retention = {
keepWithin = "14d"; keepWithin = "14d";
keepSecondly = 12; keepSecondly = 12;
extraConfig = { prefix = "hostname"; }; extraConfig = { prefix = "hostname"; };
}; };
consistency = { consistency = {
checks = [ checks = [
{ {
name = "repository"; name = "repository";
frequency = "2 weeks"; frequency = "2 weeks";
} }
{ {
name = "archives"; name = "archives";
frequency = "4 weeks"; frequency = "4 weeks";
} }
]; ];
extraConfig = { prefix = "hostname"; }; extraConfig = { prefix = "hostname"; };
};
}; };
}; };
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
declare -A expectations
expectations[location.source_directories[0]]="${
builtins.elemAt backups.main.location.sourceDirectories 0
}"
expectations[location.repositories[0]]="${
builtins.elemAt backups.main.location.repositories 0
}"
expectations[location.repositories[1]]="${
builtins.elemAt backups.main.location.repositories 1
}"
expectations[location.one_file_system]="${
boolToString backups.main.location.extraConfig.one_file_system
}"
expectations[location.exclude_patterns[0]]="${
builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0
}"
expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
expectations[storage.checkpoint_interval]="${
toString backups.main.storage.extraConfig.checkpoint_interval
}"
expectations[retention.keep_within]="${backups.main.retention.keepWithin}"
expectations[retention.keep_secondly]="${
toString backups.main.retention.keepSecondly
}"
expectations[retention.prefix]="${backups.main.retention.extraConfig.prefix}"
expectations[consistency.checks[0].name]="${
(builtins.elemAt backups.main.consistency.checks 0).name
}"
expectations[consistency.checks[0].frequency]="${
(builtins.elemAt backups.main.consistency.checks 0).frequency
}"
expectations[consistency.checks[1].name]="${
(builtins.elemAt backups.main.consistency.checks 1).name
}"
expectations[consistency.checks[1].frequency]="${
(builtins.elemAt backups.main.consistency.checks 1).frequency
}"
expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}"
yq=${pkgs.yq-go}/bin/yq
for filter in "''${!expectations[@]}"; do
expected_value="''${expectations[$filter]}"
actual_value="$($yq ".$filter" $config_file)"
if [[ "$actual_value" != "$expected_value" ]]; then
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
fi
done
one_file_system=$($yq ".location.one_file_system" $config_file)
if [[ $one_file_system != "true" ]]; then
fail "Expected one_file_system to be true but it was $one_file_system"
fi
'';
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
declare -A expectations
expectations[location.source_directories[0]]="${
builtins.elemAt backups.main.location.sourceDirectories 0
}"
expectations[location.repositories[0]]="${
builtins.elemAt backups.main.location.repositories 0
}"
expectations[location.repositories[1]]="${
builtins.elemAt backups.main.location.repositories 1
}"
expectations[location.one_file_system]="${
boolToString backups.main.location.extraConfig.one_file_system
}"
expectations[location.exclude_patterns[0]]="${
builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0
}"
expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
expectations[storage.checkpoint_interval]="${
toString backups.main.storage.extraConfig.checkpoint_interval
}"
expectations[retention.keep_within]="${backups.main.retention.keepWithin}"
expectations[retention.keep_secondly]="${
toString backups.main.retention.keepSecondly
}"
expectations[retention.prefix]="${backups.main.retention.extraConfig.prefix}"
expectations[consistency.checks[0].name]="${
(builtins.elemAt backups.main.consistency.checks 0).name
}"
expectations[consistency.checks[0].frequency]="${
(builtins.elemAt backups.main.consistency.checks 0).frequency
}"
expectations[consistency.checks[1].name]="${
(builtins.elemAt backups.main.consistency.checks 1).name
}"
expectations[consistency.checks[1].frequency]="${
(builtins.elemAt backups.main.consistency.checks 1).frequency
}"
expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}"
yq=${pkgs.yq-go}/bin/yq
for filter in "''${!expectations[@]}"; do
expected_value="''${expectations[$filter]}"
actual_value="$($yq ".$filter" $config_file)"
if [[ "$actual_value" != "$expected_value" ]]; then
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
fi
done
one_file_system=$($yq ".location.one_file_system" $config_file)
if [[ $one_file_system != "true" ]]; then
fail "Expected one_file_system to be true but it was $one_file_system"
fi
'';
} }

View file

@ -1,40 +1,40 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
let let
backups = config.programs.borgmatic.backups; backups = config.programs.borgmatic.backups;
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar"; excludeFile = builtins.toFile "excludeFile.txt" "/foo/bar";
in { in {
config = { programs.borgmatic = {
programs.borgmatic = { enable = true;
enable = true; backups = {
backups = { main = {
main = { location = {
location = { sourceDirectories = [ "/my-stuff-to-backup" ];
sourceDirectories = [ "/my-stuff-to-backup" ]; repositories = [ "/mnt/disk1" ];
repositories = [ "/mnt/disk1" ]; excludeHomeManagerSymlinks = true;
excludeHomeManagerSymlinks = true;
};
}; };
}; };
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
yq=${pkgs.yq-go}/bin/yq
hmExclusionsFile=$($yq '.location.exclude_from[0]' $config_file)
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
grep --quiet "$expected_content" "$hmExclusionsFile"
if [[ $? -ne 0 ]]; then
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
exit 1
fi
'';
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
yq=${pkgs.yq-go}/bin/yq
hmExclusionsFile=$($yq '.location.exclude_from[0]' $config_file)
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
grep --quiet "$expected_content" "$hmExclusionsFile"
if [[ $? -ne 0 ]]; then
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
exit 1
fi
'';
} }

View file

@ -1,54 +1,54 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
let let
backups = config.programs.borgmatic.backups; backups = config.programs.borgmatic.backups;
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar"; excludeFile = builtins.toFile "excludeFile.txt" "/foo/bar";
in { in {
config = { programs.borgmatic = {
programs.borgmatic = { enable = true;
enable = true; backups = {
backups = { main = {
main = { location = {
location = { sourceDirectories = [ "/my-stuff-to-backup" ];
sourceDirectories = [ "/my-stuff-to-backup" ]; repositories = [ "/mnt/disk1" ];
repositories = [ "/mnt/disk1" ]; excludeHomeManagerSymlinks = true;
excludeHomeManagerSymlinks = true; extraConfig = { exclude_from = [ (toString excludeFile) ]; };
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
};
}; };
}; };
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
declare -A expectations
expectations[location.exclude_from[0]]="${excludeFile}"
yq=${pkgs.yq-go}/bin/yq
for filter in "''${!expectations[@]}"; do
expected_value="''${expectations[$filter]}"
actual_value="$($yq ".$filter" $config_file)"
if [[ "$actual_value" != "$expected_value" ]]; then
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
fi
done
hmExclusionsFile=$($yq '.location.exclude_from[1]' $config_file)
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
grep --quiet "$expected_content" "$hmExclusionsFile"
if [[ $? -ne 0 ]]; then
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
exit 1
fi
'';
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
declare -A expectations
expectations[location.exclude_from[0]]="${excludeFile}"
yq=${pkgs.yq-go}/bin/yq
for filter in "''${!expectations[@]}"; do
expected_value="''${expectations[$filter]}"
actual_value="$($yq ".$filter" $config_file)"
if [[ "$actual_value" != "$expected_value" ]]; then
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
fi
done
hmExclusionsFile=$($yq '.location.exclude_from[1]' $config_file)
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
grep --quiet "$expected_content" "$hmExclusionsFile"
if [[ $? -ne 0 ]]; then
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
exit 1
fi
'';
} }

View file

@ -1,45 +1,45 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
let let
backups = config.programs.borgmatic.backups; backups = config.programs.borgmatic.backups;
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar"; excludeFile = builtins.toFile "excludeFile.txt" "/foo/bar";
in { in {
config = { programs.borgmatic = {
programs.borgmatic = { enable = true;
enable = true; backups = {
backups = { main = {
main = { location = {
location = { sourceDirectories = [ "/my-stuff-to-backup" ];
sourceDirectories = [ "/my-stuff-to-backup" ]; repositories = [ "/mnt/disk1" ];
repositories = [ "/mnt/disk1" ]; excludeHomeManagerSymlinks = false;
excludeHomeManagerSymlinks = false; extraConfig = { exclude_from = [ (toString excludeFile) ]; };
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
};
}; };
}; };
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
declare -A expectations
expectations[location.exclude_from[0]]="${excludeFile}"
yq=${pkgs.yq-go}/bin/yq
for filter in "''${!expectations[@]}"; do
expected_value="''${expectations[$filter]}"
actual_value="$($yq ".$filter" $config_file)"
if [[ "$actual_value" != "$expected_value" ]]; then
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
fi
done
'';
}; };
test.stubs.borgmatic = { };
nmt.script = ''
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
assertFileExists $config_file
declare -A expectations
expectations[location.exclude_from[0]]="${excludeFile}"
yq=${pkgs.yq-go}/bin/yq
for filter in "''${!expectations[@]}"; do
expected_value="''${expectations[$filter]}"
actual_value="$($yq ".$filter" $config_file)"
if [[ "$actual_value" != "$expected_value" ]]; then
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
fi
done
'';
} }

View file

@ -1,19 +1,17 @@
{ config, pkgs, ... }: { ... }:
{ {
config = { services.barrier.client = {
services.barrier.client = { enable = true;
enable = true; server = "testServer";
server = "testServer";
};
test.stubs.barrier = { };
nmt.script = ''
clientServiceFile=home-files/.config/systemd/user/barrierc.service
assertFileExists $clientServiceFile
assertFileRegex $clientServiceFile 'ExecStart=.*/bin/barrierc -f testServer'
'';
}; };
test.stubs.barrier = { };
nmt.script = ''
clientServiceFile=home-files/.config/systemd/user/barrierc.service
assertFileExists $clientServiceFile
assertFileRegex $clientServiceFile 'ExecStart=.*/bin/barrierc -f testServer'
'';
} }

View file

@ -1,37 +1,37 @@
{ config, pkgs, ... }: { { ... }:
config = {
services.devilspie2 = {
enable = true;
config = '' {
if (get_window_class() == "Gnome-terminal") then services.devilspie2 = {
make_always_on_top(); enable = true;
end
if string.match(get_window_name(), "LibreOffice Writer") then config = ''
maximize(); if (get_window_class() == "Gnome-terminal") then
end make_always_on_top();
end
if (get_window_class()=="Org.gnome.Nautilus") then if string.match(get_window_name(), "LibreOffice Writer") then
set_window_geometry(1600,300,900,700); maximize();
end end
'';
};
test.stubs.devilspie2 = { }; if (get_window_class()=="Org.gnome.Nautilus") then
set_window_geometry(1600,300,900,700);
nmt.script = '' end
configlua=home-files/.config/devilspie2/config.lua
assertFileExists $configlua
assertFileContent $configlua ${./config.lua}
serviceFile=home-files/.config/systemd/user/devilspie2.service
assertFileExists $serviceFile
assertFileRegex $serviceFile 'ExecStart=.*/bin/devilspie2'
''; '';
}; };
test.stubs.devilspie2 = { };
nmt.script = ''
configlua=home-files/.config/devilspie2/config.lua
assertFileExists $configlua
assertFileContent $configlua ${./config.lua}
serviceFile=home-files/.config/systemd/user/devilspie2.service
assertFileExists $serviceFile
assertFileRegex $serviceFile 'ExecStart=.*/bin/devilspie2'
'';
} }

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { pkgs, ... }:
{ {
nixpkgs.overlays = [ nixpkgs.overlays = [

View file

@ -1,38 +1,37 @@
{ config, lib, pkgs, ... }: { lib, pkgs, ... }:
with lib;
{ {
config = { nixpkgs.overlays = [
nixpkgs.overlays = [ (self: super: rec {
(self: super: rec { emacs = pkgs.writeShellScriptBin "dummy-emacs-27.2" "" // {
emacs = pkgs.writeShellScriptBin "dummy-emacs-27.2" "" // { outPath = "@emacs@";
outPath = "@emacs@"; };
}; emacsPackagesFor = _:
emacsPackagesFor = _: lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); })
}) ];
];
programs.emacs.enable = true; programs.emacs.enable = true;
services.emacs.enable = true; services.emacs.enable = true;
services.emacs.client.enable = true; services.emacs.client.enable = true;
services.emacs.extraOptions = [ "-f" "exwm-enable" ]; services.emacs.extraOptions = [ "-f" "exwm-enable" ];
nmt.script = '' nmt.script = ''
assertPathNotExists home-files/.config/systemd/user/emacs.socket assertPathNotExists home-files/.config/systemd/user/emacs.socket
assertFileExists home-files/.config/systemd/user/emacs.service assertFileExists home-files/.config/systemd/user/emacs.service
assertFileExists home-path/share/applications/emacsclient.desktop assertFileExists home-path/share/applications/emacsclient.desktop
assertFileContent home-files/.config/systemd/user/emacs.service \ assertFileContent \
${ home-files/.config/systemd/user/emacs.service \
pkgs.substituteAll { ${
inherit (pkgs) runtimeShell; pkgs.substituteAll {
src = ./emacs-service-emacs.service; inherit (pkgs) runtimeShell;
} src = ./emacs-service-emacs.service;
} }
assertFileContent home-path/share/applications/emacsclient.desktop \ }
${./emacs-27-emacsclient.desktop}
''; assertFileContent \
}; home-path/share/applications/emacsclient.desktop \
${./emacs-27-emacsclient.desktop}
'';
} }

View file

@ -1,40 +1,38 @@
{ config, lib, pkgs, ... }: { lib, pkgs, ... }:
with lib;
{ {
config = { nixpkgs.overlays = [
nixpkgs.overlays = [ (self: super: rec {
(self: super: rec { emacs = pkgs.writeShellScriptBin "dummy-emacs-28.2" "" // {
emacs = pkgs.writeShellScriptBin "dummy-emacs-28.2" "" // { outPath = "@emacs@";
outPath = "@emacs@"; };
}; emacsPackagesFor = _:
emacsPackagesFor = _: lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); })
}) ];
];
programs.emacs.enable = true; programs.emacs.enable = true;
services.emacs.enable = true; services.emacs.enable = true;
services.emacs.client.enable = true; services.emacs.client.enable = true;
services.emacs.extraOptions = [ "-f" "exwm-enable" ]; services.emacs.extraOptions = [ "-f" "exwm-enable" ];
services.emacs.startWithUserSession = "graphical"; services.emacs.startWithUserSession = "graphical";
nmt.script = '' nmt.script = ''
assertPathNotExists home-files/.config/systemd/user/emacs.socket assertPathNotExists home-files/.config/systemd/user/emacs.socket
assertFileExists home-files/.config/systemd/user/emacs.service assertFileExists home-files/.config/systemd/user/emacs.service
assertFileExists home-path/share/applications/emacsclient.desktop assertFileExists home-path/share/applications/emacsclient.desktop
assertFileContent home-files/.config/systemd/user/emacs.service \ assertFileContent \
${ home-files/.config/systemd/user/emacs.service \
pkgs.substituteAll { ${
inherit (pkgs) runtimeShell; pkgs.substituteAll {
src = inherit (pkgs) runtimeShell;
./emacs-service-emacs-after-graphical-session-target.service; src = ./emacs-service-emacs-after-graphical-session-target.service;
} }
} }
assertFileContent home-path/share/applications/emacsclient.desktop \
${./emacs-28-emacsclient.desktop} assertFileContent \
''; home-path/share/applications/emacsclient.desktop \
}; ${./emacs-28-emacsclient.desktop}
'';
} }

View file

@ -1,6 +1,4 @@
{ config, lib, pkgs, ... }: { lib, pkgs, ... }:
with lib;
{ {
config = { config = {
@ -10,7 +8,7 @@ with lib;
outPath = "@emacs@"; outPath = "@emacs@";
}; };
emacsPackagesFor = _: emacsPackagesFor = _:
makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
}) })
]; ];
@ -24,15 +22,18 @@ with lib;
assertFileExists home-files/.config/systemd/user/emacs.service assertFileExists home-files/.config/systemd/user/emacs.service
assertFileExists home-path/share/applications/emacsclient.desktop assertFileExists home-path/share/applications/emacsclient.desktop
assertFileContent home-files/.config/systemd/user/emacs.service \ assertFileContent \
${ home-files/.config/systemd/user/emacs.service \
pkgs.substituteAll { ${
inherit (pkgs) runtimeShell; pkgs.substituteAll {
src = ./emacs-service-emacs.service; inherit (pkgs) runtimeShell;
} src = ./emacs-service-emacs.service;
} }
assertFileContent home-path/share/applications/emacsclient.desktop \ }
${./emacs-28-emacsclient.desktop}
assertFileContent \
home-path/share/applications/emacsclient.desktop \
${./emacs-28-emacsclient.desktop}
''; '';
}; };
} }

View file

@ -1,10 +1,6 @@
{ config, lib, pkgs, ... }: { lib, pkgs, ... }:
with lib; {
let
in {
config = { config = {
nixpkgs.overlays = [ nixpkgs.overlays = [
(self: super: rec { (self: super: rec {
@ -12,7 +8,7 @@ in {
outPath = "@emacs@"; outPath = "@emacs@";
}; };
emacsPackagesFor = _: emacsPackagesFor = _:
makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
}) })
]; ];
@ -27,17 +23,22 @@ in {
assertFileExists home-files/.config/systemd/user/emacs.service assertFileExists home-files/.config/systemd/user/emacs.service
assertFileExists home-path/share/applications/emacsclient.desktop assertFileExists home-path/share/applications/emacsclient.desktop
assertFileContent home-files/.config/systemd/user/emacs.socket \ assertFileContent \
${./emacs-socket-emacs.socket} home-files/.config/systemd/user/emacs.socket \
assertFileContent home-files/.config/systemd/user/emacs.service \ ${./emacs-socket-emacs.socket}
${
pkgs.substituteAll { assertFileContent \
inherit (pkgs) runtimeShell coreutils; home-files/.config/systemd/user/emacs.service \
src = ./emacs-socket-emacs.service; ${
} pkgs.substituteAll {
} inherit (pkgs) runtimeShell coreutils;
assertFileContent home-path/share/applications/emacsclient.desktop \ src = ./emacs-socket-emacs.service;
${./emacs-27-emacsclient.desktop} }
}
assertFileContent \
home-path/share/applications/emacsclient.desktop \
${./emacs-27-emacsclient.desktop}
''; '';
}; };
} }

View file

@ -1,10 +1,6 @@
{ config, lib, pkgs, ... }: { lib, pkgs, ... }:
with lib; {
let
in {
config = { config = {
nixpkgs.overlays = [ nixpkgs.overlays = [
(self: super: rec { (self: super: rec {
@ -12,7 +8,7 @@ in {
outPath = "@emacs@"; outPath = "@emacs@";
}; };
emacsPackagesFor = _: emacsPackagesFor = _:
makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
}) })
]; ];
@ -27,17 +23,22 @@ in {
assertFileExists home-files/.config/systemd/user/emacs.service assertFileExists home-files/.config/systemd/user/emacs.service
assertFileExists home-path/share/applications/emacsclient.desktop assertFileExists home-path/share/applications/emacsclient.desktop
assertFileContent home-files/.config/systemd/user/emacs.socket \ assertFileContent \
${./emacs-socket-emacs.socket} home-files/.config/systemd/user/emacs.socket \
assertFileContent home-files/.config/systemd/user/emacs.service \ ${./emacs-socket-emacs.socket}
${
pkgs.substituteAll { assertFileContent \
inherit (pkgs) runtimeShell coreutils; home-files/.config/systemd/user/emacs.service \
src = ./emacs-socket-emacs.service; ${
} pkgs.substituteAll {
} inherit (pkgs) runtimeShell coreutils;
assertFileContent home-path/share/applications/emacsclient.desktop \ src = ./emacs-socket-emacs.service;
${./emacs-28-emacsclient.desktop} }
}
assertFileContent \
home-path/share/applications/emacsclient.desktop \
${./emacs-28-emacsclient.desktop}
''; '';
}; };
} }

View file

@ -1,7 +1,5 @@
{ lib, pkgs, ... }: { lib, pkgs, ... }:
with lib;
{ {
services.emacs = { services.emacs = {
enable = true; enable = true;
@ -15,7 +13,7 @@ with lib;
outPath = "@emacs@"; outPath = "@emacs@";
}; };
emacsPackagesFor = _: emacsPackagesFor = _:
makeScope super.newScope (_: { emacsWithPackages = _: emacs; }); lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
}) })
]; ];

View file

@ -1,13 +1,11 @@
{ ... }: { ... }:
{ {
config = { services.flameshot = { enable = true; };
services.flameshot = { enable = true; };
test.stubs.flameshot = { }; test.stubs.flameshot = { };
nmt.script = '' nmt.script = ''
assertPathNotExists home-files/.config/flameshot/flameshot.ini assertPathNotExists home-files/.config/flameshot/flameshot.ini
''; '';
};
} }

View file

@ -1,30 +1,28 @@
{ ... }: { ... }:
{ {
config = { services.flameshot = {
services.flameshot = { enable = true;
enable = true;
settings = { settings = {
General = { General = {
disabledTrayIcon = true; disabledTrayIcon = true;
showStartupLaunchMessage = false; showStartupLaunchMessage = false;
};
}; };
}; };
test.stubs.flameshot = { };
nmt.script = ''
assertFileContent \
home-files/.config/flameshot/flameshot.ini \
${
builtins.toFile "expected.ini" ''
[General]
disabledTrayIcon=true
showStartupLaunchMessage=false
''
}
'';
}; };
test.stubs.flameshot = { };
nmt.script = ''
assertFileContent \
home-files/.config/flameshot/flameshot.ini \
${
builtins.toFile "expected.ini" ''
[General]
disabledTrayIcon=true
showStartupLaunchMessage=false
''
}
'';
} }

View file

@ -1,25 +1,25 @@
{ config, pkgs, ... }: { { ... }:
config = {
services.fluidsynth.enable = true;
services.fluidsynth.soundService = "pipewire-pulse";
services.fluidsynth.soundFont = "/path/to/soundFont";
services.fluidsynth.extraOptions = [ "--sample-rate 96000" ];
test.stubs.fluidsynth = { }; {
services.fluidsynth.enable = true;
services.fluidsynth.soundService = "pipewire-pulse";
services.fluidsynth.soundFont = "/path/to/soundFont";
services.fluidsynth.extraOptions = [ "--sample-rate 96000" ];
nmt.script = '' test.stubs.fluidsynth = { };
serviceFile=home-files/.config/systemd/user/fluidsynth.service
assertFileExists $serviceFile nmt.script = ''
serviceFile=home-files/.config/systemd/user/fluidsynth.service
assertFileContains $serviceFile \ assertFileExists $serviceFile
'ExecStart=@fluidsynth@/bin/fluidsynth -a pulseaudio -si --sample-rate 96000 /path/to/soundFont'
assertFileContains $serviceFile \ assertFileContains $serviceFile \
'After=pipewire-pulse.service' 'ExecStart=@fluidsynth@/bin/fluidsynth -a pulseaudio -si --sample-rate 96000 /path/to/soundFont'
assertFileContains $serviceFile \ assertFileContains $serviceFile \
'BindsTo=pipewire-pulse.service' 'After=pipewire-pulse.service'
'';
}; assertFileContains $serviceFile \
'BindsTo=pipewire-pulse.service'
'';
} }

View file

@ -1,34 +1,30 @@
{ config, lib, pkgs, ... }: { ... }:
with lib;
{ {
imports = [ ../../accounts/email-test-accounts.nix ]; imports = [ ../../accounts/email-test-accounts.nix ];
config = { services.lieer.enable = true;
services.lieer.enable = true;
accounts.email.accounts = { accounts.email.accounts = {
"hm@example.com" = { "hm@example.com" = {
flavor = "gmail.com"; flavor = "gmail.com";
lieer = { lieer = {
enable = true; enable = true;
sync.enable = true; sync.enable = true;
};
notmuch.enable = true;
}; };
notmuch.enable = true;
}; };
test.stubs.lieer = { };
nmt.script = ''
assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.service
assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.timer
assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.service \
${./lieer-service-expected.service}
assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.timer \
${./lieer-service-expected.timer}
'';
}; };
test.stubs.lieer = { };
nmt.script = ''
assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.service
assertFileExists home-files/.config/systemd/user/lieer-hm-example-com.timer
assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.service \
${./lieer-service-expected.service}
assertFileContent home-files/.config/systemd/user/lieer-hm-example-com.timer \
${./lieer-service-expected.timer}
'';
} }

View file

@ -1,47 +1,42 @@
{ lib, pkgs, ... }: { pkgs, ... }:
with lib;
{ {
config = { xsession.windowManager.bspwm = {
xsession.windowManager.bspwm = { enable = true;
enable = true; monitors.focused = [ "desktop 1" "d'esk top" ]; # pathological desktop names
monitors.focused = alwaysResetDesktops = false;
[ "desktop 1" "d'esk top" ]; # pathological desktop names settings = {
alwaysResetDesktops = false; border_width = 2;
settings = { split_ratio = 0.52;
border_width = 2; gapless_monocle = true;
split_ratio = 0.52; external_rules_command = "/path/to/external rules command";
gapless_monocle = true; ignore_ewmh_fullscreen = [ "enter" "exit" ];
external_rules_command = "/path/to/external rules command";
ignore_ewmh_fullscreen = [ "enter" "exit" ];
};
rules."*" = {
sticky = true;
center = false;
desktop = "d'esk top#next";
splitDir = "north";
border = null;
unknownRule = 42;
};
extraConfigEarly = ''
extra config early
'';
extraConfig = ''
extra config
'';
startupPrograms = [ "foo" "bar || qux" ];
}; };
rules."*" = {
test.stubs.bspwm = { }; sticky = true;
center = false;
nmt.script = '' desktop = "d'esk top#next";
bspwmrc=home-files/.config/bspwm/bspwmrc splitDir = "north";
assertFileExists "$bspwmrc" border = null;
assertFileIsExecutable "$bspwmrc" unknownRule = 42;
assertFileContent "$bspwmrc" ${ };
pkgs.writeShellScript "bspwmrc-expected" (readFile ./bspwmrc) extraConfigEarly = ''
} extra config early
''; '';
extraConfig = ''
extra config
'';
startupPrograms = [ "foo" "bar || qux" ];
}; };
test.stubs.bspwm = { };
nmt.script = ''
bspwmrc=home-files/.config/bspwm/bspwmrc
assertFileExists "$bspwmrc"
assertFileIsExecutable "$bspwmrc"
assertFileContent "$bspwmrc" ${
pkgs.writeShellScript "bspwmrc-expected" (builtins.readFile ./bspwmrc)
}
'';
} }

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { ... }:
{ {
imports = [ ./i3-stubs.nix ]; imports = [ ./i3-stubs.nix ];

View file

@ -1,31 +1,27 @@
{ config, lib, ... }: { ... }:
with lib;
{ {
config = { xsession.windowManager.i3 = {
xsession.windowManager.i3 = { enable = true;
enable = true;
config.focus.followMouse = false; config.focus.followMouse = false;
};
nixpkgs.overlays = [
(self: super: {
dmenu = super.dmenu // { outPath = "@dmenu@"; };
i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; };
i3-gaps = super.writeScriptBin "i3" "" // { outPath = "@i3-gaps@"; };
i3status = super.i3status // { outPath = "@i3status@"; };
})
];
nmt.script = ''
assertFileExists home-files/.config/i3/config
assertFileContent home-files/.config/i3/config \
${./i3-followmouse-expected.conf}
'';
}; };
nixpkgs.overlays = [
(self: super: {
dmenu = super.dmenu // { outPath = "@dmenu@"; };
i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; };
i3-gaps = super.writeScriptBin "i3" "" // { outPath = "@i3-gaps@"; };
i3status = super.i3status // { outPath = "@i3status@"; };
})
];
nmt.script = ''
assertFileExists home-files/.config/i3/config
assertFileContent home-files/.config/i3/config \
${./i3-followmouse-expected.conf}
'';
} }

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { ... }:
{ {
imports = [ ./i3-stubs.nix ]; imports = [ ./i3-stubs.nix ];

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { ... }:
{ {
imports = [ ./i3-stubs.nix ]; imports = [ ./i3-stubs.nix ];

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { ... }:
{ {
imports = [ ./i3-stubs.nix ]; imports = [ ./i3-stubs.nix ];
@ -11,6 +11,6 @@
nmt.script = '' nmt.script = ''
assertFileExists home-files/.config/i3/config assertFileExists home-files/.config/i3/config
assertFileContent home-files/.config/i3/config \ assertFileContent home-files/.config/i3/config \
${pkgs.writeText "expected" ""} ${builtins.toFile "expected" ""}
''; '';
} }

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { ... }:
{ {
imports = [ ./i3-stubs.nix ]; imports = [ ./i3-stubs.nix ];

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { ... }:
let let
i3 = { i3 = {

View file

@ -1,6 +1,4 @@
{ config, lib, pkgs, ... }: { config, pkgs, ... }:
with lib;
{ {
imports = [ ./sway-stubs.nix ]; imports = [ ./sway-stubs.nix ];

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = [ ./sway-stubs.nix ]; imports = [ ./sway-stubs.nix ];

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = [ ./sway-stubs.nix ]; imports = [ ./sway-stubs.nix ];

View file

@ -1,15 +1,13 @@
{ config, lib, pkgs, ... }: { ... }:
{ {
config = { wayland.windowManager.sway.swaynag = {
wayland.windowManager.sway.swaynag = { enable = true;
enable = true;
settings = { }; settings = { };
};
nmt.script = ''
assertPathNotExists home-files/.config/swaynag
'';
}; };
nmt.script = ''
assertPathNotExists home-files/.config/swaynag
'';
} }

View file

@ -1,23 +1,19 @@
{ config, lib, pkgs, ... }: { lib, ... }:
with lib;
{ {
config = { home.username = lib.mkForce "root";
home.username = mkForce "root";
systemd.user.services."test-service@" = { systemd.user.services."test-service@" = {
Unit = { Description = "A basic test service"; }; Unit = { Description = "A basic test service"; };
Service = { Service = {
Environment = [ "VAR1=1" "VAR2=2" ]; Environment = [ "VAR1=1" "VAR2=2" ];
ExecStart = ''/some/exec/start/command --with-arguments "%i"''; ExecStart = ''/some/exec/start/command --with-arguments "%i"'';
};
}; };
nmt.script = ''
serviceFile=home-files/.config/systemd/user/test-service@.service
assertPathNotExists $serviceFile
'';
}; };
nmt.script = ''
serviceFile=home-files/.config/systemd/user/test-service@.service
assertPathNotExists $serviceFile
'';
} }

View file

@ -5,33 +5,31 @@ let
echo "Just a test" echo "Just a test"
''; '';
in { in {
config = { systemd.user.services."test-service@" = {
systemd.user.services."test-service@" = { Unit = { Description = "A basic test service"; };
Unit = { Description = "A basic test service"; };
Service = { Service = {
Environment = [ "VAR1=1" "VAR2=2" ]; Environment = [ "VAR1=1" "VAR2=2" ];
ExecStartPre = drvScript; ExecStartPre = drvScript;
ExecStart = ''/some/exec/start/command --with-arguments "%i"''; ExecStart = ''/some/exec/start/command --with-arguments "%i"'';
};
}; };
nmt.script = ''
serviceFile=home-files/.config/systemd/user/test-service@.service
assertFileExists $serviceFile
assertFileContent $serviceFile \
${
pkgs.writeText "services-expected.conf" ''
[Service]
Environment=VAR1=1
Environment=VAR2=2
ExecStart=/some/exec/start/command --with-arguments "%i"
ExecStartPre=${drvScript}
[Unit]
Description=A basic test service
''
}
'';
}; };
nmt.script = ''
serviceFile=home-files/.config/systemd/user/test-service@.service
assertFileExists $serviceFile
assertFileContent $serviceFile \
${
pkgs.writeText "services-expected.conf" ''
[Service]
Environment=VAR1=1
Environment=VAR2=2
ExecStart=/some/exec/start/command --with-arguments "%i"
ExecStartPre=${drvScript}
[Unit]
Description=A basic test service
''
}
'';
} }

View file

@ -1,26 +1,24 @@
{ config, lib, pkgs, ... }: { pkgs, ... }:
{ {
config = { systemd.user.sessionVariables = {
systemd.user.sessionVariables = { V_int = 1;
V_int = 1; V_str = "2";
V_str = "2";
};
nmt.script = ''
envFile=home-files/.config/environment.d/10-home-manager.conf
assertFileExists $envFile
assertFileContent $envFile ${
pkgs.writeText "expected" ''
LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive
V_int=1
V_str=2
XDG_CACHE_HOME=/home/hm-user/.cache
XDG_CONFIG_HOME=/home/hm-user/.config
XDG_DATA_HOME=/home/hm-user/.local/share
XDG_STATE_HOME=/home/hm-user/.local/state
''
}
'';
}; };
nmt.script = ''
envFile=home-files/.config/environment.d/10-home-manager.conf
assertFileExists $envFile
assertFileContent $envFile ${
pkgs.writeText "expected" ''
LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive
V_int=1
V_str=2
XDG_CACHE_HOME=/home/hm-user/.cache
XDG_CONFIG_HOME=/home/hm-user/.config
XDG_DATA_HOME=/home/hm-user/.local/share
XDG_STATE_HOME=/home/hm-user/.local/state
''
}
'';
} }

View file

@ -1,31 +1,27 @@
{ config, lib, pkgs, ... }: { ... }:
with lib;
{ {
config = { systemd.user.slices.app-test = {
systemd.user.slices.app-test = { Unit = { Description = "Slice for a test app"; };
Unit = { Description = "Slice for a test app"; };
Slice = { Slice = {
MemoryHigh = "30%"; MemoryHigh = "30%";
MemoryMax = "40%"; MemoryMax = "40%";
};
}; };
nmt.script = ''
sliceFile=home-files/.config/systemd/user/app-test.slice
assertFileExists $sliceFile
assertFileContent $sliceFile ${
builtins.toFile "app-test-expected.conf" ''
[Slice]
MemoryHigh=30%
MemoryMax=40%
[Unit]
Description=Slice for a test app
''
}
'';
}; };
nmt.script = ''
sliceFile=home-files/.config/systemd/user/app-test.slice
assertFileExists $sliceFile
assertFileContent $sliceFile ${
builtins.toFile "app-test-expected.conf" ''
[Slice]
MemoryHigh=30%
MemoryMax=40%
[Unit]
Description=Slice for a test app
''
}
'';
} }

View file

@ -1,25 +1,21 @@
{ config, lib, pkgs, ... }: { ... }:
with lib;
{ {
config = { systemd.user.timers.test-timer = {
systemd.user.timers.test-timer = { Unit = { Description = "A basic test timer"; };
Unit = { Description = "A basic test timer"; };
Timer = { OnUnitActiveSec = "1h 30m"; }; Timer = { OnUnitActiveSec = "1h 30m"; };
Install = { WantedBy = [ "timers.target" ]; }; Install = { WantedBy = [ "timers.target" ]; };
};
nmt.script = ''
unitDir=home-files/.config/systemd/user
timerFile=$unitDir/test-timer.timer
assertFileExists $timerFile
assertFileContent $timerFile ${./timers-expected.conf}
assertFileExists $unitDir/timers.target.wants/test-timer.timer
'';
}; };
nmt.script = ''
unitDir=home-files/.config/systemd/user
timerFile=$unitDir/test-timer.timer
assertFileExists $timerFile
assertFileContent $timerFile ${./timers-expected.conf}
assertFileExists $unitDir/timers.target.wants/test-timer.timer
'';
} }