Skip to content

Commit 9bb8b66

Browse files
author
Emery Hemingway
committed
Implement NixOS distro check
1 parent e5ed4c1 commit 9bb8b66

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/pure/distros.nim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ from strutils import contains, toLowerAscii
2929

3030
when not defined(nimscript):
3131
from osproc import execProcess
32+
from os import existsEnv
3233

3334
type
3435
Distribution* {.pure.} = enum ## the list of known distributions
@@ -105,7 +106,7 @@ type
105106
Clonezilla
106107
SteamOS
107108
Absolute
108-
NixOS
109+
NixOS ## NixOS or a Nix build environment
109110
AUSTRUMI
110111
Arya
111112
Porteus
@@ -161,6 +162,9 @@ proc detectOsImpl(d: Distribution): bool =
161162
of Distribution.BSD: result = defined(bsd)
162163
of Distribution.ArchLinux:
163164
result = "arch" in toLowerAscii(uname())
165+
of Distribution.NixOS:
166+
result = existsEnv("NIX_BUILD_TOP") or existsEnv("__NIXOS_SET_ENVIRONMENT_DONE")
167+
# Check if this is a Nix build or NixOS environment
164168
of Distribution.OpenSUSE:
165169
result = "suse" in toLowerAscii(uname()) or "suse" in toLowerAscii(release())
166170
of Distribution.GoboLinux:

0 commit comments

Comments
 (0)