Skip to content

Instantly share code, notes, and snippets.

@diegosouza
Last active April 14, 2021 20:15
Show Gist options
  • Save diegosouza/b69e17e4d87fe5b83ec36bfd9a57890d to your computer and use it in GitHub Desktop.
Save diegosouza/b69e17e4d87fe5b83ec36bfd9a57890d to your computer and use it in GitHub Desktop.
exemplos simples e práticos com nix

nix-env (packages available to the user):

# search (query for --installed or --available)
nix-env -q --installed vim
nix-env -q --available 'emacs.*'

# install
nix-env -i htop

# remove
nix-env --uninstall htop

nix-shell:

nix-shell -p nodejs python3

shell.nix:

{ pkgs ? import <nixpkgs> {}
}:
pkgs.mkShell {
  name="dev-environment";
  buildInputs = [ pkgs.nodejs ];
  shellHook = ''
    echo "Start developing..."
  '';
}

nix-shell as interpreter (Python):

#! /usr/bin/env nix-shell
#! nix-shell -i python -p python pythonPackages.prettytable

import prettytable

# Print a simple table.
t = prettytable.PrettyTable(["N", "N^2"])
for n in range(1, 10): t.add_row([n, n * n])
print t

nix-shell as bash interpreter + PHP:

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p "(php.withExtensions ({ all, enabled }: enabled ++ (with all; [ imagick redis ]))).packages.composer1"

composer --version

docker:

{ pkgs ? import <nixpkgs> { system = "x86_64-linux"; }
}:
pkgs.dockerTools.buildLayeredImage {
  name = "nix-redis";
  tag = "latest";
  contents = [ pkgs.redis ];
}

It also requires:

nix-build docker-redis.nix -o ./result
docker load -i ./result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment