~ruther/nixos-config

ref: a1128e507b85a32d4a700727c24d11151284a954 nixos-config/home/modules/profiles/desktop/default.nix -rw-r--r-- 1.8 KiB
a1128e50 — Frantisek Bohacek feat(home): add desktop session startup options 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ config, lib, pkgs, ... }:

{
  imports = [
    ./qtile
    ./dwl
    ./gnome.nix
  ];

  options = {
    profiles.desktop = {
      enable = lib.mkEnableOption "desktop";
    };
  };

  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
        '';
      };
    };
  };
}
Do not follow this link