Skip to content

Commit

Permalink
flake 2
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyroussel committed Oct 29, 2023
1 parent 3314cc2 commit a64df59
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 80 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/nix-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@ on:
jobs:
package-build:
runs-on: ubuntu-latest
strategy:
matrix:
channel:
- nixos-23.05
- nixos-unstable
env:
NIXPKGS_ALLOW_UNFREE: 1
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=channel:${{ matrix.channel }}
- uses: DeterminateSystems/nix-installer-action@v6
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix-shell .github/shadow-packages.nix
- run: nix flake check
10 changes: 2 additions & 8 deletions .github/workflows/update-upstream-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=channel:nixos-23.05

- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v6
- uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Configure Git author and create branch
Expand Down
3 changes: 3 additions & 0 deletions checks/hmTests/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
shadow-client = ./shadow-client.nix;
}
28 changes: 28 additions & 0 deletions checks/hmTests/shadow-client.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ ... }:

{
programs = {
awscli = {
enable = true;
settings = {
default = {
output = "json";
region = "eu-west-3";
};
};
credentials = { iam = { credential_process = "pass show aws"; }; };
};
};

test.stubs.awscli2 = { };

nmt.script = ''
assertFileExists home-files/.aws/config
assertFileContent home-files/.aws/config \
${./aws-config.conf}
assertFileExists home-files/.aws/credentials
assertFileContent home-files/.aws/credentials \
${./aws-credentials.conf}
'';
}
55 changes: 55 additions & 0 deletions checks/nixosTests/auto.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ config, lib, ... }:

let
dmcfg = config.services.xserver.displayManager;
cfg = config.test-support.displayManager.auto;
in
{

###### interface

options = {
test-support.displayManager.auto = {
enable = lib.mkOption {
default = false;
description = lib.mdDoc ''
Whether to enable the fake "auto" display manager, which
automatically logs in the user specified in the
{option}`user` option. This is mostly useful for
automated tests.
'';
};

user = lib.mkOption {
default = "root";
description = lib.mdDoc "The user account to login automatically.";
};
};
};

###### implementation

config = lib.mkIf cfg.enable {
services.xserver.displayManager = {
lightdm.enable = true;
autoLogin = {
enable = true;
user = cfg.user;
};
};

# lightdm by default doesn't allow auto login for root, which is
# required by some nixos tests. Override it here.
security.pam.services.lightdm-autologin.text = lib.mkForce ''
auth requisite pam_nologin.so
auth required pam_succeed_if.so quiet
auth required pam_permit.so
account include lightdm
password include lightdm
session include lightdm
'';
};
}
67 changes: 30 additions & 37 deletions checks/nixosTests/shadow-client.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,44 @@ pkgs.testers.runNixOSTest ({ lib, ... }: {

nodes.machine = { pkgs, ... }: {
imports = [
./x11.nix
../../modules/nixos/shadow-nix
];
services.acme-dns = {
enable = true;
settings = {
general = rec {
domain = "acme-dns.home.arpa";
nsname = domain;
nsadmin = "admin.home.arpa";
records = [
"${domain}. A 127.0.0.1"
"${domain}. AAAA ::1"
"${domain}. NS ${domain}."
];
};
logconfig.loglevel = "debug";
};
};
environment.systemPackages = with pkgs; [ curl bind ];
};

testScript = ''
import json
machine.wait_for_unit("acme-dns.service")
machine.wait_for_open_port(53) # dns
machine.wait_for_open_port(8080) # http api
# Provides the `vainfo` command
environment.systemPackages = with pkgs; [ libva-utils ];

result = machine.succeed("curl --fail -X POST http://localhost:8080/register")
print(result)
# Hardware hybrid decoding
# nixpkgs.config.packageOverrides = pkgs: {
# vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
# };

registration = json.loads(result)
# Hardware drivers
hardware.opengl = {
enable = true;
extraPackages = with pkgs; [
vaapiIntel
vaapiVdpau
libvdpau-va-gl
intel-media-driver
];
};

machine.succeed(f'dig -t TXT @localhost {registration["fulldomain"]} | grep "SOA" | grep "admin.home.arpa"')
programs.shadow-client = {
enable = true;
channel = "prod";
};
};

# acme-dns exspects a TXT value string length of exactly 43 chars
txt = "___dummy_validation_token_for_txt_record___"
# enableOCR = true;

machine.succeed(
"curl --fail -X POST http://localhost:8080/update "
+ f' -H "X-Api-User: {registration["username"]}"'
+ f' -H "X-Api-Key: {registration["password"]}"'
+ f' -d \'{{"subdomain":"{registration["subdomain"]}", "txt":"{txt}"}}\'''
)
testScript = ''
machine.wait_for_x()
assert txt in machine.succeed(f'dig -t TXT +short @localhost {registration["fulldomain"]}')
machine.execute("shadow-prod >&2 &")
# machine.wait_for_window("Shadow PC")
# machine.wait_for_text(r"(New Game|Start Server|Load Game|Help Manual|Join Game|About|Play Online)")
machine.sleep(10)
machine.screenshot("screen")
'';
})
17 changes: 17 additions & 0 deletions checks/nixosTests/x11.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ lib, ... }:

{
imports = [
./auto.nix
];

services.xserver.enable = true;

# Automatically log in.
test-support.displayManager.auto.enable = true;

# Use IceWM as the window manager.
# Don't use a desktop manager.
services.xserver.displayManager.defaultSession = lib.mkDefault "none+icewm";
services.xserver.windowManager.icewm.enable = true;
}
47 changes: 41 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
home-manager.url = "github:nix-community/home-manager";
};

outputs = inputs@{ flake-parts, ... }:
Expand Down
18 changes: 0 additions & 18 deletions import/.drirc

This file was deleted.

2 changes: 1 addition & 1 deletion modules/hm/shadow-nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ in {
] ++ lib.forEach cfg.extraChannels shadow-package;

# Add GPU fixes
file.".drirc".source = lib.mkIf (cfg.enableGpuFix) ../.drirc;
file.".drirc".source = lib.mkIf (cfg.enableGpuFix) ../../.drirc;

# Force VA Driver
sessionVariables.LIBVA_DRIVER_NAME = toString cfg.forceDriver;
Expand Down
2 changes: 1 addition & 1 deletion modules/nixos/shadow-nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ in {
] ++ lib.forEach cfg.extraChannels shadow-package;

# Add GPU fixes
etc.drirc.source = lib.mkIf (cfg.enableGpuFix) ../.drirc;
etc.drirc.source = lib.mkIf (cfg.enableGpuFix) ../../.drirc;

# Force VA Driver
variables.LIBVA_DRIVER_NAME = lib.mkIf (cfg.forceDriver != null) [ cfg.forceDriver ];
Expand Down

0 comments on commit a64df59

Please sign in to comment.