~ruther/nixos-config

7853b4870f22b764029164454ea105e8d76c2c2d — Frantisek Bohacek 8 months ago a1128e5
feat: use desktopSessions options instead of custom .sessions folder
M home/modules/default.nix => home/modules/default.nix +2 -0
@@ 4,5 4,7 @@
    ./profiles/default.nix
    ./programs/default.nix
    ./themes.nix
    ./sessions
    ./sessions/default-hm-impl.nix
  ];
}

M home/modules/profiles/desktop/default.nix => home/modules/profiles/desktop/default.nix +1 -60
@@ 14,65 14,6 @@
  };

  config = lib.mkIf config.profiles.desktop.enable {
    home.file.".start-session".source = pkgs.writeShellScript "start-session" ''
      sessions=($(ls ~/.sessions))
      session_indices=(''${!sessions[@]})

      timeout=3
      selected="start-dwl" # default

      echo "Default session to start is $selected"

      echo "Available sessions:"
      for i in ''${!sessions[@]}; do
          echo "  $((i+1))) ''${sessions[$i]}"
      done
      echo "  q) Enter tty."

      echo -n "Choose session to start: "
      read -t"$timeout" -n1 user_input
      echo

      if [[ $user_input == "q" ]]; then
          exit
      elif [[ $user_input ]]; then
          user_input=$((user_input-1))
          echo $user_input
          echo ''${session_indices[@]}
          if [[ " ''${session_indices[@]} " =~ " $user_input " ]]; then
              selected="''${sessions[$user_input]}"
              echo "Got $user_input. Going to start $selected"
          else
              echo "Got unknown option. Exiting."
              exit
          fi
      else
          echo "Got no input, starting $selected"
      fi

      echo "Going to start $selected"

      exec "~/.sessions/$selected"

    '';

    programs = {
      bash = {
        enable = true;
        profileExtra =  ''
          if [[ "$(tty)" == "/dev/tty1" && "$(id -u)" != 0 ]]; then
            ~/.start-session
          fi
        '';
      };
      zsh = {
        enable = true;
        profileExtra = ''
          if [[ "$(tty)" == "/dev/tty1" && "$(id -u)" != 0 ]]; then
            ~/.start-session
          fi
        '';
      };
    };
    desktopSessions.enable = true;
  };
}

M home/modules/profiles/desktop/dwl/default.nix => home/modules/profiles/desktop/dwl/default.nix +25 -1
@@ 19,6 19,8 @@ let
  wlopmDisableScreens = wlopmScreens "off";
  wlopmEnableScreens = wlopmScreens "on";

  dwl = inputs.self.packages.${pkgs.system}.dwl;

  emacs-anywhere = pkgs.writeShellScriptBin "emacs-anywhere" ''
    emacs --batch --script "${./emacs-anywhere.el}" | wl-copy
  '';


@@ 35,6 37,28 @@ in {
  };

  config = lib.mkIf config.profiles.desktop.dwl.enable {
    desktopSessions.instances.dwl = let
      dwlInternal = pkgs.writeShellScript "dwl-s" ''
        exec <&-
        dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP DISPLAY
        systemctl start --user wlr-session.target
      '';
    in {
      environment = {
        XDG_CURRENT_DESKTOP = "wlroots";
        XDG_BACKEND = "wayland";
        QT_QPA_PLATFORM = "wayland";
        MOZ_ENABLE_WAYLAND = "1";
        _JAVA_AWT_WM_NONREPARENTING = "1";
      };

      executable = lib.getExe dwl;
      arguments = [
        "-s"
        "${dwlInternal}"
      ];
    };

    profiles.desktop.enable = true;
    systemd.user.targets.wlr-session = {
      Unit = {


@@ 105,7 129,7 @@ in {

      emacs-anywhere

      inputs.self.packages.${pkgs.system}.dwl
      dwl
    ];

    programs = {

M nixos/hosts/laptop-phobos/home.nix => nixos/hosts/laptop-phobos/home.nix +13 -9
@@ 5,22 5,26 @@ let
  #   if etc-file.text != null then
  #     etc-file.text else
  #     (builtins.readFile etc-file.source);
  readEtcFile = etc-file: lib.mkMerge [
    (lib.mkIf (etc-file.text != null) etc-file.text)
    (lib.mkIf (etc-file.source != null) (builtins.readFile etc-file.source))
  ];
  # NO IFDs, future me!!!!
  # readEtcFile = etc-file: lib.mkMerge [
  #   (lib.mkIf (etc-file.text != null) etc-file.text)
  #   (lib.mkIf (etc-file.source != null) (builtins.readFile etc-file.source))
  # ];
in {
  profiles.development.enable = true;
  profiles.desktop.dwl.enable = true;
  profiles.matrix.enable = true;

  desktopSessions.defaultSession = "dwl";

  # Don't Starve doesn't pick up /etc/alsa/conf.d.
  # ALSA lib conf.c:4136:(config_file_load) cannot stat file/directory /etc/alsa/conf.d
  # This is a workaround that puts the stuff from /etc/alsa/conf.d into ~/.asoundrc that
  # Don't starve is able to read.
  home.file.".asoundrc".text = lib.mkMerge [
    (readEtcFile osConfig.environment.etc."alsa/conf.d/49-pipewire-modules.conf")
    (readEtcFile osConfig.environment.etc."alsa/conf.d/50-pipewire.conf")
    (readEtcFile osConfig.environment.etc."alsa/conf.d/99-pipewire-default.conf")
  ];
  # home.file.".asoundrc".text = lib.mkMerge [
    # TODO: get rid of the ifd before commenting this out!
    # (readEtcFile osConfig.environment.etc."alsa/conf.d/49-pipewire-modules.conf")
    # (readEtcFile osConfig.environment.etc."alsa/conf.d/50-pipewire.conf")
    # (readEtcFile osConfig.environment.etc."alsa/conf.d/99-pipewire-default.conf")
  # ];
}

Do not follow this link