]> git.lizzy.rs Git - rust.git/commitdiff
Use /etc/os-release to check for NixOS
authorLaurențiu Nicola <lnicola@dend.ro>
Mon, 21 Dec 2020 17:18:50 +0000 (19:18 +0200)
committerLaurențiu Nicola <lnicola@dend.ro>
Mon, 21 Dec 2020 17:21:43 +0000 (19:21 +0200)
The motivation in #5641 isn't too strong, but /etc/os-release exists on
pretty much every Linux distro, while /etc/nixos sounds like an
implementation detail.

editors/code/src/main.ts

index 191960960a34b69f62e12dbf111b9c0441264654..4eaaed62bdc368a7c4d818b532b67d0db0acad5e 100644 (file)
@@ -340,7 +340,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     });
 
     // Patching executable if that's NixOS.
-    if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
+    if (await isNixOs()) {
         await patchelf(dest);
     }
 
@@ -348,6 +348,15 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     return dest;
 }
 
+async function isNixOs(): Promise<boolean> {
+    try {
+        const contents = await fs.readFile("/etc/os-release");
+        return contents.indexOf("ID=nixos") !== -1;
+    } catch (e) {
+        return false;
+    }
+}
+
 async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
     while (true) {
         try {