File nix-installer.spec of Package nix-installer

#
# spec file for package nix-installer
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# https://github.com/DeterminateSystems/nix-installer#building-a-binary
%define __rustflags --cfg tokio_unstable

# the nix version is pinned in the flake.nix file
# https://github.com/DeterminateSystems/nix-installer/blob/v%{version}/flake.nix
%define nix_version 2.32.4

# the nixd has is pinned in the flake.lock file
# https://github.com/DeterminateSystems/nix-installer/blob/v%{version}/flake.lock#L49
%define determinate_flake_hash v3.14.0

Name:           nix-installer
Version:        3.14.0
Release:        0
Summary:	Install Nix and flakes with the fast and reliable
License:        LGPL-2.1
URL:            https://github.com/DeterminateSystems/nix-installer
Source0:        %{name}-%{version}.tar.gz
Source1:        vendor.tar.zst
# nix tarballs
Source2:        https://releases.nixos.org/nix/nix-%{nix_version}/nix-%{nix_version}-x86_64-linux.tar.xz
Source3:        https://releases.nixos.org/nix/nix-%{nix_version}/nix-%{nix_version}-aarch64-linux.tar.xz
# nixd binaries
Source5:        https://install.determinate.systems/determinate-nixd/rev/%{determinate_flake_hash}/x86_64-linux#/nixd-x86_64
Source6:        https://install.determinate.systems/determinate-nixd/rev/%{determinate_flake_hash}/aarch64-linux#/nixd-aarch64
#
Source11:       Makefile
Source12:       PACKAGING_README.md
BuildRequires:  cargo-packaging
BuildRequires:  zstd
BuildRequires:  cargo
ExclusiveArch:  x86_64 aarch64

%description
A fast, friendly, and reliable tool to help you use Nix with Flakes everywhere.

%prep
%autosetup -a 1 -p 1
mkdir -p .cargo
# Remove exec bits to prevent an issue in fedora shebang checking. Uncomment only if required.
# find vendor -type f -name \*.rs -exec chmod -x '{}' \;

%ifarch x86_64
cp %{SOURCE2} src/
cp %{SOURCE5} src/
%endif

%ifarch aarch64
cp %{SOURCE3} src/
cp %{SOURCE6} src/
%endif

%build
export DETERMINATE_NIXD_BINARY_PATH=nixd-%{_arch}
export DETERMINATE_NIX_TARBALL_PATH=nix-%{nix_version}-%{_arch}-linux.tar.xz
export NIX_INSTALLER_TARBALL_PATH=nix-%{nix_version}-%{_arch}-linux.tar.xz
export NIX_TARBALL_URL="https://releases.nixos.org/nix/nix-%{nix_version}/nix-%{nix_version}-%{_arch}.tar.xz"
%{cargo_build}

%install
install -D -d -m 0755 %{buildroot}%{_bindir}
install -m 0755 %{_builddir}/%{name}-%{version}/target/release/%{name} %{buildroot}%{_bindir}/%{name}

%check
# run the tests
export DETERMINATE_NIXD_BINARY_PATH=nixd-%{_arch}
export DETERMINATE_NIX_TARBALL_PATH=nix-%{nix_version}-%{_arch}-linux.tar.xz
export NIX_INSTALLER_TARBALL_PATH=nix-%{nix_version}-%{_arch}-linux.tar.xz
export NIX_TARBALL_URL="https://releases.nixos.org/nix/nix-%{nix_version}/nix-%{nix_version}-%{_arch}.tar.xz"
%{cargo_test}

%files
%{_bindir}/nix-installer

%changelog
openSUSE Build Service is sponsored by