/ modules / virtualization / nspawn / containers / graphicalExample.nix
graphicalExample.nix
  1  {
  2        graphicalExample = let
  3              #hostCfg = config;
  4  
  5        in {
  6          bindMounts = {
  7            waylandDisplay = rec {
  8              hostPath = "/run/user/${toString base.userUid}";
  9              mountPoint = hostPath;
 10              isReadOnly = false;
 11            };
 12            x11Display = rec {
 13              hostPath = "/tmp/.X11-unix";
 14              mountPoint = hostPath;
 15              isReadOnly = true;
 16            };
 17            dri = rec {
 18              hostPath = "/dev/dri";
 19              mountPoint = hostPath;
 20            };
 21          };
 22  
 23          config = {
 24            system.stateVersion = inputs.system.stateVersion-unstable;
 25            imports = [
 26              inputs.home-manager.nixosModules.home-manager
 27              ./common/home.nix
 28            ];
 29            users.users.${base.userName} = {
 30              uid = base.userUid;
 31              isNormalUser = true;
 32              initialPassword = "secret";
 33              extraGroups = [ "wheel" ];
 34            };
 35  
 36            fonts.packages = with pkgs; [
 37              dejavu_fonts  # Default font used by Alacritty.
 38            ];
 39  
 40            hardware.graphics = {
 41              enable = true;
 42            };
 43  
 44            environment.systemPackages = with pkgs; [
 45              #jetbrains.idea-community
 46              fastfetch
 47            ];
 48  
 49            home-manager = {
 50              useGlobalPkgs = true;
 51              users.${base.userName} = {
 52                #imports = [ ./home.nix ];
 53                programs.bash.enable = true;
 54                gtk.enable = true;
 55                wayland.windowManager.sway = {
 56                  enable = true;
 57                };
 58                home = {
 59                  packages = with pkgs; [
 60                    alacritty
 61                  ];
 62                  sessionVariables = {
 63                    WAYLAND_DISPLAY                     = "wayland-1";
 64                    QT_QPA_PLATFORM                     = "wayland";
 65                    QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
 66                    SDL_VIDEODRIVER                     = "wayland";
 67                    CLUTTER_BACKEND                     = "wayland";
 68                    MOZ_ENABLE_WAYLAND                  = "1";
 69                    _JAVA_AWT_WM_NONREPARENTING         = "1";
 70                    _JAVA_OPTIONS                       = "-Dawt.useSystemAAFontSettings=lcd";
 71                    XDG_RUNTIME_DIR                     = "/run/user/${toString base.userUid}";
 72                    DISPLAY                             = ":0";
 73                  };
 74                  stateVersion = config.system.stateVersion;
 75                };
 76              };
 77            };
 78  
 79            systemd.services = {
 80              fix-nix-dirs = let
 81                profileDir = "/nix/var/nix/profiles/per-user/${base.userName}";
 82                gcrootsDir = "/nix/var/nix/gcroots/per-user/${base.userName}";
 83              in {
 84                script = ''
 85                  #!${pkgs.stdenv.shell}
 86                  set -euo pipefail
 87  
 88                  mkdir -p ${profileDir} ${gcrootsDir}
 89                  chown ${base.userName}:root ${profileDir} ${gcrootsDir}
 90                '';
 91                wantedBy = [ "multi-user.target" ];
 92                serviceConfig = {
 93                  Type = "oneshot";
 94                };
 95              };
 96  
 97              fix-run-permission = {
 98                script = ''
 99                  #!${pkgs.stdenv.shell}
100                  set -euo pipefail
101  
102                  chown ${base.userName}:users /run/user/${toString base.userUid}
103                  chmod u=rwx /run/user/${toString base.userUid}
104                '';
105                wantedBy = [ "multi-user.target" ];
106                serviceConfig = {
107                  Type = "oneshot";
108                };
109              };
110            };
111          };
112        };
113      };