Nix package manager windows

You can install NixOS on physical hardware by burning one of the CD images onto a blank CD/DVD disk, or by copying it onto a USB stick. For installation instructions, please see the manual.

Graphical ISO image

The graphical installation ISO image contains the graphical NixOS installer as well as a Desktop Environment and several applications. It’s a live CD, so it allows you to get an impression of NixOS (and the Nix package manager) without installing it.

Note that while the image itself only comes in GNOME and Plasma variations, the included installer also allows installing various other desktops, or installing without a desktop.

Minimal ISO image

The minimal installation ISO image does not contain the graphical user interface, and is therefore a lot smaller. You have to run the installer from the console. It contains a number of rescue tools.

NixOS AMIs

NixOS can be deployed to Amazon EC2 using our official AMI. We publish
AMIs to all AWS regions for both x86_64 and arm64 on a weekly basis.

We will start deprecating and garbage collecting images older than 90 days
in the future.
This is why we suggest using a terraform data source or the AWS API to query
for the latest AMI.

Via Terraform / OpenTofu

You can easily query for the latest AMI using a data source:

provider "aws" {
  region = "eu-central-1"
}

data "aws_ami" "nixos_arm64" {
  owners      = ["427812963091"]
  most_recent = true

  filter {
    name   = "name"
    values = ["nixos/24.11*"]
  }
  filter {
    name   = "architecture"
    values = ["arm64"] # or "x86_64"
  }
}

resource "aws_instance" "nixos_arm64" {
  ami           = data.aws_ami.nixos_arm64.id
  instance_type = "t4g.nano"
}

Via Command Line / AWS API

The DescribeImages API
can be used to query the latest AMI too:

aws ec2 describe-images --owners 427812963091  --filter 'Name=name,Values=nixos/24.11*' 'Name=architecture,Values=arm64' --query 'sort_by(Images, &CreationDate)'

Search for specific AMIs

You can also use the Image searcher to find
a specific AMI. Do note that we intend to deprecate images older than 90 days
automatically and we do not recommend hardcoding AMI ids.

Nix, the purely functional package manager

Nix is a new take on package management that is fairly unique. Because of its
purity aspects, a lot of issues found in traditional package managers don’t
appear with Nix.

To find out more about the tool, usage and installation instructions, please
read the manual, which is available on the Nix website at
http://nixos.org/nix/manual.

Contributing

Take a look at the Hacking Section
of the manual. It helps you to get started with building Nix from source.

License

Nix is released under the LGPL v2.1

This product includes software developed by the OpenSSL Project for
use in the OpenSSL Toolkit.

Using nix, the functional package manager on the Windows Subsystem for Linux is fairly easy, however a couple of additional steps need to be done.

WARNING

An update is published, using wsl2 & NixOS in December 2023.

  1. Enable WSL, see Windows Subsystem for Linux Installation Guide for Windows 10
  2. Pick Ubuntu inside the Microsoft Store
  3. Update Ubuntu
    1
    2
    
     sudo apt update
     sudo apt upgrade
    

  4. Create the /etc/nix directory
  5. Create & edit /etc/nix/nix.conf, add following items:
    1
    2
    
     sandbox = false
     use-sqlite-wal = false
    

    Unfortunately there are still some things that require this workaround:

    • sandbox = false is following bug: NixOS/nix#2651: Installing Nix fails on Ubuntu 18.04.1 LTS Error: cloning builder process: Invalid argument
    • use-sqlite-wal = false are following bugs: NixOS/nix#2292: WSL Nix installation db.sqlite is busy and NixOS/nix#1203: nix-shell under Windows WSL is broken
  6. Install nix:
    1
    
     curl -L https://nixos.org/nix/install | sh
    

You are done, let’s test it:

1
  nix-shell -p busybox --run 'echo $PATH'

Nix on Windows

Some extra useful links:

  • tweag.io: Nix on the Windows Subsystem for Linux
  • nixos.org/nix

January 19, 2011 by invalidmagic

motivation

nix (see [2])  is a package manager like apt (used in debian/ubuntu) or portage (used in gentoo). windows does have a package manager which is typical among linux distributions. so here some recent findings and how to use nix (and nixpkgs) on windows.

reproduction of my nix system

setup of my system:

  • core 2 duo processor
  • windows xp sp3
  • cygwin (setup.exe version 2.738) with a full installation [1] (some 2-7 GB, 1h download)
    using setup.exe, do use ‘default parameters’ everywhere, expect for the software selection: use all (do not install the source, binaries are enough)
  • nix 0.16 release from [2]
  • install (as mentioned in the docs) to a ntfs partition

