Skip to content

Nix

Cheatsheet

Run temporary fhsChrootEnv

Runs FHS-compatible lightweight sandbox. More info: https://nixos.org/nixpkgs/manual/#sec-fhs-environments

$ nix-build -E '(import <nixpkgs> {}).buildFHSUserEnv {name = "fhs"; targetPkgs = pkgs: (with pkgs; []); }'
$ ./result/bin/fhs

Uninstall package

$ nix-env --uninstall firefox
$ nix-collect-garbage

Install package from unstable while running stable

$ nix-channel --add https://nixos.org/channels/nixos-unstable unstable
$ nix-channel --update
$ nix-channel --list

And then install via nix-env -iA unstable.<package_name>.

Search for package

nix-env -qaP | grep gitea
nixos.gitea                   gitea-1.9.4
unstable.gitea                gitea-1.9.5

Upgrade NixOS

[root] nixos-rebuild switch --upgrade

Run as root or use sudo.

Nix environment file

See https://maybevoid.com/posts/2019-01-27-getting-started-haskell-nix.html

{ nixpkgs ? import <nixpkgs> {} }:
let
  inherit (nixpkgs) pkgs;
  inherit (pkgs) haskellPackages;

  haskellDeps = ps: with ps; [
    base
    lens
    mtl
  ];

  ghc = haskellPackages.ghcWithPackages haskellDeps;

  nixPackages = [
    ghc
    pkgs.gdb
    haskellPackages.cabal-install
  ];
in
pkgs.stdenv.mkDerivation {
  name = "env";
  buildInputs = nixPackages;
}

Fabric Minecraft

with import <nixpkgs> {};
let
  nixPackages = [
    jdk
    xorg.libX11
    libGL
    libGLU
    libpulseaudio
    flite
  ];
  libpath = stdenv.lib.makeLibraryPath nixPackages;
in stdenv.mkDerivation {
  name = "minecraft-modding-env";
  buildInputs = nixPackages;
  LD_LIBRARY_PATH = "/run/opengl-driver/lib;${libpath}";
}

Last update: November 23, 2020