diff --git a/.github/workflows/nix-package.yml b/.github/workflows/nix-package.yml index 179ff06..b35846f 100644 --- a/.github/workflows/nix-package.yml +++ b/.github/workflows/nix-package.yml @@ -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 diff --git a/.github/workflows/update-upstream-info.yml b/.github/workflows/update-upstream-info.yml index 361293c..f3b7b75 100644 --- a/.github/workflows/update-upstream-info.yml +++ b/.github/workflows/update-upstream-info.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index fe8d377..1d972e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # IDE .vscode .idea + +# Exclude `nix build` output directory +result diff --git a/checks/hmTests/default.nix b/checks/hmTests/default.nix new file mode 100644 index 0000000..664a2b0 --- /dev/null +++ b/checks/hmTests/default.nix @@ -0,0 +1,3 @@ +{ + shadow-client = ./shadow-client.nix; +} diff --git a/checks/hmTests/shadow-client.nix b/checks/hmTests/shadow-client.nix new file mode 100644 index 0000000..0a96990 --- /dev/null +++ b/checks/hmTests/shadow-client.nix @@ -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} + ''; +} diff --git a/checks/nixosTests/auto.nix b/checks/nixosTests/auto.nix new file mode 100644 index 0000000..ac56bed --- /dev/null +++ b/checks/nixosTests/auto.nix @@ -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 + ''; + }; +} diff --git a/checks/nixosTests/shadow-client.nix b/checks/nixosTests/shadow-client.nix new file mode 100644 index 0000000..d118299 --- /dev/null +++ b/checks/nixosTests/shadow-client.nix @@ -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") + ''; +}) diff --git a/checks/nixosTests/x11.nix b/checks/nixosTests/x11.nix new file mode 100644 index 0000000..0d76a0e --- /dev/null +++ b/checks/nixosTests/x11.nix @@ -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; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..49a067d --- /dev/null +++ b/flake.lock @@ -0,0 +1,99 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1696343447, + "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1698479159, + "narHash": "sha256-rJHBDwW4LbADEfhkgGHjKGfL2dF44NrlyXdXeZrQahs=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "f92a54fef4eacdbe86b0a2054054dd58b0e2a2a4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1697456312, + "narHash": "sha256-roiSnrqb5r+ehnKCauPLugoU8S36KgmWraHgRqVYndo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ca012a02bf8327be9e488546faecae5e05d7d749", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1698318101, + "narHash": "sha256-gUihHt3yPD7bVqg+k/UVHgngyaJ3DMEBchbymBMvK1E=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "63678e9f3d3afecfeafa0acead6239cdb447574c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6c71fc6 --- /dev/null +++ b/flake.nix @@ -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; + }; + }; + }; + +} diff --git a/import/.drirc b/modules/.drirc similarity index 100% rename from import/.drirc rename to modules/.drirc diff --git a/config.nix b/modules/config.nix similarity index 100% rename from config.nix rename to modules/config.nix diff --git a/import/home-manager.nix b/modules/hm/shadow-nix/default.nix similarity index 92% rename from import/home-manager.nix rename to modules/hm/shadow-nix/default.nix index 7f23fae..db53101 100644 --- a/import/home-manager.nix +++ b/modules/hm/shadow-nix/default.nix @@ -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; diff --git a/import/system.nix b/modules/nixos/shadow-nix/default.nix similarity index 74% rename from import/system.nix rename to modules/nixos/shadow-nix/default.nix index 8adcc3d..72353b9 100644 --- a/import/system.nix +++ b/modules/nixos/shadow-nix/default.nix @@ -5,7 +5,8 @@ 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; @@ -13,7 +14,8 @@ let 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; @@ -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 ]; diff --git a/systemd-session/config.nix b/modules/nixos/shadow-nix/systemd-session/config.nix similarity index 100% rename from systemd-session/config.nix rename to modules/nixos/shadow-nix/systemd-session/config.nix diff --git a/systemd-session/default.nix b/modules/nixos/shadow-nix/systemd-session/default.nix similarity index 100% rename from systemd-session/default.nix rename to modules/nixos/shadow-nix/systemd-session/default.nix diff --git a/x-session/config.nix b/modules/nixos/shadow-nix/x-session/config.nix similarity index 100% rename from x-session/config.nix rename to modules/nixos/shadow-nix/x-session/config.nix diff --git a/x-session/default.nix b/modules/nixos/shadow-nix/x-session/default.nix similarity index 100% rename from x-session/default.nix rename to modules/nixos/shadow-nix/x-session/default.nix diff --git a/x-session/openbox/obconfig.nix b/modules/nixos/shadow-nix/x-session/openbox/obconfig.nix similarity index 100% rename from x-session/openbox/obconfig.nix rename to modules/nixos/shadow-nix/x-session/openbox/obconfig.nix diff --git a/x-session/openbox/obmenu.nix b/modules/nixos/shadow-nix/x-session/openbox/obmenu.nix similarity index 100% rename from x-session/openbox/obmenu.nix rename to modules/nixos/shadow-nix/x-session/openbox/obmenu.nix diff --git a/x-session/wrapper.nix b/modules/nixos/shadow-nix/x-session/wrapper.nix similarity index 100% rename from x-session/wrapper.nix rename to modules/nixos/shadow-nix/x-session/wrapper.nix diff --git a/debug.nix b/packages/shadow-nix/debug.nix similarity index 100% rename from debug.nix rename to packages/shadow-nix/debug.nix diff --git a/default.nix b/packages/shadow-nix/default.nix similarity index 100% rename from default.nix rename to packages/shadow-nix/default.nix diff --git a/update.py b/packages/shadow-nix/update.py similarity index 100% rename from update.py rename to packages/shadow-nix/update.py diff --git a/upstream-info.json b/packages/shadow-nix/upstream-info.json similarity index 100% rename from upstream-info.json rename to packages/shadow-nix/upstream-info.json