components i used (get installed using cygwin::setup.exe:

  • gcc version 4.3.4 20090804 (release1) (gcc), target i686-pc-cygwin
  • libtoolize (GNU libtool) 2.4
  • aclocal (GNU automake) 1.11.1
  • autoheader (GNU Autoconf) 2.68
  • automake (GNU automake) 1.11.1
  • autoconf (GNU Autoconf) 2.68

how to build

as there is no windows installer (for example using NSIS) you have to bootstrap nix from source.

  1. extract nix-0.16 to c:\nix
  2. start the cygwin shell (desktop icon)
  3. in the shell, type: ‘cd /cygdrive/c/nix/nix-0.16
  4. type: ‘./bootstrap.sh‘ (this is very important)
    that is why several of my attempts to get nix running failed ;P
  5. type: ‘./configure
  6. type: ‘make install
  7. afterwards you can use it with: ‘nix-env -qa ‘*’‘ for example

how to use nix

this is quite easy but it does not work as mentioned in the documentation (which worked only for unix systems so far). the full cygwin installation installes many tools.

  1. check your environmen for nix, type ‘nix-env.exe’ and test if that program works (should be in the path)
  2. if ‘nix-env.exe’ does not work, check /usr/local/bin for a propper nix installation
  3. check if there is a unrar tool already (not included in full-cygwin installation with: ‘unrar.exe
  4. you have to subscribe to a nix channel, see the nix documentation: chapter 2. quick start [4]
  5. if ‘nix-env.exe’ works, install ‘unrar’ using: ‘nix-env.exe -i unrar
    you should see compiler stuff and it installs a million *.drv files…
  6. now type: ‘unrar.exe‘, should say: “bash: unrar.exe: command not found”
  7. now type: “export PATH=~./nix-profile/bin:$PATH
  8. and try the command from step 5 again, now you should get a working ‘unrar.exe’ installation

what worked using nix on cygwin-windows

most of the software related to X did not work, as windows and mesa don’t go along nicely. i’ve tried a few programs:

  • wget.exe worked (checked with ‘which wget’) and a download
  • hello.exe worked (GNU hello)
  • unrar.exe worked (compiled, installed, probably to work, didn’t extract anything)
  • qt (nix throws a nix exception): unsupported platform for Mesa
  • irssi (nix tries to compile the needed software but fails at glib-2.24.1)
  • firefox (nix throws a nix exception): flashplayer is not supported on this platform

summary

great to have nix on windows. no it’s time to use it, here are a bunch of scenarios:

  • use it to create windows software
  • use it to create installers (using NSIS)

but both points would be  independent of nix, so this results in a very nice build system. maybe combined with hyrdra this is a great way to build software.

links

[1] http://www.cygwin.com/cygwin-ug-net/setup-net.html

[2] http://nixos.org/nix/

[3] http://hydra.nixos.org/build/858291/download/1/manual/

[4] http://hydra.nixos.org/build/858291/download/1/manual/#chap-quick-start

Posted in linux, package manager, qt, technology, windows | 3 Comments

Nix Reference Manual

Introduction

Nix is a purely functional package manager. This means that it
treats packages like values in purely functional programming languages
such as Haskell — they are built by functions that don’t have
side-effects, and they never change after they have been built. Nix
stores packages in the Nix store, usually the directory
/nix/store, where each package has its own unique subdirectory such
as

/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-33.1/

where b6gvzjyb2pg0… is a unique identifier for the package that
captures all its dependencies (it’s a cryptographic hash of the
package’s build dependency graph). This enables many powerful
features.

Multiple versions

You can have multiple versions or variants of a package
installed at the same time. This is especially important when
different applications have dependencies on different versions of the
same package — it prevents the “DLL hell”. Because of the hashing
scheme, different versions of a package end up in different paths in
the Nix store, so they don’t interfere with each other.

An important consequence is that operations like upgrading or
uninstalling an application cannot break other applications, since
these operations never “destructively” update or delete files that are
used by other packages.

Complete dependencies

Nix helps you make sure that package dependency specifications are
complete. In general, when you’re making a package for a package
management system like RPM, you have to specify for each package what
its dependencies are, but there are no guarantees that this
specification is complete. If you forget a dependency, then the
package will build and work correctly on your machine if you have
the dependency installed, but not on the end user’s machine if it’s
not there.

Since Nix on the other hand doesn’t install packages in “global”
locations like /usr/bin but in package-specific directories, the
risk of incomplete dependencies is greatly reduced. This is because
tools such as compilers don’t search in per-packages directories such
as /nix/store/5lbfaxb722zp…-openssl-0.9.8d/include, so if a package
builds correctly on your system, this is because you specified the
dependency explicitly. This takes care of the build-time dependencies.

Once a package is built, runtime dependencies are found by scanning
binaries for the hash parts of Nix store paths (such as r8vvq9kq…).
This sounds risky, but it works extremely well.

Multi-user support

Nix has multi-user support. This means that non-privileged users can
securely install software. Each user can have a different profile,
a set of packages in the Nix store that appear in the user’s PATH.
If a user installs a package that another user has already installed
previously, the package won’t be built or downloaded a second time.
At the same time, it is not possible for one user to inject a Trojan
horse into a package that might be used by another user.

Atomic upgrades and rollbacks

Since package management operations never overwrite packages in the
Nix store but just add new versions in different paths, they are
atomic. So during a package upgrade, there is no time window in
which the package has some files from the old version and some files
from the new version — which would be bad because a program might well
crash if it’s started during that period.

And since packages aren’t overwritten, the old versions are still
there after an upgrade. This means that you can roll back to the
old version:

$ nix-env --upgrade --attr nixpkgs.some-package
$ nix-env --rollback

Garbage collection

When you uninstall a package like this…

$ nix-env --uninstall firefox

the package isn’t deleted from the system right away (after all, you
might want to do a rollback, or it might be in the profiles of other
users). Instead, unused packages can be deleted safely by running the
garbage collector:

$ nix-collect-garbage

This deletes all packages that aren’t in use by any user profile or by
a currently running program.

Functional package language

Packages are built from Nix expressions, which is a simple
functional language. A Nix expression describes everything that goes
into a package build task (a “derivation”): other packages, sources,
the build script, environment variables for the build script, etc.
Nix tries very hard to ensure that Nix expressions are
deterministic: building a Nix expression twice should yield the same
result.

Because it’s a functional language, it’s easy to support
building variants of a package: turn the Nix expression into a
function and call it any number of times with the appropriate
arguments. Due to the hashing scheme, variants don’t conflict with
each other in the Nix store.

Transparent source/binary deployment

Nix expressions generally describe how to build a package from
source, so an installation action like

$ nix-env --install --attr nixpkgs.firefox

could cause quite a bit of build activity, as not only Firefox but
also all its dependencies (all the way up to the C library and the
compiler) would have to be built, at least if they are not already in the
Nix store. This is a source deployment model. For most users,
building from source is not very pleasant as it takes far too long.
However, Nix can automatically skip building from source and instead
use a binary cache, a web server that provides pre-built
binaries. For instance, when asked to build
/nix/store/b6gvzjyb2pg0…-firefox-33.1 from source, Nix would first
check if the file https://cache.nixos.org/b6gvzjyb2pg0….narinfo
exists, and if so, fetch the pre-built binary referenced from there;
otherwise, it would fall back to building from source.

Nix Packages collection

We provide a large set of Nix expressions containing hundreds of
existing Unix packages, the Nix Packages collection (Nixpkgs).

Managing build environments

Nix is extremely useful for developers as it makes it easy to
automatically set up the build environment for a package. Given a Nix
expression that describes the dependencies of your package, the
command nix-shell will build or download those dependencies if
they’re not already in your Nix store, and then start a Bash shell in
which all necessary environment variables (such as compiler search
paths) are set.

For example, the following command gets all dependencies of the
Pan newsreader, as described by its
Nix expression:

$ nix-shell '<nixpkgs>' --attr pan

You’re then dropped into a shell where you can edit, build and test
the package:

[nix-shell]$ unpackPhase
[nix-shell]$ cd pan-*
[nix-shell]$ configurePhase
[nix-shell]$ buildPhase
[nix-shell]$ ./pan/gui/pan

Portability

Nix runs on Linux and macOS.

NixOS

NixOS is a Linux distribution based on Nix. It uses Nix not just for
package management but also to manage the system configuration (e.g.,
to build configuration files in /etc). This means, among other
things, that it is easy to roll back the entire configuration of the
system to an earlier state. Also, users can install software without
root privileges. For more information and downloads, see the NixOS
homepage.

License

Nix is released under the terms of the GNU LGPLv2.1 or (at your
option) any later
version.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Опишите работу с контекстным меню windows 7
  • Удаленная установка windows через касперского
  • Color picker for windows
  • Dell inspiron 3582 драйвера windows 7
  • Для выполнения этой команды требуются права администратора windows 10