├── flake.lock.license ├── .gitignore ├── static ├── nix-system-graphics.svg.license └── nix-system-graphics.svg ├── .editorconfig ├── .envrc ├── flake.lock ├── .pre-commit-config.yaml ├── LICENSES ├── MIT.txt ├── CC0-1.0.txt └── CC-BY-4.0.txt ├── LICENSE ├── flake.nix ├── system └── modules │ └── graphics.nix └── README.md /flake.lock.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: NONE 2 | SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: NONE 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | .direnv/ 6 | result* 7 | -------------------------------------------------------------------------------- /static/nix-system-graphics.svg.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: Jay Michalska 2 | SPDX-License-Identifier: CC-BY-4.0 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 SoupGlasses 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # EditorConfig helps developers define and maintain consistent 6 | # coding styles between different editors and IDEs 7 | # editorconfig.org 8 | 9 | root = true 10 | 11 | [*] 12 | charset = utf-8 13 | end_of_line = lf 14 | insert_final_newline = true 15 | trim_trailing_whitespace = true 16 | indent_style = space 17 | 18 | [*.{diff,patch}] 19 | end_of_line = unset 20 | insert_final_newline = unset 21 | trim_trailing_whitespace = unset 22 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: NONE 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | # vi: ft=bash 6 | 7 | # Ensure direnv has source_url support. 8 | if ! direnv_version 2.23.0; then 9 | echo "Please update direnv to at least v2.23.0" 10 | exit 1 11 | fi 12 | 13 | # Ensure and download a common nix-direnv version to unify installs. 14 | if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then 15 | source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-0EVQVNSRQWsln+rgPW3mXVmnF5sfcmKEYOmOSfLYxHg=" 16 | fi 17 | 18 | use flake 19 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1726937504, 6 | "narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "9357f4f23713673f310988025d9dc261c20e70c6", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 SoupGlasses 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | default_install_hook_types: [pre-commit, pre-push] 6 | repos: 7 | - repo: local 8 | hooks: 9 | - id: alejandra 10 | name: alejandra 11 | entry: alejandra 12 | language: system 13 | files: \.nix$ 14 | stages: [pre-commit] 15 | - id: deadnix 16 | name: deadnix 17 | entry: deadnix --fail 18 | language: system 19 | files: \.nix$ 20 | stages: [pre-commit] 21 | - id: editorconfig-checker 22 | name: editorconfig-checker 23 | entry: editorconfig-checker 24 | language: system 25 | stages: [pre-commit] 26 | - id: nix-flake-check 27 | name: nix flake check 28 | entry: nix flake check 29 | language: system 30 | files: '.*\.(nix|lock)$' 31 | pass_filenames: false 32 | stages: [pre-push] 33 | - id: reuse 34 | name: reuse 35 | entry: reuse lint 36 | language: system 37 | pass_filenames: false 38 | stages: [pre-commit] 39 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024-2025 SoupGlasses and the nix-system-graphics contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 SoupGlasses 2 | # 3 | # SPDX-License-Identifier: MIT 4 | { 5 | description = "Run graphics accelerated programs built with Nix on any Linux distribution"; 6 | 7 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 8 | 9 | outputs = { 10 | self, 11 | nixpkgs, 12 | }: let 13 | systems = ["aarch64-linux" "x86_64-linux"]; 14 | eachSystem = f: 15 | nixpkgs.lib.genAttrs systems (system: 16 | f { 17 | inherit system; 18 | pkgs = nixpkgs.legacyPackages.${system}; 19 | }); 20 | in { 21 | # -- System Modules -- 22 | # Holds re-usable system modules meant for systemConfigs to include. 23 | 24 | systemModules = { 25 | default = self.systemModules.graphics; 26 | graphics = import ./system/modules/graphics.nix; 27 | }; 28 | 29 | # -- System Configurations -- 30 | # Holds Nix system configurations for Linux computers. 31 | 32 | systemConfigs = let 33 | # Use fetchTarball to import system-manager within the example 34 | # systemConfigs to prevent dependants from needing to override it if it 35 | # instead was imported as a flake input. 36 | system-manager = builtins.fetchTarball { 37 | url = "https://github.com/soupglasses/system-manager-lite/archive/40ec3633e4cf41fa01dbf144cec0b18e03810197.tar.gz"; 38 | sha256 = "0gkd1sjffll9il9w3vvyk6ypra6i8x1cvx7wbhy352s3xbp233nm"; 39 | }; 40 | system-manager-lib = import "${system-manager}/nix/lib.nix" {inherit nixpkgs;}; 41 | in { 42 | default = system-manager-lib.makeSystemConfig { 43 | modules = [ 44 | self.systemModules.default 45 | ({...}: { 46 | config = { 47 | nixpkgs.hostPlatform = "x86_64-linux"; 48 | system-manager.allowAnyDistro = true; 49 | system-graphics.enable = true; 50 | }; 51 | }) 52 | ]; 53 | }; 54 | }; 55 | 56 | # -- Development Shells -- 57 | # Scoped environments including packages and shell-hooks to aid project development. 58 | 59 | devShells = eachSystem ({pkgs, ...}: { 60 | default = pkgs.mkShellNoCC { 61 | shellHook = '' 62 | ${pkgs.pre-commit}/bin/pre-commit install --install-hooks --overwrite 63 | ''; 64 | nativeBuildInputs = with pkgs; [ 65 | pre-commit 66 | alejandra 67 | deadnix 68 | editorconfig-checker 69 | reuse 70 | ]; 71 | }; 72 | }); 73 | }; 74 | } 75 | -------------------------------------------------------------------------------- /system/modules/graphics.nix: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2003-2024 Eelco Dolstra and the Nixpkgs/NixOS contributors 2 | # SPDX-FileCopyrightText: 2024 SoupGlasses 3 | # 4 | # SPDX-License-Identifier: MIT 5 | { 6 | config, 7 | pkgs, 8 | lib, 9 | ... 10 | }: let 11 | inherit (lib) types; 12 | 13 | cfg = config.system-graphics; 14 | 15 | driversEnv = pkgs.buildEnv { 16 | name = "graphics-drivers"; 17 | paths = [cfg.package] ++ cfg.extraPackages; 18 | }; 19 | 20 | driversEnv32 = pkgs.buildEnv { 21 | name = "graphics-drivers-32bit"; 22 | paths = [cfg.package32] ++ cfg.extraPackages32; 23 | }; 24 | in { 25 | options = { 26 | system-graphics = { 27 | enable = lib.mkOption { 28 | description = '' 29 | Whether to enable hardware accelerated graphics drivers. 30 | 31 | This is required to allow most graphical applications and 32 | environments to use hardware rendering, video encode/decode 33 | acceleration, etc. 34 | ''; 35 | type = types.bool; 36 | default = false; 37 | }; 38 | 39 | enable32Bit = lib.mkOption { 40 | description = '' 41 | On 64-bit systems, whether to also install 32-bit drivers for 42 | 32-bit applications (such as Wine). 43 | ''; 44 | type = lib.types.bool; 45 | default = false; 46 | }; 47 | 48 | package = lib.mkPackageOption pkgs ["mesa" "drivers"] {}; 49 | 50 | package32 = lib.mkPackageOption pkgs ["pkgsi686Linux" "mesa" "drivers"] { 51 | extraDescription = '' 52 | Used when {option}`enable32Bit` is enabled. 53 | ''; 54 | }; 55 | 56 | extraPackages = lib.mkOption { 57 | description = '' 58 | Additional packages to add to OpenGL drivers. 59 | This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc. 60 | 61 | ::: {.note} 62 | intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver. 63 | ::: 64 | ''; 65 | type = types.listOf types.package; 66 | default = []; 67 | example = lib.literalExpression "with pkgs; [ intel-media-driver intel-ocl intel-vaapi-driver ]"; 68 | }; 69 | 70 | extraPackages32 = lib.mkOption { 71 | description = '' 72 | Additional packages to add to 32-bit OpenGL drivers on 64-bit systems. 73 | Used when {option}`driSupport32Bit` is set. This can be used to add OpenCL drivers, VA-API/VDPAU drivers etc. 74 | 75 | ::: {.note} 76 | intel-media-driver supports hardware Broadwell (2014) or newer. Older hardware should use the mostly unmaintained intel-vaapi-driver driver. 77 | ::: 78 | ''; 79 | type = types.listOf types.package; 80 | default = []; 81 | example = lib.literalExpression "with pkgs.pkgsi686Linux; [ intel-media-driver intel-vaapi-driver ]"; 82 | }; 83 | }; 84 | }; 85 | config = lib.mkIf cfg.enable { 86 | assertions = [ 87 | { 88 | assertion = cfg.enable32Bit -> pkgs.stdenv.isx86_64; 89 | message = "Option `system-graphics.enable32Bit` only makes sense on a 64-bit system."; 90 | } 91 | ]; 92 | 93 | systemd.tmpfiles.rules = [ 94 | "L+ /run/opengl-driver - - - - ${driversEnv}" 95 | ( 96 | if pkgs.stdenv.isi686 97 | then "L+ /run/opengl-driver-32 - - - - opengl-driver" 98 | else if cfg.enable32Bit 99 | then "L+ /run/opengl-driver-32 - - - - ${driversEnv32}" 100 | else "r /run/opengl-driver-32" 101 | ) 102 | ]; 103 | 104 | system-manager.preActivationAssertions.systemGraphicsEnsureNoNixOS = { 105 | enable = true; 106 | script = '' 107 | source /etc/os-release 108 | if [ $ID = "nixos" ]; then 109 | echo "You cannot run nix-system-graphics on a NixOS system." 110 | echo "Please use the 'hardware.graphics' module in NixOS instead." 111 | exit 1 112 | fi 113 | ''; 114 | }; 115 | }; 116 | } 117 | -------------------------------------------------------------------------------- /static/nix-system-graphics.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /LICENSES/CC0-1.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 8 | 9 |

