2
2
// Licensed under GNU GPLv2
3
3
// Final-step Nix invocation methods
4
4
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"
8
6
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
10
18
{
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
12
28
}
13
29
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`.
14
38
fun get_nix()
15
39
{
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
+
16
47
enter_alt_buffer()
17
48
set_title("Building Nix...")
18
49
19
50
// Cleanly exit alt-buffer if hit with ^C
20
51
trust $trap "{nameof teardown}; exit 1" SIGKILL SIGTERM SIGINT SIGABRT$
21
52
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
+
23
62
echo "Pretend we're doing something here..."
24
63
trust $sleep 1$
25
64
@@ -28,7 +67,12 @@ fun get_nix()
28
67
fail 1
29
68
}
30
69
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
32
76
{
33
77
34
78
}
0 commit comments