Skip to content

Latest commit

 

History

History
146 lines (105 loc) · 4.13 KB

README.md

File metadata and controls

146 lines (105 loc) · 4.13 KB

FLAKES

Demonstrate how to use nix flakes.

TODO:

  • What is nix bundle?
  • How do I just build flake without entering it? Or if I enter it how do I then run all the tools I need? nix run error: flake 'path:/work/jq' does not provide attribute 'apps.x86_64-linux.default', 'defaultApp.x86_64-linux', 'packages.x86_64-linux.default' or 'defaultPackage.x86_64-linux'

NOTES:

  • The flake.lock file lock to a specific revision of the nix pkg.
  • commits in nixpkgs here
  • To lock to a retrospective version you can copy the commitid into the lock. If you run nix flake check --impure you can copy the NAR hash to match.

🏠 Build and Run

# build nix
docker build -f Dockerfile -t nix-flakes .

# debugging and host repo in build folder
docker run -v "$(pwd):/work" --rm -it --entrypoint /root/.nix-profile/bin/bash nix-flakes 

# inside container
nix --help

nix flake --help

# there are a set of templates that can be used. 
nix flake show templates

# get version
nix-env --version

Enabling flakes

NOTE: This is not required for the Dockerfile as it is done on docker build

find / -iname "nix.conf"

nix-shell -p nano

cat /etc/nix/nix.conf
nano /etc/nix/nix.conf
# add the following line
experimental-features = nix-command flakes

# or each command can use the overrides
nix flake new hello --extra-experimental-features nix-command --extra-experimental-features flakes

Creating Flakes

# 
cd ./hello-world

nix flake new hello-world

# check the validity of the flake
# NOTE: forgot exactly what imupure does (volatile output)
nix flake check
nix flake check --impure


nix build --impure

Entering Flakes

cd ./ffmpeg5

# nix read evaluate print loop
nix repl

nix flake update

# enter flake
echo $SHLVL  
echo $PATH
nix develop --impure
echo $SHLVL  
echo $PATH

# show environments
nix flake show --impure

ffmpeg

Installing specific versions of ffmpeg.

# inside the container
cd ./ffmpeg5.1.2
# enter (this will install)
nix develop --impure --command bash -c 'ffmpeg -version'
# ffmpeg version 5.1.2
cd ./ffmpeg4
# enter (this will install)
nix develop --impure --command bash -c 'ffmpeg -version'
# ffmpeg version 4.4.3

To a specific commit. To lock to a retrospective version you can copy the commitid from (nixos/nixpkgs) into the lock. You can then run nix flake check --impure and copy the output conflicting NAR hash to match. I also had to remove the "lastModified": 1677074004, property.

# inside the container
cd ./ffmpeg5.1.1
# enter (this will install)
nix develop --impure --command bash -c 'ffmpeg -version'
# ffmpeg version 5.1.1

jq

cd ./jq
nix develop --impure --command bash -c 'echo $SHLVL && echo $PATH && jq --version'
echo $SHLVL  
echo $PATH

Resources

  • the-nix-way/dev-templates here

  • Error: experimental Nix feature ‘nix-command’ is disabled here

  • the-nix-way/nix-flake-dev-environments here

  • Nix Flakes: an Introduction here

  • Nix from First Principles: Flake Edition here

  • Nix Flakes: first steps here

  • Nix Language here

  • Nix Pills here

  • How to Learn Nix, Part 43: My first brush with flakes here

  • the-nix-way/nix-flake-dev-environments here

  • attribute self.lastModifiedDate missing #13 here

  • NIX FLAKES, PART 1: AN INTRODUCTION AND TUTORIAL here

  • Flakes templates github.com/NixOS/templates