]>
git.scottworley.com Git - nix-env-apps/blob - apps.py
4b0d0d581a5c917d442baf3f64432c9b1b37c36c
1 from gi
.repository
import Gtk
6 gi
.require_version("Gtk", "4.0")
10 config_dir
= os
.path
.join(
11 os
.environ
.get('XDG_CONFIG_HOME', os
.path
.expanduser('~/.config')),
14 os
.makedirs(config_dir
, exist_ok
=True)
15 config_file
= os
.path
.join(config_dir
, 'userPackages.nix')
17 with open(config_file
, mode
="x") as f
:
18 f
.write('''final: prev: {
19 userPackages = final.buildEnv {
20 name = "userPackages";
21 paths = (with final; [
29 except FileExistsError
:
31 subprocess
.run(['xdg-open', config_file
], check
=True)
34 def try_exec_terminal(terminal
, args
):
36 os
.execvp(terminal
, [terminal
] + args
)
37 except FileNotFoundError
:
42 command
= ['nix-env', '-riA', 'nixos.userPackages']
43 command_string
= ' '.join(command
)
44 close_string
= ''' && read -p "SUCCESS: Press ENTER to close this window" || read -p "FAILURE: Press ENTER to close this window"'''
45 # This should be a simple `xdg-terminal` invocation, but as of 2025,
46 # xdg-terminal is extremely broken in Gnome:
47 # * It doesn't cause a terminal window to appear
48 # * It doesn't run the given command
49 # * It exits with status 0, so you can't even tell that it failed
50 # * There's no way for the user to configure their preferred terminal?
51 # So we just try launching a whole bunch of terminals until we find one
54 try_exec_terminal('kitty', ['sh', '-c', command_string
+ close_string
])
57 '-e', 'sh', '-c', command_string
+ close_string
])
58 try_exec_terminal('kgx', ['--'] + command
)
61 '-e', 'sh', '-c', command_string
+ close_string
])
62 try_exec_terminal('xfce4-terminal', ['--hold', '-e', command_string
])
63 try_exec_terminal('st', ['sh', '-c', command_string
+ close_string
])
66 '-e', 'sh', '-c', command_string
+ close_string
])
69 '-e', 'sh', '-c', command_string
+ close_string
])
71 # Don't even try gnome-terminal. Sometimes it will start, but not run the command,
72 # and exit with status 0 so we wouldn't even be able to tell that there was a problem.
73 # try_exec_terminal('gnome-terminal', ['--', 'sh', '-c', command_string + close_string])
75 # As a last resort, run the command directly, without a terminal, where
76 # the user probably can't see it. :(
77 os
.execvp(command
[0], command
)
81 win
= Gtk
.ApplicationWindow(application
=app
)
83 box
.set_orientation(Gtk
.Orientation
.VERTICAL
)
84 edit
= Gtk
.Button(label
="Edit Configuration")
85 apply = Gtk
.Button(label
="Apply Configuration")
86 edit
.connect('clicked', on_edit
)
87 apply.connect('clicked', on_apply
)
95 app
= Gtk
.Application(application_id
='net.chkno.nix-env-apps')
96 app
.connect('activate', on_activate
)
100 if __name__
== '__main__':