diff --git a/.github/shell.nix b/.github/shell.nix new file mode 100644 index 0000000..bab995d --- /dev/null +++ b/.github/shell.nix @@ -0,0 +1,22 @@ +let pkgs = import {}; +in pkgs.mkShell { + buildInputs = [ + (pkgs.callPackage ../default.nix { + shadowChannel = "prod"; + enableDiagnostics = true; + desktopLauncher = true; + }) + + (pkgs.callPackage ../default.nix { + shadowChannel = "preprod"; + enableDiagnostics = true; + desktopLauncher = true; + }) + + (pkgs.callPackage ../default.nix { + shadowChannel = "testing"; + enableDiagnostics = true; + desktopLauncher = true; + }) + ]; +} diff --git a/.github/workflows/package-build.yml b/.github/workflows/package-build.yml new file mode 100644 index 0000000..3c2ad03 --- /dev/null +++ b/.github/workflows/package-build.yml @@ -0,0 +1,15 @@ +name: "Package build" +on: + pull_request: + push: +jobs: + tests: + runs-on: ubuntu-latest + env: + NIXPKGS_ALLOW_UNFREE: 1 + steps: + - uses: actions/checkout@v2.3.4 + - uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixos-20.09 + - run: nix-shell .github/shell.nix diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..579a995 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ +# Changelog + +### Version 1 + +[Pull request](https://github.com/NicolasGuilloux/shadow-nix/pull/11) + +For this version, the ownership was transfered from [Elyhaka](https://github.com/Elyhaka) to [NicolasGuilloux](https://github.com/NicolasGuilloux). + +The goal of this version was to simply the code, reorganize it to make it more readable and understandable. + +- Adding direct access to the renderer +- Adding CI to check the package integrity +- Adding more documentation +- Cleaning all the code +- Refactoring some features +- Moving imports to the dedicated folder +- Changing tag version naming diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3e551f9 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at contact@richcongress.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/README.md b/README.md index 71ddcb7..5e08061 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,112 @@ -# Porting Shadow to NixOS +# Shadow on NixOS + +![Package build](https://github.com/NicolasGuilloux/shadow-nix/workflows/Package%20build/badge.svg) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/NicolasGuilloux/shadow-nix/issues) +[![License](https://img.shields.io/badge/license-Unlicense-blue.png)](LICENSE) The goal of this project is to provide Shadow on NixOS with a dynamic derivation to handle frequent updates. **This project is not affiliated with Blade, the company providing Shadow, in any way.** -## How to use +![Shadow loves Nix](./assets/images/shadow_loves_nix.svg) + +## Table of content -### Install +1. [Installation](#1-installation) + - [As a system package](#as-a-system-package) + - [As a home-manager package](#as-a-home-manager-package) +2. [Configuration](#2-configuration) + - [Package configuration](#package-configuration) + - [XSession configuration](#xsession-configuration) + - [Systemd session configuration](#systemd-session-configuration) +3. [About VAAPI](#3-about-vaapi) + - [An example for Intel and AMD GPU](#an-example-for-intel-and-amd-gpu) +4. [Versioning](#4-versioning) +5. [Contributing](#5-contributing) +6. [License](#6-license) +7. [Mentions](#7-mentions) -Note that the ref value (`v*.*.*`) should point to the lastest release. Checkout the tags to know it. +## 1. Installation + +Note that the ref value (`v*.*.*`) should point to the lastest release. Checkout the tags to know it. The version is the derivation one, not the launcher nor the streamer version. Installing any version of this repository will always install the latest version of the launcher available. If you want the latest package derivation, use `ref = "master"` instead. -#### As a home-manager package +#### As a system package -In your `home.nix` : +In your `configuration.nix` : ```nix { imports = [ - (fetchGit { url = "https://github.com/NicolasGuilloux/shadow-nix"; ref = "v0.14.1"; } + "/home-manager.nix") + (fetchGit { url = "https://github.com/NicolasGuilloux/shadow-nix"; ref = "v1.0.0"; } + "/import/system.nix") ]; programs.shadow-client = { enable = true; - channel = "preprod"; + channel = "prod"; }; } ``` -#### As a system package +#### As a home-manager package -In your `configuration.nix` : +In your `home.nix` : ```nix { imports = [ - (fetchGit { url = "https://github.com/NicolasGuilloux/shadow-nix"; ref = "v0.14.1"; } + "/system.nix") + (fetchGit { url = "https://github.com/NicolasGuilloux/shadow-nix"; ref = "v1.0.0"; } + "/import/home-manager.nix") ]; programs.shadow-client = { enable = true; - channel = "prod"; + channel = "preprod"; }; } ``` -## Options +## 2. Configuration + +#### Package configuration - - `channel` : Choose a channel for the Shadow application. `prod` is the stable channel, `preprod` is the beta channel and `testing` is the alpha channel. - - `enableDesktopLauncher` : `bool` / default `true` : Provides the desktop file for launching Shadow from current session (only works with Xorg sessions). - - `enableDiagnostics` : `bool` / default `false` : The command used to execute the client will be output in a file in /tmp. The client will output its strace in /tmp. This is mainly used for diagnostics purposes (when an update breaks something). - - `provideXSession` : `bool` / default `false` (requires system mode) : Provides a XSession desktop file for Shadow Launcher. Useful if you want to autostart it without any DE/WM. - - `preferredScreens` : `bool` / default `[]` : Name of preferred screens, ordered by name. If one screen currently plugged matches the listed screens in this options, it shutdowns all other screens. This feature use xrandr, thus you must use xrandr screen names. This can be useful for laptops with changing multi-heads setups. - - `forceDriver` : `enum` / default `""` : Force the VA driver used by Shadow using the LIBVA_DRIVER_NAME environment variable. - - `disableGpuFix` : `bool` / default `false` : Disable the GPU fixes for Shadow related to the color bit size. +This is the configuration of the package itself. You can set them via `programs.shadow-client.`. +| Key | Type | Default | Possible values | Description | +|-----------------------|--------|---------|-----------------------------|-----------------------------------------------------------| +| enable | bool | false | true, false | Enable the package | +| channel | enum | prod | prod, preprod, testing | `prod` is stable, `preprod` is beta, `testing` is alpha | +| launchArgs | string | | | Add launch arguments to the renderer | +| enableDesktopLauncher | bool | true | true, false | Creates a .desktop entry | +| enableDiagnostics | bool | false | true, false | Provide debug tools | +| forceDriver | enum | null | iHD, i965, radeon, radeonsi | Force the LIBVA driver | +| enableGpuFix | bool | true | true, false | Create the `drirc` file to fix some driver related issues | -## A word on vaapi + +#### XSession configuration + +This package also provides a standalone session with only the necessary component to start Openbox and Shadow. You can set the configuration via `programs.shadow-client.x-session.`. + +| Key | Type | Default | Possible values | Description | +|-----------------------|--------|---------|-----------------------------|------------------------------------------------------------| +| enable | bool | false | true, false | Enable the standalone XSession | +| additionalMenuEntries | | {} | | Additional menu entries for the Openbox right click menu | +| startScript | string | | | Additional start option to be executed when Openbox starts | + + +#### Systemd session configuration + +This package provides a standalone systemd daemon to start only the client wrapped into Xorg in a TTY. You can set the configuration at `programs.shadow-client.systemd-session.`. + +| Key | Type | Default | Possible values | Description | +|--------------|--------|---------|-----------------------------|----------------------------------------------| +| enable | bool | false | true, false | Enable the standalone XSession with Systemd | +| user | string | | | User that will start the session | +| tty | int | 8 | | TTY number where the session will be started | +| onClosingTty | int | null | | TTY number that will be selected on closing | + + +## 3. About VAAPI It is important to have `vaapi` enabled to make Shadow works correctly. You can find information on this [NixOS wiki page](https://nixos.wiki/wiki/Accelerated_Video_Playback). @@ -89,8 +138,29 @@ The following example should work for both AMD and Intel GPU. This is just an ex } ``` +## 4. Versioning + +`shadow-nix` follows [semantic versioning](https://semver.org/). In short the scheme is MAJOR.MINOR.PATCH where +1. MAJOR is bumped when there is a breaking change, +2. MINOR is bumped when a new feature is added in a backward-compatible way, +3. PATCH is bumped when a bug is fixed in a backward-compatible way. + +Versions bellow 1.0.0 are considered experimental and breaking changes may occur at any time. + +## 5. Contributing + +Contributions are welcomed! There are many ways to contribute, and we appreciate all of them. Here are some of the major ones: + +* [Bug Reports](https://github.com/NicolasGuilloux/shadow-nix/issues): While we strive for quality software, bugs can happen and we can't fix issues we're not aware of. So please report even if you're not sure about it or just want to ask a question. If anything the issue might indicate that the documentation can still be improved! +* [Feature Request](https://github.com/NicolasGuilloux/shadow-nix/issues): You have a use case not covered by the current api? Want to suggest a change or add something? We'd be glad to read about it and start a discussion to try to find the best possible solution. +* [Pull Request](https://github.com/NicolasGuilloux/shadow-nix/merge_requests): Want to contribute code or documentation? We'd love that! If you need help to get started, GitHub as [documentation](https://help.github.com/articles/about-pull-requests/) on pull requests. We use the ["fork and pull model"](https://help.github.com/articles/about-collaborative-development-models/) were contributors push changes to their personnal fork and then create pull requests to the main repository. Please make your pull requests against the `master` branch. + +As a reminder, all contributors are expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md). + +## 6. License -## I want to add an option +`shadow-nix` is distributed under the terms of the [Unlicense license](LICENSE). - - Issues and PR are welcome! I'll do my best to make this works for everyone! +## 7. Mentions +This repository was originally created and maintained by [Elyhaka](https://github.com/Elyhaka). A big thanks to him for helping me learning Nix! diff --git a/openbox/background.png b/assets/images/background.png similarity index 100% rename from openbox/background.png rename to assets/images/background.png diff --git a/assets/images/shadow_loves_nix.png b/assets/images/shadow_loves_nix.png new file mode 100644 index 0000000..d03b1a2 Binary files /dev/null and b/assets/images/shadow_loves_nix.png differ diff --git a/assets/images/shadow_loves_nix.svg b/assets/images/shadow_loves_nix.svg new file mode 100644 index 0000000..5d50677 --- /dev/null +++ b/assets/images/shadow_loves_nix.svg @@ -0,0 +1,146 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/cfg.nix b/cfg.nix deleted file mode 100644 index 3d30eec..0000000 --- a/cfg.nix +++ /dev/null @@ -1,135 +0,0 @@ -{ config, pkgs, lib, ... }: - -with lib; - -{ - options.programs.shadow-client = { - enable = mkEnableOption '' - Enable the client to the Shadow Gaming Cloud Computer on NixOS - ''; - - enableDesktopLauncher = mkOption { - type = types.bool; - default = true; - example = false; - description = '' - Provides the desktop file for launching Shadow from current session (only works with Xorg sessions). - ''; - }; - - enableDiagnostics = mkOption { - type = types.bool; - default = false; - example = true; - description = '' - The command used to execute the client will be output in a file in /tmp. - The client will output its strace in /tmp. - This is mainly used for diagnostics purposes (when an update breaks something). - ''; - }; - - provideXSession = mkOption { - type = types.bool; - default = false; - example = true; - description = '' - Provides a XSession desktop file for Shadow Launcher. - Useful if you want to autostart it without any DE/WM. - ''; - }; - - provideSystemdSession = { - enable = mkOption { - type = types.bool; - default = false; - example = true; - description = '' - Provides an autonomous systemd session for Shadow. - ''; - }; - - tty = mkOption { - type = types.str; - default = "8"; - example = "1"; - description = '' - Select the TTY where to start the systemd session - ''; - }; - - user = mkOption { - type = types.str; - default = ""; - example = "myself"; - description = '' - Select the user with which the session is started - ''; - }; - - onClosingTty = mkOption { - type = types.nullOr types.str; - default = null; - example = "1"; - description = '' - Select the TTY to switch to when exiting - ''; - }; - }; - - channel = mkOption { - type = types.enum [ "prod" "preprod" "testing" ]; - default = "prod"; - example = "preprod"; - description = '' - Choose a channel for the Shadow application. - `prod` is the stable channel, `preprod` is the beta channel. - ''; - }; - - launchArgs = mkOption { - type = types.str; - default = ""; - example = "--report"; - description = '' - Start the launcher with arguments by default - ''; - }; - - forceDriver = mkOption { - type = types.enum [ "" "iHD" "i965" "radeon" "radeonsi" ]; - default = ""; - example = "iHD"; - description = '' - Force the VA driver used by Shadow using the LIBVA_DRIVER_NAME environment variable. - ''; - }; - - disableGpuFix = mkOption { - type = types.bool; - default = false; - example = true; - description = '' - Disable the GPU fixes for Shadow related to the color bit size. - ''; - }; - - customSessionMenu = mkOption { - default = null; - example = ''{ "myProgram" = "myProgramCommand" }''; - description = '' - Sets the content of the menu provided in the Openbox bundled standalone session. - ''; - }; - - customSessionStartScript = mkOption { - type = types.str; - default = ""; - example = '' - tint2 & - ''; - description = '' - Custom script executed before shadow is launched in the Openbox bundled standalone session. - ''; - }; - }; -} diff --git a/config.nix b/config.nix new file mode 100644 index 0000000..ca931fd --- /dev/null +++ b/config.nix @@ -0,0 +1,68 @@ +{ config, pkgs, lib, ... }: + +with lib; + +{ + options.programs.shadow-client = { + enable = mkEnableOption '' + Enable the client to the Shadow Gaming Cloud Computer on NixOS + ''; + + channel = mkOption { + type = types.enum [ "prod" "preprod" "testing" ]; + default = "prod"; + example = "preprod"; + description = '' + Choose a channel for the Shadow application. + `prod` is the stable channel, `preprod` is the beta channel. + ''; + }; + + launchArgs = mkOption { + type = types.str; + default = ""; + example = "--report"; + description = '' + Start the launcher with arguments by default + ''; + }; + + enableDesktopLauncher = mkOption { + type = types.bool; + default = true; + example = false; + description = '' + Provides the desktop file for launching Shadow from current session (only works with Xorg sessions). + ''; + }; + + enableDiagnostics = mkOption { + type = types.bool; + default = false; + example = true; + description = '' + The command used to execute the client will be output in a file in /tmp. + The client will output its strace in /tmp. + This is mainly used for diagnostics purposes (when an update breaks something). + ''; + }; + + forceDriver = mkOption { + type = types.nullOr (types.enum [ "iHD" "i965" "radeon" "radeonsi" ]); + default = null; + example = "iHD"; + description = '' + Force the VA driver used by Shadow using the LIBVA_DRIVER_NAME environment variable. + ''; + }; + + enableGpuFix = mkOption { + type = types.bool; + default = true; + example = false; + description = '' + Disable the GPU fixes for Shadow related to the color bit size. + ''; + }; + }; +} diff --git a/shadow-package.nix b/default.nix similarity index 52% rename from shadow-package.nix rename to default.nix index f410e68..84d4328 100644 --- a/shadow-package.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, runCommand, yq, jq, fetchurl, makeWrapper, autoPatchelfHook +{ stdenv, lib, pkgs, runCommand, yq, jq, fetchurl, makeWrapper, autoPatchelfHook , wrapGAppsHook, zlib, runtimeShell , xorg, alsaLib, libbsd, libopus, openssl, libva, pango, cairo, libuuid, nspr @@ -6,49 +6,28 @@ , pulseaudio, libGL, dbus, libnghttp2, libidn2, libpsl, libkrb5, openldap , rtmpdump, libinput -, enableDiagnostics ? false, extraClientParameters ? [ ] -, shadowChannel ? "preprod", desktopLauncher ? true }: +, enableDiagnostics ? false, extraClientParameters ? [] +, shadowChannel ? "prod", desktopLauncher ? true }: with lib; let - # Reading dynamic versions information from upstream update system - latestVersion = builtins.fetchurl - "https://storage.googleapis.com/shadow-update/launcher/${shadowChannel}/linux/ubuntu_18.04/latest-linux.yml"; - latestVersionJson = (runCommand "transform" { buildInputs = [ yq jq ]; } - "cat ${latestVersion} | yq -j . > $out"); - source = builtins.fromJSON (builtins.readFile latestVersionJson); + # Import tools + utilities = (import ./utilities { inherit lib pkgs; }); - # This permit to display errors that could not be displayed otherwise - diagTxt = '' - mv $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow \ - $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/.Shadow-Orig - - echo "#!${runtimeShell}" > $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow - - echo "echo \"\$@\" > /tmp/shadow.current_cmd" >> \ - $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow - - echo "strace $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/.Shadow-Orig \"\$@\" > /tmp/shadow.strace 2>&1" >> \ - $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow - - chmod +x $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow - ''; + # Latest release information + info = utilities.shadowApi.getLatestInfo shadowChannel; in stdenv.mkDerivation rec { pname = "shadow-${shadowChannel}"; - version = source.version; - - src = fetchurl { - url = - "https://update.shadow.tech/launcher/${shadowChannel}/linux/ubuntu_18.04/${source.path}"; - hash = "sha512-${source.sha512}"; - }; - - binaryName = - (if shadowChannel == "prod" then "shadow" else "shadow-${shadowChannel}"); + version = info.version; + src = fetchurl (utilities.shadowApi.getDownloadInfo info); + binaryName = (if shadowChannel == "prod" then "shadow" else "shadow-${shadowChannel}"); + channel = shadowChannel; + # Add all hooks nativeBuildInputs = [ autoPatchelfHook wrapGAppsHook makeWrapper ]; + # Useful libraries to build the package buildInputs = [ stdenv.cc.cc.lib @@ -89,6 +68,7 @@ in stdenv.mkDerivation rec { rtmpdump ]; + # Mandatory libraries for the runtime runtimeDependencies = [ stdenv.cc.cc.lib systemd @@ -101,43 +81,70 @@ in stdenv.mkDerivation rec { libva ]; + # Unpack the AppImage unpackPhase = '' - cp $src ./ShadowBeta.AppImage - chmod 777 ./ShadowBeta.AppImage + cp $src ./Shadow.AppImage + chmod 777 ./Shadow.AppImage patchelf \ --set-interpreter ${stdenv.cc.bintools.dynamicLinker} \ --replace-needed libz.so.1 ${zlib}/lib/libz.so.1 \ - ./ShadowBeta.AppImage + ./Shadow.AppImage - ./ShadowBeta.AppImage --appimage-extract - rm ./ShadowBeta.AppImage + ./Shadow.AppImage --appimage-extract + rm ./Shadow.AppImage ''; - installPhase = '' + # Create the package + installPhase = + '' mkdir -p $out/opt - mv ./squashfs-root/usr/share $out/ mkdir -p $out/lib - ln -s ${lib.getLib systemd}/lib/libudev.so.1 $out/lib/libudev.so.1 + + mv ./squashfs-root/usr/share $out/ mkdir -p $out/share/applications + + ln -s ${lib.getLib systemd}/lib/libudev.so.1 $out/lib/libudev.so.1 rm -r ./squashfs-root/usr/lib rm ./squashfs-root/AppRun mv ./squashfs-root $out/opt/shadow-${shadowChannel} - '' + optionalString enableDiagnostics diagTxt + '' + '' + + + # Add debug wrapper + optionalString enableDiagnostics (utilities.debug.wrapRenderer shadowChannel) + + + # Wrap renderer + '' wrapProgram $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow \ - --prefix LD_LIBRARY_PATH : ${makeLibraryPath runtimeDependencies} ${ - optionalString (extraClientParameters != [ ]) '' - ${concatMapStrings (x: " --add-flags '" + x + "'") - extraClientParameters} - '' - } + --run "cd $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/" \ + --prefix LD_LIBRARY_PATH : "$out/opt/shadow-${shadowChannel}" \ + --prefix LD_LIBRARY_PATH : "$out/lib" \ + --prefix LD_LIBRARY_PATH : ${makeLibraryPath runtimeDependencies} \ + --add-flags "--no-usb" \ + --add-flags "--agent \"Linux;x64;Chrome 80.0.3987.165;latest\"" \ + ${concatMapStrings (x: " --add-flags '" + x + "'") extraClientParameters} + '' + + # Wrap Renderer into binary + + '' + makeWrapper \ + $out/opt/shadow-${shadowChannel}/resources/app.asar.unpacked/release/native/Shadow \ + $out/bin/shadow-${shadowChannel}-renderer \ + --prefix LD_LIBRARY_PATH : ${makeLibraryPath runtimeDependencies} + '' + # Wrap launcher + + '' makeWrapper $out/opt/shadow-${shadowChannel}/${binaryName} $out/bin/shadow-${shadowChannel} \ --prefix LD_LIBRARY_PATH : ${makeLibraryPath runtimeDependencies} - '' + optionalString desktopLauncher '' + '' + + # Add Desktop entry + + optionalString desktopLauncher '' substitute $out/opt/shadow-${shadowChannel}/${binaryName}.desktop \ $out/share/applications/${binaryName}.desktop \ - --replace "Exec=AppRun" "Exec=$out/bin/shadow-${shadowChannel}" + --replace "Exec=AppRun" "Exec=$out/bin/shadow-${shadowChannel}" \ + --replace "Icon=${binaryName}" "Icon=$out/opt/${binaryName}/resources/app.asar.unpacked/release/main/assets/icons/shadow-${shadowChannel}.png" ''; meta = with stdenv.lib; { diff --git a/home-manager.nix b/home-manager.nix deleted file mode 100644 index c8bcb56..0000000 --- a/home-manager.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ config, pkgs, lib, ... }: - -with lib; - -let - cfg = config.programs.shadow-client; - - shadow-package = pkgs.callPackage ./shadow-package.nix { - shadowChannel = cfg.channel; - enableDiagnostics = cfg.enableDiagnostics; - desktopLauncher = cfg.enableDesktopLauncher; - }; - - shadow-wrapped = pkgs.callPackage ./wrapper.nix { - shadow-package = shadow-package; - - shadowChannel = cfg.channel; - provideSession = cfg.provideXSession; - launchArgs = cfg.launchArgs; - - menuOverride = cfg.customSessionMenu; - customStartScript = cfg.customSessionStartScript; - }; -in { - imports = [ ./cfg.nix ]; - - config = mkIf cfg.enable { home.packages = [ shadow-wrapped ]; }; -} diff --git a/import/home-manager.nix b/import/home-manager.nix new file mode 100644 index 0000000..55f2c05 --- /dev/null +++ b/import/home-manager.nix @@ -0,0 +1,36 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.programs.shadow-client; + utilities = import ../utilities { inherit lib pkgs; }; + + # Declare the package with the appropriate configuration + shadow-package = pkgs.callPackage ../default.nix { + shadowChannel = cfg.channel; + enableDiagnostics = cfg.enableDiagnostics; + desktopLauncher = cfg.enableDesktopLauncher; + }; + + # Drirc file + drirc = utilities.files.drirc; +in { + # Import the configuration + imports = [ ../config.nix ]; + + # By default, if you import this file, the Shadow app will be installed + programs.shadow-client.enable = mkDefault true; + + # Enables + home = mkIf cfg.enable { + # Install Shadow wrapper + packages = with pkgs; [ shadow-package libva-utils libva ]; + + # Add GPU fixes + file.".drirc".source = mkIf (cfg.enableGpuFix) drirc; + + # Force VA Driver + sessionVariables.LIBVA_DRIVER_NAME = mkIf (cfg.forceDriver != "") [ cfg.forceDriver ]; + }; +} diff --git a/import/system.nix b/import/system.nix new file mode 100644 index 0000000..7260440 --- /dev/null +++ b/import/system.nix @@ -0,0 +1,36 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.programs.shadow-client; + utilities = import ../utilities { inherit lib pkgs; }; + + # Declare the package with the appropriate configuration + shadow-package = pkgs.callPackage ../default.nix { + shadowChannel = cfg.channel; + enableDiagnostics = cfg.enableDiagnostics; + desktopLauncher = cfg.enableDesktopLauncher; + }; + + # Drirc file + drirc = utilities.files.drirc; +in { + # Import the configuration + imports = [ ../config.nix ../x-session ../systemd-session ]; + + # By default, if you import this file, the Shadow app will be installed + programs.shadow-client.enable = mkDefault true; + + # Enables + environment = mkIf cfg.enable { + # Install Shadow wrapper + systemPackages = with pkgs; [ shadow-package libva-utils libva ]; + + # Add GPU fixes + etc.drirc.source = mkIf (cfg.enableGpuFix) drirc; + + # Force VA Driver + variables.LIBVA_DRIVER_NAME = mkIf (cfg.forceDriver != null) [ cfg.forceDriver ]; + }; +} diff --git a/system.nix b/system.nix deleted file mode 100644 index a2de89c..0000000 --- a/system.nix +++ /dev/null @@ -1,84 +0,0 @@ -{ config, pkgs, lib, ... }: - -with lib; - -let - cfg = config.programs.shadow-client; - - # Declare the package with the appropriate configuration - shadow-package = pkgs.callPackage ./shadow-package.nix { - shadowChannel = cfg.channel; - enableDiagnostics = cfg.enableDiagnostics; - desktopLauncher = cfg.enableDesktopLauncher; - }; - - # Declare the wrapper with the appropriate configuration - shadow-wrapped = pkgs.callPackage ./wrapper.nix { - shadow-package = shadow-package; - - shadowChannel = cfg.channel; - provideSession = cfg.provideXSession || cfg.provideSystemdSession.enable; - launchArgs = cfg.launchArgs; - - menuOverride = cfg.customSessionMenu; - customStartScript = cfg.customSessionStartScript; - }; - - # Drirc file - drirc = (fetchGit { - url = "https://github.com/NicolasGuilloux/blade-shadow-beta"; - ref = "master"; - } + "/resources/drirc"); -in { - # Import the configuration - imports = [ ./cfg.nix ]; - - config = mkIf cfg.enable { - # Install Shadow wrapper - environment.systemPackages = mkIf cfg.enableDesktopLauncher [ shadow-wrapped ]; - - # Add Shadow session - services.xserver.displayManager.sessionPackages = - mkIf cfg.provideXSession [ shadow-wrapped ]; - - systemd.services.shadow-tech = - let - sess = cfg.provideSystemdSession; - in mkIf sess.enable { - enable = true; - wants = [ "systemd-machined.service" ]; - after = [ - "rc-local.service" - "systemd-machined.service" - "systemd-user-sessions.service" - "systemd-logind.service" - ]; - serviceConfig = { - ExecStartPre = "${config.system.path}/bin/chvt ${sess.tty}"; - ExecStart = - "${pkgs.dbus}/bin/dbus-run-session ${shadow-wrapped}/bin/${shadow-wrapped.sessionBinaryName}"; - ExecStopPost = - mkIf (sess.onClosingTty != null) "${config.system.path}/bin/chvt ${sess.onClosingTty}"; - - TTYPath = "/dev/tty${sess.tty}"; - TTYReset = "yes"; - TTYVHangup = "yes"; - TTYVTDisallocate = "yes"; - PAMName = "login"; - User = sess.user; - WorkingDirectory = "/home/${sess.user}"; - StandardInput = "tty"; - StandardError = "journal"; - StandardOutput = "journal"; - Restart = "no"; - }; - }; - - # Add GPU fixes - environment.etc."drirc" = mkIf (!cfg.disableGpuFix) { source = drirc; }; - - # Force VA Driver - environment.variables = - mkIf (cfg.forceDriver != "") { LIBVA_DRIVER_NAME = [ cfg.forceDriver ]; }; - }; -} diff --git a/systemd-session/config.nix b/systemd-session/config.nix new file mode 100644 index 0000000..1577acf --- /dev/null +++ b/systemd-session/config.nix @@ -0,0 +1,43 @@ +{ config, pkgs, lib, ... }: + +with lib; + +{ + options.programs.shadow-client.systemd-session = { + enable = mkOption { + type = types.bool; + default = false; + example = true; + description = '' + Provides an autonomous systemd session for Shadow. + ''; + }; + + user = mkOption { + type = types.str; + default = ""; + example = "myself"; + description = '' + Select the user with which the session is started + ''; + }; + + tty = mkOption { + type = types.int; + default = 8; + example = 1; + description = '' + Select the TTY where to start the systemd session + ''; + }; + + onClosingTty = mkOption { + type = types.nullOr types.int; + default = null; + example = 1; + description = '' + Select the TTY to switch to when exiting + ''; + }; + }; +} diff --git a/systemd-session/default.nix b/systemd-session/default.nix new file mode 100644 index 0000000..acd2bdb --- /dev/null +++ b/systemd-session/default.nix @@ -0,0 +1,61 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.shadow-client.systemd-session; + sessionCfg = config.programs.shadow-client.x-session; + packageCfg = config.programs.shadow-client; + + # Declare the package with the appropriate configuration + shadow-package = pkgs.callPackage ../default.nix { + shadowChannel = packageCfg.channel; + enableDiagnostics = packageCfg.enableDiagnostics; + desktopLauncher = packageCfg.enableDesktopLauncher; + }; + + # Declare the wrapper with the appropriate configuration + shadow-wrapped = pkgs.callPackage ../x-session/wrapper.nix { + shadow-package = shadow-package; + + shadowChannel = packageCfg.channel; + provideSession = cfg.enable; + launchArgs = packageCfg.launchArgs; + + menuOverride = sessionCfg.additionalMenuEntries; + customStartScript = sessionCfg.startScript; + }; +in +{ + imports = [ ./config.nix ]; + + systemd.services.shadow-tech = lib.mkIf cfg.enable { + enable = true; + wants = [ "systemd-machined.service" ]; + after = [ + "rc-local.service" + "systemd-machined.service" + "systemd-user-sessions.service" + "systemd-logind.service" + ]; + serviceConfig = { + ExecStartPre = "${config.system.path}/bin/chvt ${toString cfg.tty}"; + ExecStart = + "${pkgs.dbus}/bin/dbus-run-session ${shadow-wrapped}/bin/${shadow-wrapped.sessionBinaryName}"; + ExecStopPost = + lib.mkIf + (cfg.onClosingTty != null) + "${config.system.path}/bin/chvt ${toString cfg.onClosingTty}"; + + TTYPath = "/dev/tty${toString cfg.tty}"; + TTYReset = "yes"; + TTYVHangup = "yes"; + TTYVTDisallocate = "yes"; + PAMName = "login"; + User = cfg.user; + WorkingDirectory = "/home/${cfg.user}"; + StandardInput = "tty"; + StandardError = "journal"; + StandardOutput = "journal"; + Restart = "no"; + }; + }; +} diff --git a/utilities/debug.nix b/utilities/debug.nix new file mode 100644 index 0000000..f5ac7f9 --- /dev/null +++ b/utilities/debug.nix @@ -0,0 +1,25 @@ +{ lib, pkgs, ... }: + +/* Helper to debug the Shadow app */ +rec { + /* Wrap the renderer to capture debug logs + + Example: + wrapRenderer "preprod" + => (string) + */ + wrapRenderer = channel: '' + mv $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/Shadow \ + $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/.Shadow-Orig + + echo "#!${pkgs.runtimeShell}" > $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/Shadow + + echo "echo \"\$@\" > /tmp/shadow.current_cmd" >> \ + $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/Shadow + + echo "strace $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/.Shadow-Orig \"\$@\" > /tmp/shadow.strace 2>&1" >> \ + $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/Shadow + + chmod +x $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/Shadow + ''; +} \ No newline at end of file diff --git a/utilities/default.nix b/utilities/default.nix new file mode 100644 index 0000000..1341042 --- /dev/null +++ b/utilities/default.nix @@ -0,0 +1,16 @@ +{ lib, pkgs, ... }: + +# Use it by adding the following lines +# let +# utilities = (import ./utilities { inherit lib pkgs; }); +# in +# ... +let + # Import library method + callLib = path: (import path { inherit lib pkgs; }); +in +{ + shadowApi = callLib ./shadow-api.nix; + debug = callLib ./debug.nix; + files = callLib ./files.nix; +} diff --git a/utilities/files.nix b/utilities/files.nix new file mode 100644 index 0000000..8cc91b5 --- /dev/null +++ b/utilities/files.nix @@ -0,0 +1,8 @@ +{ lib, ... }: + +rec { + drirc = builtins.fetchGit { + url = "https://github.com/NicolasGuilloux/blade-shadow-beta"; + ref = "master"; + } + "/resources/drirc"; +} diff --git a/utilities/shadow-api.nix b/utilities/shadow-api.nix new file mode 100644 index 0000000..1275fde --- /dev/null +++ b/utilities/shadow-api.nix @@ -0,0 +1,42 @@ +{ lib, pkgs, ... }: + +/* Helper to interact with the Shadow API + + Import example: + let + inherit (import ./utilities/shadow-api.nix { inherit lib; }) getLatestInfo; + + ... + in +*/ +rec { + /* Return the latest version information for the given channel + + Example: + getLatestInfo "preprod" + => { channel = "preprod"; version = "3.1.6"; sha512 = "..."; path = "..."; } + */ + getLatestInfo = channel: + let + yamlInfo = builtins.fetchurl "https://storage.googleapis.com/shadow-update/launcher/${channel}/linux/ubuntu_18.04/latest-linux.yml"; + jsonInfo = (pkgs.runCommand "transform" { buildInputs = with pkgs; [ yq jq ]; } "cat ${yamlInfo} | yq -j . > $out"); + info = builtins.fromJSON (builtins.readFile jsonInfo); + in + { + channel = channel; + version = info.version; + sha512 = info.sha512; + path = info.path; + }; + + /* Return the file information to give to fetchurl + + Example: + getDownloadInfo info + => { url = "..."; hash = "sha512-..."; } + */ + getDownloadInfo = info: { + url = "https://update.shadow.tech/launcher/${info.channel}/linux/ubuntu_18.04/${info.path}"; + hash = "sha512-${info.sha512}"; + }; +} \ No newline at end of file diff --git a/x-session/config.nix b/x-session/config.nix new file mode 100644 index 0000000..3dbe8ea --- /dev/null +++ b/x-session/config.nix @@ -0,0 +1,34 @@ +{ config, pkgs, lib, ... }: + +with lib; + +{ + options.programs.shadow-client.x-session = { + enable = mkOption { + type = types.bool; + default = false; + example = true; + description = '' + Provides a XSession desktop file for Shadow Launcher. + Useful if you want to autostart it without any DE/WM. + ''; + }; + + additionalMenuEntries = mkOption { + default = {}; + example = ''{ "myProgram" = "myProgramCommand"; }''; + description = '' + Sets the content of the menu provided in the Openbox bundled standalone session. + ''; + }; + + startScript = mkOption { + type = types.str; + default = ""; + example = "tint2 &"; + description = '' + Custom script executed before shadow is launched in the Openbox bundled standalone session. + ''; + }; + }; +} diff --git a/x-session/default.nix b/x-session/default.nix new file mode 100644 index 0000000..cef9a07 --- /dev/null +++ b/x-session/default.nix @@ -0,0 +1,30 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.programs.shadow-client; + provideSession = cfg.x-session.enable || cfg.systemd-session.enable; + + # Declare the package with the appropriate configuration + shadow-package = pkgs.callPackage ../default.nix { + shadowChannel = cfg.channel; + enableDiagnostics = cfg.enableDiagnostics; + desktopLauncher = cfg.enableDesktopLauncher; + }; + + # Declare the wrapper with the appropriate configuration + shadow-wrapped = pkgs.callPackage ./wrapper.nix { + shadow-package = shadow-package; + + shadowChannel = cfg.channel; + provideSession = provideSession; + launchArgs = cfg.launchArgs; + + menuOverride = cfg.x-session.additionalMenuEntries; + customStartScript = cfg.x-session.startScript; + }; +in { + imports = [ ./config.nix ]; + +} diff --git a/openbox/obconfig.nix b/x-session/openbox/obconfig.nix similarity index 100% rename from openbox/obconfig.nix rename to x-session/openbox/obconfig.nix diff --git a/openbox/obmenu.nix b/x-session/openbox/obmenu.nix similarity index 100% rename from openbox/obmenu.nix rename to x-session/openbox/obmenu.nix diff --git a/wrapper.nix b/x-session/wrapper.nix similarity index 97% rename from wrapper.nix rename to x-session/wrapper.nix index 72d3a61..a7bd203 100644 --- a/wrapper.nix +++ b/x-session/wrapper.nix @@ -22,7 +22,7 @@ let ${compton}/bin/compton --vsync -b --backend glx # Display a beautiful wallpaper - ${feh}/bin/feh --bg-scale ${./openbox/background.png} + ${feh}/bin/feh --bg-scale ${../assets/images/background.png} exec ${shadow-package}/bin/shadow-${shadowChannel} "$@" '';