Commit 5c975b81 authored by Katharina Fey's avatar Katharina Fey 🏴
Browse files

Update course day 2 and (a bit) 3

parent d59536b3
......@@ -16,7 +16,7 @@
\\
+ Setup a build environment?
+ Install depnedencies?
+ Install dependencies?
+ Find and link against the _right_ version of a library
**
......
......@@ -276,7 +276,7 @@
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "my-packge";
src = ./.;
dontUnpack = true;
installPhase = ''
mkdir $out
echo "Hello :)" >> $out/message.txt
......@@ -315,15 +315,19 @@
Hello :)
#+END_SRC
** Some less common configuration
** Environment variables
\\
Not all parts of derivation building are configured via Nix! Some
are handled by the derivation builder (written in bash).
~dontUnpack~ is one of these.
Any _additional key_ passed to ~mkDerivation~ is set as an
environment variable in the build environment
Some of these variables are used by Nix builds internally (for
example ~dontUnpack~). Everything else is up to you.
** Some less common configuration
How to find them?
\\
1. Find ~nixpkgs~ on your system (e.g. via ~$NIX_PATH~)
2. ~nixpkgs/pkgs/stdenv/generic/setup.sh~
......@@ -345,7 +349,6 @@
Importantly: some of these defaults are _different_ based on what
builder is invoking them (more on that later)
**
Some more useful things: https://nixos.org/manual/nix/stable/language/advanced-attributes.html
......
......@@ -64,7 +64,7 @@
}
#+END_SRC
What happens if `latest.tar.gz` changes?
What happens if ~latest.tar.gz~ changes?
** Caching 🔥
......
#+Title: Special builders
#+SETUPFILE: ../../reveal.setup
** Do I really have to build my ~$LANG~ application by hand?
** No
** Remember ~build-support~ ?
\\
+ Commonly used languages have specific build support in nixpkgs
+ Pros: each builder can handle special cases
+ Cons: each builder handles special cases
** Rust builder
\\
#+BEGIN_SRC nix
rustPlatform.buildRustPackage rec {
pname = "bat";
version = "0.22.1";
src = fetchFromGitHub {
owner = "sharkdp";
repo = pname;
rev = "v${version}";
sha256 = "sha256-ye6GH4pcI9h1CNpobUzfJ+2WlqJ98saCdD77AtSGafg=";
};
cargoSha256 = "sha256-ye6GH4pcI9h1CNpobUzfJ+2WlqJ98saCdD77AtSGafg=";
...
}
#+END_SRC
** Go builder
\\
#+BEGIN_SRC nix
buildGoModule rec {
pname = "dive";
version = "0.10.0";
src = fetchFromGitHub {
owner = "wagoodman";
repo = pname;
rev = "v${version}";
sha256 = "sha256-1pmw8pUlek5FlI1oAuvLSqDow7hw5rw86DRDZ7pFAmA=";
};
vendorSha256 = "sha256-YPkEei7d7mXP+5FhooNoMDARQLosH2fdSaLXGZ5C27o=";
}
#+END_SRC
** Python builder
\\
#+BEGIN_SRC nix
buildPythonPackage rec {
version = "0.7.5";
pname = "pickleshare";
src = fetchPypi {
inherit pname version;
sha256 = "87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca";
};
}
#+END_SRC
**
Not all specific builders are defined in ~build-support~ (that would be too boring).
But a lot of them are.
** [[file:README.org][Back to index]]
#+Title: Override & OverrideAttr
#+SETUPFILE: ../../reveal.setup
** Problem
\\
How to change a package without having to re-write it yourself?
** Solution
\\
Overrides!
** Basic idea
\\
+ ~override~ and ~overrideAttr~ are special functions implemented
around derivations
+ An example from day 1: ~pkgs.wine.override { ... }~
+ What's their difference?
** Override
\\
+ Specific to each package
+ Acts on the derivation _output_
#+BEGIN_SRC nix
with import <nixpkgs> {};
{
my-git = pkgs.git.override {
svnSupport = true;
sendEmailSupport = true;
};
}
#+END_SRC
**
#+BEGIN_SRC shell
❤ (theia) ~> nix-build ./override.nix
this derivation will be built:
/nix/store/rn2qbgzkc4b8h7zsflhdyn9rhsjy0mp1-git-with-svn-2.38.1.drv
building '/nix/store/rn2qbgzkc4b8h7zsflhdyn9rhsjy0mp1-git-with-svn-2.38.1.drv'...
...
#+END_SRC
** ~overrideAttrs~
\\
+ Generic for /all*/ derivations
+ Acts on the _inputs_ to ~mkDerivation~
+ It therefore allows much more generic overrides
/*any derivation which is wrapped in 'makeOverridable'/
**
~overrideAttrs~ takes a function which takes an attribute set and
returns an attribute set. Only changed keys should be returned.
\\
#+BEGIN_SRC nix
some-package.overrideAttrs { ... }: { /* ... */ }
#+END_SRC
**
#+BEGIN_SRC nix
htop.overrideAttrs ({ patches ? [], nativeBuildInputs ? [], postConfigure ? "", ... }: {
patches = patches ++ [ ./0001-htop-untruncated-username.patch ];
})
#+END_SRC
** ~overrideDerivation~
\\
+ _Extremely_ special function which is very rarely useful
+ Override attributes that ~mkDerivation~ passes to ~derivation~
+ You might see this in some places but you probably don't need/
want to use it!
** [[file:README.org][Back to index]]
......@@ -11,9 +11,9 @@
...
#+END_SRC
+ https://github.com/thiderman/doge
+ https://github.com/XAMPPRocky/tokei
+ https://dev.yorhel.nl/ncdu
1. https://github.com/XAMPPRocky/tokei (Rust)
2. https://github.com/thiderman/doge (Python)
3. https://dev.yorhel.nl/ncdu (Zig)
** Some pointers
......@@ -23,7 +23,7 @@
~pythonPackages.buildPythonPackage~,
~rustPlatform.buildRustPackage~, ...
+ Use TOFU when fetching the source, set the hash and re-run
+ You can define _environment variables_ in the derivation _(hint hint lol)
+ You can define _environment variables_ in the derivation
+ Flail around with your arms until I come help you
** [[file:README.org][Back to index]]
#+Title: Overriding package sources
#+SETUPFILE: ../../reveal.setup
**
\\
Take a package from ~nixpkgs~ and roll it back to a previous
version.
1. Change the source
2. Figure out the build hash
3. Fix compilation problems that come up (if any)
......@@ -15,8 +15,11 @@ Today we will cover the following subjects:
1. [[./50-derivations.org][Derivations]]
2. [[./51-fixed-output.org][Fixed output Derivations]]
3.
3. [[file:52-special-builders.org][Special builders]]
4. [[file:53-overrides.org][Overrides]]
** Homework
3. [[./60-exercise-packaging.org][(Exercise) Building your first packages]]
5. [[./60-exercise-packaging.org][Building some packages]]
6. [[file:61-overrides.org][Override sources]]
......@@ -79,50 +79,6 @@
'';
}
#+END_SRC
** Overrides
\\
You _can_ override packages without an overlay, for example in-line
to your configuration!
#+BEGIN_SRC nix
{ pkgs, ... }:
{
environment.systemPackages = [
(pkgs.git.override {
svnSupport = true;
sendEmailSupport = true;
})
];
}
#+END_SRC
** ~override~ vs ~overrideAttrs~
\\
+ ~override~ overrides attributes in a _derivation_
+ ~overrideAttrs~ overrides attributes passed _to ~mkDerivation~_
**
Let's put it all together and override actually htop!
#+BEGIN_SRC nix
import <nixpkgs> {
overlays = [
(import overlays/patches);
# ...
];
}
#+END_SRC
#+BEGIN_SRC console
❤ (theia) ~/sys> ls overlays
kookie/ patches/ rust/ staging/
#+END_SRC
**
......
with import <nixpkgs> {};
self: super: {
htop = self.callPackage ./htop { htop = super.htop; }
}
with import <nixpkgs> {};
self: super: {
htop = self.callPackage ./htop { htop = super.htop; }
{
my-git = pkgs.git.override {
svnSupport = true;
sendEmailSupport = true;
};
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment