2022-08-16 16:09:27 +03:00
|
|
|
# Copyright 2022 Julie Bettens
|
2021-08-06 22:50:56 +03:00
|
|
|
#
|
|
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
# copyright notice and this permission notice appear in all copies.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2021-08-03 23:06:02 +03:00
|
|
|
inputs@{ self, nixpkgs, ... }: system:
|
|
|
|
|
|
|
|
with nixpkgs.legacyPackages.${system};
|
|
|
|
with self.packages.${system};
|
|
|
|
let
|
|
|
|
# need a fixed-output copy of nixpkgs for offline use and reproducibility
|
|
|
|
pinned-nixpkgs = fetchFromGitHub {
|
|
|
|
owner = "NixOS";
|
|
|
|
repo = "nixpkgs";
|
|
|
|
rev = "21.05";
|
|
|
|
sha256 = "sha256-ZjBd81a6J3TwtlBr3rHsZspYUwT9OdhDk+a/SgSEf7I=";
|
|
|
|
};
|
|
|
|
|
|
|
|
mkTest = { name, testScript }: nixosTest {
|
|
|
|
inherit name;
|
2022-06-13 22:11:47 +03:00
|
|
|
nodes.machine = {
|
2021-08-02 17:33:59 +03:00
|
|
|
environment.systemPackages = [
|
2022-08-08 17:34:05 +03:00
|
|
|
miniguest
|
2021-08-02 17:33:59 +03:00
|
|
|
];
|
2022-06-04 00:19:26 +03:00
|
|
|
system.extraDependencies = [ pinned-nixpkgs (import pinned-nixpkgs { inherit system; }).stdenvNoCC ];
|
2021-08-03 23:06:02 +03:00
|
|
|
virtualisation.memorySize = 1024;
|
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
machine.copy_from_host("${data/flake1}", "/tmp/flake1")
|
|
|
|
machine.succeed("""
|
|
|
|
cat > /tmp/flake1/params.json << EOF
|
|
|
|
${builtins.toJSON { inherit system; }}
|
|
|
|
EOF
|
|
|
|
# override nixpkgs
|
2022-06-04 00:19:26 +03:00
|
|
|
${nixFlakes}/bin/nix --experimental-features "nix-command flakes" flake update /tmp/flake1 --override-input nixpkgs ${pinned-nixpkgs}
|
2021-08-03 23:06:02 +03:00
|
|
|
""");
|
|
|
|
'' + testScript;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.optionalAttrs stdenv.isLinux {
|
|
|
|
install_dummy = mkTest {
|
|
|
|
name = "miniguest-install-dummy";
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest install /tmp/flake1#dummy
|
|
|
|
""")
|
|
|
|
assert "foo" in machine.succeed("""
|
|
|
|
cat /etc/miniguests/dummy/boot/init
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-08-20 00:42:24 +03:00
|
|
|
install_dummy_force = mkTest {
|
|
|
|
name = "miniguest-install-dummy-force";
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest install -f /tmp/flake1#dummy
|
|
|
|
""")
|
|
|
|
assert "foo" in machine.succeed("""
|
|
|
|
cat /etc/miniguests/dummy/boot/init
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
install_dummy_twice = mkTest {
|
|
|
|
name = "miniguest-install-dummy-twice";
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest install /tmp/flake1#dummy
|
|
|
|
""")
|
|
|
|
assert "--force" in machine.fail("""
|
|
|
|
miniguest install /tmp/flake1#dummy 2>&1
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
install_dummy_twice_force = mkTest {
|
|
|
|
name = "miniguest-install-dummy-twice-force";
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest install /tmp/flake1#dummy
|
|
|
|
""")
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest install --force /tmp/flake1#dummy
|
|
|
|
""")
|
|
|
|
assert "foo" in machine.succeed("""
|
|
|
|
cat /etc/miniguests/dummy/boot/init
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-09-29 21:46:08 +03:00
|
|
|
install_rename = mkTest {
|
|
|
|
name = "miniguest-install-rename";
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("""
|
2022-08-08 17:34:05 +03:00
|
|
|
miniguest install --name renamed_dummy /tmp/flake1#dummy
|
2021-09-29 21:46:08 +03:00
|
|
|
""")
|
|
|
|
assert "foo" in machine.succeed("""
|
|
|
|
cat /etc/miniguests/renamed_dummy/boot/init
|
|
|
|
""")
|
|
|
|
assert "/nix/var/nix/profiles/miniguest-profiles/renamed_dummy\n" == machine.succeed("""
|
|
|
|
readlink /etc/miniguests/renamed_dummy
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-08-03 23:06:02 +03:00
|
|
|
install_nonexistent = mkTest {
|
|
|
|
name = "miniguest-install-nonexistent";
|
|
|
|
testScript = ''
|
|
|
|
machine.fail("""
|
|
|
|
miniguest install /tmp/flake1#nonexistent
|
|
|
|
""")
|
|
|
|
machine.succeed("""
|
|
|
|
test ! -e /etc/miniguests/nonexistent
|
|
|
|
""")
|
|
|
|
machine.succeed("""
|
|
|
|
test ! -e /nix/var/nix/miniguest-profiles/nonexistent
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
2021-08-08 13:26:39 +03:00
|
|
|
|
|
|
|
remove_dummy = mkTest {
|
|
|
|
name = "miniguest-remove-dummy";
|
|
|
|
testScript = ''
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest install /tmp/flake1#dummy
|
|
|
|
""")
|
|
|
|
machine.succeed("""
|
|
|
|
miniguest remove dummy
|
|
|
|
""")
|
|
|
|
machine.succeed("""
|
|
|
|
test ! -e /etc/miniguests/nonexistent
|
|
|
|
""")
|
|
|
|
machine.succeed("""
|
|
|
|
test ! -e /nix/var/nix/miniguest-profiles/nonexistent
|
|
|
|
""")
|
|
|
|
'';
|
|
|
|
};
|
2021-08-03 23:06:02 +03:00
|
|
|
}
|