10 | 11 |

12 | 13 | # Nix System Graphics 14 | 15 | Run graphics accelerated programs built with Nix on _any_ Linux distribution. Works with both OpenGL and Vulkan seamlessly. 16 | 17 | ## Table of contents 18 | 19 | - [Comparison Table](#comparison-table) 20 | - [Installing with Nix Flakes](#installing-with-nix-flakes) 21 | - [Extra Graphical Packages](#extra-graphical-packages) 22 | - [Nvidia Support](#nvidia-support) 23 | - [But why another Nix-with-OpenGL project?](#but-why-another-nix-with-opengl-project) 24 | - [Acknowledgements](#acknowledgements) 25 | 26 | 27 | ## Comparison Table 28 | 29 | | | [**NixGL**](https://github.com/nix-community/nixGL) | [**nix-gl-host**](https://github.com/numtide/nix-gl-host/) | [**nix-system-graphics**](https://github.com/soupglasses/nix-system-graphics) | 30 | |---|:-:|:-:|:-:| 31 | | Requires no wrapping? (no `nixgl ...`) | ❌ | ❌ | ✅ | 32 | | Works with AMD/Intel? (Mesa) | ✅ | ❌ | ✅ | 33 | | Works with Nvidia? (Proprietary) | ✅ | ✅ | ⚠️[³](#ref-3) | 34 | | Works with `nix run nixpkgs#...`? | ⚠️[¹](#ref-1) | ⚠️[¹](#ref-1) | ✅ | 35 | | Nix program can launch system apps? | ❌[²](#ref-2) | ❌[²](#ref-2) | ✅ | 36 | 37 | 1. Requires wrapping `nix run` with their wrapper before it works. 38 | 2. Can be done in very select cases under certain setups by manually changing internal variables. [Example](https://github.com/nix-community/nixGL/issues/116#issuecomment-1265042706). 39 | 3. While Nvidia is functional in nix-system-graphics, it requires manual effort to be kept in sync with the __exact__ version of the host. See [this Github comment](https://github.com/soupglasses/nix-system-graphics/issues/5#issuecomment-2443771338) for how this is done. [nix-gl-host](https://github.com/numtide/nix-gl-host/) may be a better alternative if the other above features of nix-system-graphics is not required, and a set-and-forget approach is desired. 40 | 41 | 42 | ## Installing with Nix Flakes 43 | 44 | Ensure you have Nix installed with Flakes support enabled. If you do not have Nix installed already, you can do this by installing [Lix](https://lix.systems/install/) or using one of the [nix-installers](https://nix-community.github.io/nix-installers/) which enable this automatically. Alternatively, you may also [enable Flakes support manually](https://nixos.wiki/wiki/Flakes#Other_Distros.2C_without_Home-Manager) if you have installed Nix with another approach, but didn't enable Flakes support for you. 45 | 46 | Now, adding a system-manager config will be very individualized to how your `flake.nix` is written, but generally a complete file would look like the following. 47 | 48 | ```nix 49 | { 50 | inputs = { 51 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 52 | 53 | system-manager = { 54 | url = "github:numtide/system-manager"; 55 | inputs.nixpkgs.follows = "nixpkgs"; 56 | }; 57 | 58 | nix-system-graphics = { 59 | url = "github:soupglasses/nix-system-graphics"; 60 | inputs.nixpkgs.follows = "nixpkgs"; 61 | }; 62 | }; 63 | 64 | outputs = { self, flake-utils, nixpkgs, system-manager, nix-system-graphics }: { 65 | systemConfigs.default = system-manager.lib.makeSystemConfig { 66 | modules = [ 67 | nix-system-graphics.systemModules.default 68 | ({ 69 | config = { 70 | nixpkgs.hostPlatform = "x86_64-linux"; 71 | system-manager.allowAnyDistro = true; 72 | system-graphics.enable = true; 73 | }; 74 | }) 75 | ]; 76 | }; 77 | }; 78 | } 79 | ``` 80 | 81 | Then you can change into your system-manager config by using the `system-manager` package, either by installing it, running it in a development shell, or running it directly from the upstream flake URL, which we will do here. 82 | 83 | ```bash 84 | nix run 'github:numtide/system-manager' -- switch --flake '.' 85 | ``` 86 | 87 | Lastly, to verify that the driver is now functioning on your system, you may run the following command. 88 | 89 | ```bash 90 | nix shell 'nixpkgs#mesa-demos' --command glxgears 91 | ``` 92 | 93 | 94 | ## Extra Graphical Packages 95 | 96 | > [!IMPORTANT] 97 | > This section is currently under testing and may not work as expected, so if you hit any issues or simply have success with this method, please [give feedback in the following Github issue #4](https://github.com/soupglasses/nix-system-graphics/issues/4). 98 | 99 | You should be able to add VA-API/VDPAU/OpenCL/CUDA support similarly as you would in NixOS. Just add the relevant packages to `system-graphics.extraPackages` and `system-graphics.extraPackages32` as needed. Due to the variety of libraries that could possibly be added here, I recommend to read up on the relevant NixOS Wiki pages. 100 | 101 | [Accelerated Video Playback](https://nixos.wiki/wiki/Accelerated_Video_Playback) | [AMD OpenCL](https://nixos.wiki/wiki/AMD_GPU#OpenCL) | [Nvidia CUDA](https://nixos.wiki/wiki/CUDA) 102 | 103 | ## Nvidia Support 104 | 105 | > [!IMPORTANT] 106 | > This section is currently under testing and may not work as expected, so if you hit any issues or simply have success with this method, please [give feedback in the following Github issue #5](https://github.com/soupglasses/nix-system-graphics/issues/5). 107 | 108 | For a machine running the proprietary nvidia driver, the default mesa drivers will not work. So instead, please add the following to the config section of the system-manager config. 109 | 110 | ```nix 111 | system-graphics.package = pkgs.linuxPackages.nvidia_x11.override { libsOnly = true; kernel = null; }; 112 | # Only required if you enable `system-graphics.enable32Bit` 113 | system-graphics.package32 = (pkgs.linuxPackages.nvidia_x11.override { libsOnly = true; kernel = null; }).lib32; 114 | ``` 115 | 116 | There exists multiple versions of the NVIDIA driver, and they are typically incompatible with one another. So pay extra attention on [pinning the NVIDIA driver to the correct major version](https://nixos.wiki/wiki/Nvidia#Determining_the_Correct_Driver_Version). You should be able to see the current NVIDA driver version you have by running the command `cat /proc/driver/nvidia/version`. 117 | 118 | If you still have issues, you can try to pin your driver to the [spessific version you are using manually](https://nixos.wiki/wiki/Nvidia#Running_Specific_NVIDIA_Driver_Versions), filling out the sha256 sums with `lib.fakeSha256` and removing them as you rebuild. This step however should generally not be needed, and the major version should be enough. 119 | 120 | ## But why another Nix-with-OpenGL project? 121 | 122 | While there are existing solutions like [_nixGL_](https://github.com/nix-community/nixGL) and [_nix-gl-host_](https://github.com/numtide/nix-gl-host), they share a significant drawback: they rely on wrapping the execution of a Nix-built binary with internal environment variables, such as `LIBGL_DRIVER_PATH` and `__EGL_VENDOR_LIBRARY_FILENAMES`. You can find the full list of these variables as used by _nixGL_ [here](https://github.com/nix-community/nixGL/blob/310f8e49a149e4c9ea52f1adf70cdc768ec53f8a/nixGL.nix#L53-L62). 123 | 124 | While this method works, it introduces a key limitation. If your application running via _nixGL_ calls another application, that second application also needs to support _nixGL’s_ specific versions of those graphics libraries, as these get propagated down through the environment variables. In simpler terms, system-installed applications tend to crash or behave unpredictably, as seen in this [issue](https://github.com/nix-community/nixGL/issues/116). You could try unsetting these environment variables on a per-application basis after launching, but this process is both error-prone and time-consuming. 125 | 126 | Now, in contrast, _nix-system-graphics_ addresses this issue by populating `/run/opengl-driver` in the same way NixOS handles it. This eliminates the need to patch or wrap applications built from the Nix store, as they are already configured to use the `/run/opengl-driver` path by default for their `libGL` and `libvulkan` needs. Since there’s no need to wrap any binaries anymore, _all system applications work will work flawlessly, even when launched through a Nix-packaged application_. As a result, using Nix-packaged window managers like _i3_ or _sway_, or a graphically accelerated terminal emulator like _alacritty_, becomes a smooth and hassle-free experience, even when calling graphically accelerated system applications. 127 | 128 | ## Acknowledgements 129 | 130 | Special thanks goes out to [@picnoir](https://github.com/picnoir) who created `nix-gl-host`, who also so kindly helped me with reflecting on the feasabilitiy of this project. 131 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International 2 | 3 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 4 | 5 | Using Creative Commons Public Licenses 6 | 7 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 8 | 9 | Considerations for licensors: Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. More considerations for licensors. 10 | 11 | Considerations for the public: By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. More considerations for the public. 12 | 13 | Creative Commons Attribution 4.0 International Public License 14 | 15 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 16 | 17 | Section 1 – Definitions. 18 | 19 | a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 20 | 21 | b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 22 | 23 | c. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 24 | 25 | d. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 26 | 27 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 28 | 29 | f. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 30 | 31 | g. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 32 | 33 | h. Licensor means the individual(s) or entity(ies) granting rights under this Public License. 34 | 35 | i. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 36 | 37 | j. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 38 | 39 | k. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 40 | 41 | Section 2 – Scope. 42 | 43 | a. License grant. 44 | 45 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 46 | 47 | A. reproduce and Share the Licensed Material, in whole or in part; and 48 | 49 | B. produce, reproduce, and Share Adapted Material. 50 | 51 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 52 | 53 | 3. Term. The term of this Public License is specified in Section 6(a). 54 | 55 | 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 56 | 57 | 5. Downstream recipients. 58 | 59 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 60 | 61 | B. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 62 | 63 | 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 64 | 65 | b. Other rights. 66 | 67 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 68 | 69 | 2. Patent and trademark rights are not licensed under this Public License. 70 | 71 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. 72 | 73 | Section 3 – License Conditions. 74 | 75 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 76 | 77 | a. Attribution. 78 | 79 | 1. If You Share the Licensed Material (including in modified form), You must: 80 | 81 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 82 | 83 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 84 | 85 | ii. a copyright notice; 86 | 87 | iii. a notice that refers to this Public License; 88 | 89 | iv. a notice that refers to the disclaimer of warranties; 90 | 91 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 92 | 93 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 94 | 95 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 96 | 97 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 98 | 99 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 100 | 101 | 4. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. 102 | 103 | Section 4 – Sui Generis Database Rights. 104 | 105 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 106 | 107 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; 108 | 109 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and 110 | 111 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 112 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 113 | 114 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 115 | 116 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. 117 | 118 | b. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 119 | 120 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 121 | 122 | Section 6 – Term and Termination. 123 | 124 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 125 | 126 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 127 | 128 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 129 | 130 | 2. upon express reinstatement by the Licensor. 131 | 132 | c. For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 133 | 134 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 135 | 136 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 137 | 138 | Section 7 – Other Terms and Conditions. 139 | 140 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 141 | 142 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 143 | 144 | Section 8 – Interpretation. 145 | 146 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 147 | 148 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 149 | 150 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 151 | 152 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 153 | 154 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at creativecommons.org/policies, Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 155 | 156 | Creative Commons may be contacted at creativecommons.org. 157 | --------------------------------------------------------------------------------