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

feat: migrate to flake #108

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 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 --impure
12 changes: 3 additions & 9 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 All @@ -28,7 +22,7 @@ jobs:
git checkout -b update-shadow-channels

- name: Update Upstream information file
run: ./update.py --commit
run: ./packages/shadow-nix/update.py --commit

- name: Push branch
run: git push origin update-shadow-channels -f
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# IDE
.vscode
.idea

# Exclude `nix build` output directory
result
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
'';
};
}
48 changes: 48 additions & 0 deletions checks/nixosTests/shadow-client.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ pkgs, ... }:

pkgs.testers.runNixOSTest ({ lib, ... }: {
name = "shadow-client";

nodes.machine = { pkgs, ... }: {
imports = [
./x11.nix
../../modules/nixos/shadow-nix
];

# Provides the `vainfo` command
environment.systemPackages = with pkgs; [ libva-utils ];

# Hardware hybrid decoding
# nixpkgs.config.packageOverrides = pkgs: {
# vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
# };

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

programs.shadow-client = {
enable = true;
channel = "prod";
};
};

# enableOCR = true;

testScript = ''
machine.wait_for_x()

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;
}
99 changes: 99 additions & 0 deletions flake.lock

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

52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
description = "Supporting Shadow Gaming under NixOS";

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, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];


perSystem = { config, self', inputs', pkgs, system, ... }: {
packages = {
shadow-prod = pkgs.callPackage ./packages/shadow-nix {
channel = "prod";
enableDiagnostics = true;
enableDesktopLauncher = true;
};

shadow-preprod = pkgs.callPackage ./packages/shadow-nix {
channel = "preprod";
enableDiagnostics = true;
enableDesktopLauncher = true;
};

shadow-testing = pkgs.callPackage ./packages/shadow-nix {
channel = "testing";
enableDiagnostics = true;
enableDesktopLauncher = true;
};
};

checks = {
nixosTests-shadow-client = pkgs.callPackage ./checks/nixosTests/shadow-client.nix {};
};
};

flake = {
hmModules = {
shadow-client = ./modules/hm/shadow-nix;
};

nixosModules = {
shadow-client = ./modules/nixos/shadow-nix;
};
};
};

}
File renamed without changes.
File renamed without changes.
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
8 changes: 5 additions & 3 deletions import/system.nix → modules/nixos/shadow-nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ let
cfg = config.programs.shadow-client;

# Declare the package with the appropriate configuration
shadow-package = channel: pkgs.callPackage ../default.nix {
# shadow-package = channel: pkgs.callPackage ../default.nix {
shadow-package = channel: pkgs.callPackage ../../../packages/shadow-nix/default.nix {
channel = channel;
enableDiagnostics = cfg.enableDiagnostics;
enableDesktopLauncher = cfg.enableDesktopLauncher;
};

in {
# Import the configuration
imports = [ ../config.nix ../x-session ../systemd-session ];
# ./x-session ./systemd-session
imports = [ ../../config.nix ];

# By default, if you import this file, the Shadow app will be installed
programs.shadow-client.enable = lib.mkDefault true;
Expand All @@ -28,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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading