22// Licensed under GNU GPLv2
33// Final-step Nix invocation methods
44
5- import { build_nix } from "./builder.ab"
6- import { pull_binary } from "./resources.ab"
7- import { enter_alt_buffer, set_title, teardown } from "./term.ab"
5+ import { file_exists, dir_exists, dir_create } from "std/fs"
86
9- fun is_ignore_system(): Bool
7+ import { enter_alt_buffer, set_title, teardown } from "./term.ab"
8+ import { bail } from "./common.ab"
9+ import { get_osname, get_cache_root, get_system } from "./platform.ab"
10+ import { pull_binary } from "./resources.ab"
11+ import { build_nix } from "./builder.ab"
12+
13+ /// Determine whether Nix is installed system-wide. Nixie can launch the
14+ /// system-wide Nix when it is available, using the script's bundled options.
15+ ///
16+ /// This is the predicate for that behavior.
17+ fun is_nix_installed(): Bool
1018{
11- return env_var_test("nosystem")
19+ // --nixie-ignore-system flag set
20+ if env_var_test("nosystem"): return false
21+
22+ // Simple enough heuristic. In the future, might also check for the `nix`
23+ // command, but that would create a ternary situation where Nixie's static
24+ // Nix would need to use the system store.
25+ if dir_exists("/nix/store"): return true
26+
27+ return false
1228}
1329
30+ /// Attempt to retrieve the static Nix binary by all known methods.
31+ ///
32+ /// This function will first try to extract or download a static executable
33+ /// for the current system, and if it fails, a local build from source will be
34+ /// attempted.
35+ ///
36+ /// **NOTE**: On macOS, this function is also responsible for downloading
37+ /// `libfakedir.dylib`.
1438fun get_nix()
1539{
40+ let cache_root = get_cache_root()
41+ let osname = get_osname()
42+ let system = get_system()
43+
44+ let nix_path = "{cache_root}/nix-static"
45+ let fakedir_path = "{cache_root}/nix-lib/libfakedir.dylib"
46+
1647 enter_alt_buffer()
1748 set_title("Building Nix...")
1849
1950 // Cleanly exit alt-buffer if hit with ^C
2051 trust $trap "{nameof teardown}; exit 1" SIGKILL SIGTERM SIGINT SIGABRT$
2152
22- //TODO: ✨MAGIC✨
53+ if osname == "Darwin" and not file_exists(fakedir_path) {
54+ dir_create("{cache_root}/nix-lib")
55+ trust pull_binary("libfakedir.dylib", fakedir_path)
56+ }
57+
58+ if not file_exists(nix_path) {
59+ trust pull_binary("nix.{system}", nix_path)
60+ }
61+
2362 echo "Pretend we're doing something here..."
2463 trust $sleep 1$
2564
@@ -28,7 +67,12 @@ fun get_nix()
2867 fail 1
2968}
3069
31- fun launch_darwin_workaround()
70+ /// Launch Nix with the proper environment variables for fakedir and OpenSSL.
71+ ///
72+ /// This is required because macOS has no namespacing facility, and Nix will
73+ /// not attempt to use the system-wide CA bundle by default. This function
74+ /// addresses both issues.
75+ fun launch_darwin_workaround(name: Text, args: [Text]): Null
3276{
3377
3478}
0 commit comments