From baa96f47d832d3d0b6564b1eeebd7b5e7b2ad384 Mon Sep 17 00:00:00 2001 From: Diogo Xavier Date: Mon, 30 Aug 2021 19:15:10 +0100 Subject: [PATCH] Add NixOS support --- cmd/linux.go | 16 +++++++++++ cmd/linuxdb.yaml | 72 +++++++++++++++++++++++++++++++----------------- cmd/system.go | 2 ++ 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/cmd/linux.go b/cmd/linux.go index 81dcd6fc0..8ef7836ac 100644 --- a/cmd/linux.go +++ b/cmd/linux.go @@ -71,6 +71,8 @@ const ( Crux // RHEL distribution RHEL + // NixOS distribution + NixOS ) // DistroInfo contains all the information relating to a linux distribution @@ -183,6 +185,8 @@ func parseOsRelease(osRelease string) *DistroInfo { result.Distribution = EndeavourOS case "crux": result.Distribution = Crux + case "nixos": + result.Distribution = NixOS default: result.Distribution = Unknown } @@ -274,6 +278,18 @@ func PrtGetInstalled(packageName string) (bool, error) { return exitCode == 0, nil } +// NixEnvInstalled uses nix-env to see if a package is installed +func NixEnvInstalled(packageName string) (bool, error) { + program := NewProgramHelper() + nixEnv := program.FindProgram("nix-env") + if nixEnv == nil { + return false, fmt.Errorf("cannot check dependencies: nix-env not found") + } + packageName = strings.ReplaceAll(packageName, "+", `\+`) + _, _, exitCode, _ := nixEnv.Run("-q", packageName) + return exitCode == 0, nil +} + // RequestSupportForDistribution promts the user to submit a request to support their // currently unsupported distribution func RequestSupportForDistribution(distroInfo *DistroInfo) error { diff --git a/cmd/linuxdb.yaml b/cmd/linuxdb.yaml index 04db56c5e..52f6a57cd 100644 --- a/cmd/linuxdb.yaml +++ b/cmd/linuxdb.yaml @@ -318,30 +318,50 @@ distributions: - name: webkit2gtk3-devel help: Please install with `sudo zypper in webkit2gtk3-devel` and try again opensuse-leap: - id: opensuse-leap - releases: - default: - version: default - name: openSUSE Leap - gccversioncommand: *gccdumpfullversion - programs: *opensusedefaultprograms - libraries: *opensusedefaultlibraries + id: opensuse-leap + releases: + default: + version: default + name: openSUSE Leap + gccversioncommand: *gccdumpfullversion + programs: *opensusedefaultprograms + libraries: *opensusedefaultlibraries crux: - id: crux - releases: - default: - version: default - name: Crux Linux - gccversioncommand: *gccdumpversion - programs: - - name: gcc - help: Please install with `sudo prt-get depinst gcc-c++ make` and try again - - name: pkg-config - help: Please install with `sudo prt-get depinst pkg-config` and try again - - name: npm - help: Please install with `sudo prt-get depinst nodejs` and try again - libraries: - - name: gtk3 - help: Please install with `sudo prt-get depinst gtk3` and try again - - name: webkitgtk - help: Please install with `sudo prt-get depinst webkitgtk` and try again + id: crux + releases: + default: + version: default + name: Crux Linux + gccversioncommand: *gccdumpversion + programs: + - name: gcc + help: Please install with `sudo prt-get depinst gcc-c++ make` and try again + - name: pkg-config + help: Please install with `sudo prt-get depinst pkg-config` and try again + - name: npm + help: Please install with `sudo prt-get depinst nodejs` and try again + libraries: + - name: gtk3 + help: Please install with `sudo prt-get depinst gtk3` and try again + - name: webkitgtk + help: Please install with `sudo prt-get depinst webkitgtk` and try again + nixos: + id: nixos + releases: + default: + version: default + name: NixOS + gccversioncommand: *gccdumpversion + programs: + - name: gcc + help: Please install with `nix-env -iA nixos.gcc` + - name: pkg-config + help: Please install with `nix-env -iA nixos.pkg-config` + - name: npm + help: Please install with `nix-env -iA nixos.nodejs` + libraries: + - name: gtk+3 + help: Please install with `nix-env -iA nixos.gtk3` + - name: webkitgtk + help: Please install with `nix-env -iA nixos.nodePackages.webkitgtk` + diff --git a/cmd/system.go b/cmd/system.go index 76ab0b23c..5c2aa6f3c 100644 --- a/cmd/system.go +++ b/cmd/system.go @@ -293,6 +293,8 @@ func CheckDependencies(logger *Logger) (bool, error) { libraryChecker = EOpkgInstalled case Crux: libraryChecker = PrtGetInstalled + case NixOS: + libraryChecker = NixEnvInstalled default: return false, RequestSupportForDistribution(distroInfo) }