diff --git a/example/.gitignore b/example/.gitignore index 92b2793..a285cab 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1 +1,3 @@ .direnv +a.out +result diff --git a/example/flake.nix b/example/flake.nix index 2753fb0..6ada027 100644 --- a/example/flake.nix +++ b/example/flake.nix @@ -17,13 +17,12 @@ let pkgs = import nixpkgs { inherit system; - # overlays = [ overlay ]; config.allowUnfree = true; }; - dependencies = with pkgs; [ + # Here are all the packages we would like available + devDeps = with pkgs; [ clang - clang-tools cmake codespell conan @@ -32,7 +31,13 @@ gtest lcov vcpkg - vcpkg-tool + ]; + + # Additional packages for runtime use in the container + containerDeps = with pkgs; [ + bashInteractive + coreutils + findutils ]; hook = '' @@ -41,10 +46,53 @@ ''; in { + # Dev shell devShells.default = pkgs.mkShell { - buildInputs = dependencies; + buildInputs = devDeps; shellHook = hook; }; + + # Container image + packages.devContainer = pkgs.dockerTools.buildImage { + name = "cpp-dev"; + tag = "latest"; + + copyToRoot = pkgs.buildEnv { + name = "image-root"; + paths = devDeps ++ containerDeps; + }; + + extraCommands = '' + mkdir -p ./tmp + ''; + + config = { + Cmd = [ "bash" ]; + Env = [ + "PATH=${pkgs.lib.makeBinPath devDeps}:${pkgs.lib.makeBinPath containerDeps}:$PATH" + ]; + WorkingDir = "/workspace"; + }; + }; + + # Nix package build instructions + packages.default = pkgs.stdenv.mkDerivation { + pname = "Hello"; + version = "0.1"; + + src = ./.; + + nativeBuildInputs = [ pkgs.clang ]; + + buildPhase = '' + clang main.c + ''; + + installPhase = '' + mkdir -p $out/bin + cp a.out $out/bin/hello + ''; + }; } ); } diff --git a/example/main.c b/example/main.c index 577593c..d9e79d1 100644 --- a/example/main.c +++ b/example/main.c @@ -1,5 +1,5 @@ #include int main() { - printf("Hello World!"); + printf("Hello World!\n"); return 0; } diff --git a/presentation.md b/presentation.md index 9b30e5d..c324748 100644 --- a/presentation.md +++ b/presentation.md @@ -23,7 +23,17 @@ Mark Dickie * Gamer and private pilot also - +Overview +--- + +# Define Nix +# Show a small project +# Demonstrate a dev shell using a Nix flake +# Demonstrate a container image using Nix flakes +# Talk about build pipelines with Nix +# Demonstrate a Nix package +# Answer questions + Definition --- @@ -68,7 +78,7 @@ Dev Shell with Nix --- # Demo - +![](images/terminal.png) Dev Shell with Nix --- @@ -83,5 +93,57 @@ Dev Shell with Nix * Makes environments modular and re-usable - +Generate a container +--- + +# Demo +![](images/terminal.png) + +Generate a container +--- + +# Benefits + +* Can be used for development or build pipelines + +* In webapp and similar contexts this could also be used as a deployable production environment + +* Multiple container definitions could be contained in the flake with shared code + + +Build pipelines +--- + +# Multiple approaches + +* Build inside the generated container + +* Run the devShell from the flake to build + +* Use nix to build the package directly + +Build a Nix package +--- + +# Demo +![](images/terminal.png) + +Nix Details +--- + +# Nix Store + +# Binary Caching + +# Garbage Collection + +Questions? +--- + +Ask away! + +Links +--- + +Links will go here