Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake: groundwork for VM tests #5

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 15
reviewers:
- NotAShelf
assignees:
- NotAShelf
41 changes: 41 additions & 0 deletions .github/workflows/vm-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run VM tests

on:
workflow_call:
pull_request:
push:
branches:
- main
jobs:
nix:
strategy:
matrix:
system:
- x86_64-linux
- aarch64-linux

runs-on: ubuntu-latest
steps:
- name: "Set up QEMU support"
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
with:
diagnostic-endpoint: "" # no personalized self-merges tyvm.
logger: pretty
extra-conf: |
experimental-features = nix-command flakes
allow-import-from-derivation = false
extra-platforms = aarch64-linux

- name: Checkout
uses: actions/checkout@v4

# For now, only a basic test exists and thus we only build that. In the future
# we may consider chaining matrix.system and matrix.check to build more tests
# for each individual system.
- name: Build packages
run: nix build -L .#checks.${{ matrix.system }}.hjem-basic -v
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Nix build/test artifacts
.nixos-test-history
result*
38 changes: 0 additions & 38 deletions checks/default.nix

This file was deleted.

15 changes: 12 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
self,
nixpkgs,
...
} @ inputs: {
}: let
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"];
in {
nixosModules = {
hjem = ./modules/nixos.nix;
default = self.nixosModules.hjem;
};

checks = import ./checks {inherit inputs;};
checks = forAllSystems (system: let
checkArgs = {
inherit self;
pkgs = nixpkgs.legacyPackages.${system};
};
in {
hjem-basic = import ./tests/basic.nix checkArgs;
});

formatter = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"] (system: nixpkgs.legacyPackages.${system}.alejandra);
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
};
}
55 changes: 55 additions & 0 deletions tests/basic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
let
userHome = "/home/alice";
in
(import ./lib.nix) {
name = "hjem-basic";
nodes = {
node1 = {
self,
pkgs,
...
}: {
imports = [self.nixosModules.hjem];

users.groups.alice = {};
users.users.alice = {
isNormalUser = true;
home = userHome;
password = "";
};

homes = {
alice = {
enable = true;
packages = [pkgs.hello];
files.".config/foo" = {
text = "Hello world!";
};
};
};

# Also test systemd-tmpfiles internally
systemd.user.tmpfiles = {
rules = [
"d %h/user_tmpfiles_created"
];

users.alice.rules = [
"d %h/only_alice"
];
};
};
};

testScript = ''
machine.succeed("loginctl enable-linger alice")
machine.wait_until_succeeds("systemctl --user --machine=alice@ is-active systemd-tmpfiles-setup.service")

# Test file created by Hjem
machine.succeed("[ -L ~alice/.config/foo ]")

# Test regular files, created by systemd-tmpfiles
machine.succeed("[ -d ~alice/user_tmpfiles_created ]")
machine.succeed("[ -d ~alice/only_alice ]")
'';
}
17 changes: 17 additions & 0 deletions tests/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The first argument to this function is the test module itself
test: {
pkgs,
self,
}: let
inherit (pkgs) lib;
nixos-lib = import (pkgs.path + "/nixos/lib") {};
in
(nixos-lib.runTest {
hostPkgs = pkgs;
defaults.documentation.enable = lib.mkDefault false;

node.specialArgs = {inherit self;};
imports = [test];
})
.config
.result
Loading