/nix-environments

Repository to maintain out-of-tree shell.nix files (maintainer=@mic92)

Primary LanguageNixMIT LicenseMIT

Nix-environments

Repository to maintain out-of-tree shell.nix files.

For some projects it is non-trivial to get a minimal develop environment that work with Nix/NixOS. The purpose of this repository is to share shell.nix expression that help to get started with those projects. The goal of the project is not to build or package those projects (which is often even harder) but to document the build requirements.

What environments should include:

  • dependencies to build, develop or test the project

What environments should not include:

  • opinionated, user-specific dependencies for example editors or favorite debugging tools

Current available environments

Name Attribute
Arduino arduino
cc2538-bsl cc2538-bsl
Jruby jruby
Firefox firefox
Git git
Github Pages github-pages
Homeassistant home-assistant
Nannou nannou
Phoronix test suite phoronix-test-suite
OpenWRT openwrt
SPEC benchmark spec-benchmark
Yocto yocto
Xilinx vitis xilinx-vitis
InfiniSim infinisim
InfiniTime infinitime
buildroot buildroot

How to use

Stable Nix

All environments referenced in default.nix can be loaded by running nix-shell like that:

$ nix-shell https://github.com/nix-community/nix-environments/archive/master.tar.gz -A PROJECT_NAME

for example openwrt:

$ nix-shell https://github.com/nix-community/nix-environments/archive/master.tar.gz -A openwrt

To apply custom modification one can also import environments into their own shell.nix files and override them. Note that this approach does currently not work for buildFHSUserEnv-based environments!

{ pkgs ? import <nixpkgs> {} }:
let
  envs = (import (builtins.fetchTarball {
    url = "https://github.com/nix-community/nix-environments/archive/master.tar.gz";
  }));
  phoronix = envs.phoronix-test-suite { inherit pkgs; };
in (phoronix.overrideAttrs (old: {
  # this will append python to the existing dependencies
  buildInputs = old.buildInputs ++ [ pkgs.python3 ];
}))

To provide additional packages to buildFHSUserEnv-based environments you can use the extraPkgs attribute and import the shell file directly:

{pkgs ? import <nixpkgs> {}}: 
let
  yoctoEnv = ((builtins.fetchTarball {
      url = "https://github.com/nix-community/nix-environments/archive/master.tar.gz";
    })
    + "/envs/yocto/shell.nix");
in
  (import yoctoEnv) {
    inherit pkgs;
    extraPkgs = [pkgs.hello];
  }

Nix Flakes

Nix-environments are also available as Flake outputs. Flakes are an experimental new way to handle Nix expressions.

For dropping into the environment for the OpenWRT project, just run:

nix develop --no-write-lock-file github:nix-community/nix-environments#openwrt

The last part is a flake URL and is an abbreviation of github:nix-community/nix-environments#devShells.SYSTEM.openwrt, where SYSTEM is your current system, e.g. x86_64-linux.

You can also use these environments in your own flake and extend them:

{
  inputs.nix-environments.url = "github:nix-community/nix-environments";

  outputs = { self, nixpkgs, nix-environments }: let
    # Replace this string with your actual system, e.g. "x86_64-linux"
    system = "SYSTEM";
  in {
    devShell.${system} = let
        pkgs = import nixpkgs { inherit system; };
      in nix-environments.devShells.${system}.phoronix-test-suite.overrideAttrs (old: {
        buildInputs = old.buildInputs ++ [ pkgs.python3 ];
      });
  };
}

Similar projects