From 814f89e0f8ae1ef528977b18c8db4cd5e371e5c6 Mon Sep 17 00:00:00 2001 From: Shine Date: Tue, 9 Jul 2024 20:55:42 +0200 Subject: [PATCH] feat: initial release --- .envrc | 1 + .gitignore | 5 + assets/pictures/flake_relations.svg | 4 + examples/basic_flake/.envrc | 1 + examples/basic_flake/flake.lock | 27 +++ examples/basic_flake/flake.nix | 11 ++ examples/flake_part/flake.lock | 58 +++++++ examples/flake_part/flake.nix | 34 ++++ examples/nci/.envrc | 1 + examples/nci/Cargo.lock | 7 + examples/nci/Cargo.toml | 4 + examples/nci/crates.nix | 12 ++ examples/nci/flake.lock | 252 ++++++++++++++++++++++++++++ examples/nci/flake.nix | 40 +++++ examples/nci/src/main.rs | 3 + flake.lock | 162 ++++++++++++++++++ flake.nix | 54 ++++++ marp.config.mjs | 13 ++ slides/slides.md | 208 +++++++++++++++++++++++ themes/theme.css | 10 ++ 20 files changed, 907 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 assets/pictures/flake_relations.svg create mode 100644 examples/basic_flake/.envrc create mode 100644 examples/basic_flake/flake.lock create mode 100644 examples/basic_flake/flake.nix create mode 100644 examples/flake_part/flake.lock create mode 100644 examples/flake_part/flake.nix create mode 100644 examples/nci/.envrc create mode 100644 examples/nci/Cargo.lock create mode 100644 examples/nci/Cargo.toml create mode 100644 examples/nci/crates.nix create mode 100644 examples/nci/flake.lock create mode 100644 examples/nci/flake.nix create mode 100644 examples/nci/src/main.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 marp.config.mjs create mode 100644 slides/slides.md create mode 100644 themes/theme.css diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a567660 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.direnv/ +.data/ +present/ +**/target/ +**/result \ No newline at end of file diff --git a/assets/pictures/flake_relations.svg b/assets/pictures/flake_relations.svg new file mode 100644 index 0000000..3468b1a --- /dev/null +++ b/assets/pictures/flake_relations.svg @@ -0,0 +1,4 @@ + + + +
flake1
inputs = {}
outputs = {}
flake12
inputs.flake1 = "";
inputs.flake2 = "";
outputs = {}
flake2
inputs = {}
outputs = {}
\ No newline at end of file diff --git a/examples/basic_flake/.envrc b/examples/basic_flake/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/examples/basic_flake/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/examples/basic_flake/flake.lock b/examples/basic_flake/flake.lock new file mode 100644 index 0000000..8bbf80d --- /dev/null +++ b/examples/basic_flake/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/basic_flake/flake.nix b/examples/basic_flake/flake.nix new file mode 100644 index 0000000..e54f283 --- /dev/null +++ b/examples/basic_flake/flake.nix @@ -0,0 +1,11 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + outputs = + { self, nixpkgs }: + { + packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.hello; + packages.x86_64-linux.foobar = nixpkgs.legacyPackages.x86_64-linux.fortune; + }; +} diff --git a/examples/flake_part/flake.lock b/examples/flake_part/flake.lock new file mode 100644 index 0000000..5001fbf --- /dev/null +++ b/examples/flake_part/flake.lock @@ -0,0 +1,58 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1719876945, + "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/flake_part/flake.nix b/examples/flake_part/flake.nix new file mode 100644 index 0000000..3740fd7 --- /dev/null +++ b/examples/flake_part/flake.nix @@ -0,0 +1,34 @@ +{ + description = "Description for the project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + # Modules go here + ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + packages.default = pkgs.hello; + }; + }; +} diff --git a/examples/nci/.envrc b/examples/nci/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/examples/nci/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/examples/nci/Cargo.lock b/examples/nci/Cargo.lock new file mode 100644 index 0000000..c47f456 --- /dev/null +++ b/examples/nci/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "my-crate" +version = "0.1.0" diff --git a/examples/nci/Cargo.toml b/examples/nci/Cargo.toml new file mode 100644 index 0000000..e8b1f15 --- /dev/null +++ b/examples/nci/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "my-crate" +version = "0.1.0" +edition = "2018" diff --git a/examples/nci/crates.nix b/examples/nci/crates.nix new file mode 100644 index 0000000..4385463 --- /dev/null +++ b/examples/nci/crates.nix @@ -0,0 +1,12 @@ +{ ... }: +{ + perSystem = + { pkgs, config, ... }: + let + crateName = "my-crate"; + in + { + nci.projects."simple".path = ./.; + nci.crates.${crateName} = { }; + }; +} diff --git a/examples/nci/flake.lock b/examples/nci/flake.lock new file mode 100644 index 0000000..764bc9b --- /dev/null +++ b/examples/nci/flake.lock @@ -0,0 +1,252 @@ +{ + "nodes": { + "crane": { + "flake": false, + "locked": { + "lastModified": 1699217310, + "narHash": "sha256-xpW3VFUG7yE6UE6Wl0dhqencuENSkV7qpnpe9I8VbPw=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d535642bbe6f377077f7c23f0febb78b1463f449", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "ref": "v0.15.0", + "repo": "crane", + "type": "github" + } + }, + "dream2nix": { + "inputs": { + "nixpkgs": [ + "nci", + "nixpkgs" + ], + "purescript-overlay": "purescript-overlay", + "pyproject-nix": "pyproject-nix" + }, + "locked": { + "lastModified": 1720086039, + "narHash": "sha256-pbeH3DczCcKteOC/CbRnP8pf/njlcrVQ//e1agF+WpY=", + "owner": "nix-community", + "repo": "dream2nix", + "rev": "46b6ee6b0bf6e601a0765bffbbd5af9006caa2dc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "dream2nix", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "mk-naked-shell": { + "flake": false, + "locked": { + "lastModified": 1681286841, + "narHash": "sha256-3XlJrwlR0nBiREnuogoa5i1b4+w/XPe0z8bbrJASw0g=", + "owner": "yusdacra", + "repo": "mk-naked-shell", + "rev": "7612f828dd6f22b7fb332cc69440e839d7ffe6bd", + "type": "github" + }, + "original": { + "owner": "yusdacra", + "repo": "mk-naked-shell", + "type": "github" + } + }, + "nci": { + "inputs": { + "crane": "crane", + "dream2nix": "dream2nix", + "mk-naked-shell": "mk-naked-shell", + "nixpkgs": [ + "nixpkgs" + ], + "parts": "parts", + "rust-overlay": "rust-overlay", + "treefmt": "treefmt" + }, + "locked": { + "lastModified": 1720332791, + "narHash": "sha256-t26NnN/9hFNHHYzbTSiTZmDpw9XMa9zU3nyeu7k/RBI=", + "owner": "yusdacra", + "repo": "nix-cargo-integration", + "rev": "6d375fd9ed1f829381a6974d2dd4a32985bb21b0", + "type": "github" + }, + "original": { + "owner": "yusdacra", + "repo": "nix-cargo-integration", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": [ + "nci", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "purescript-overlay": { + "inputs": { + "nixpkgs": [ + "nci", + "dream2nix", + "nixpkgs" + ], + "slimlock": "slimlock" + }, + "locked": { + "lastModified": 1696022621, + "narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=", + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "rev": "047c7933abd6da8aa239904422e22d190ce55ead", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "type": "github" + } + }, + "pyproject-nix": { + "flake": false, + "locked": { + "lastModified": 1702448246, + "narHash": "sha256-hFg5s/hoJFv7tDpiGvEvXP0UfFvFEDgTdyHIjDVHu1I=", + "owner": "davhau", + "repo": "pyproject.nix", + "rev": "5a06a2697b228c04dd2f35659b4b659ca74f7aeb", + "type": "github" + }, + "original": { + "owner": "davhau", + "ref": "dream2nix", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nci": "nci", + "nixpkgs": "nixpkgs" + } + }, + "rust-overlay": { + "flake": false, + "locked": { + "lastModified": 1720318855, + "narHash": "sha256-w3CCVK9LJ5aznXGkO1IyAlbvMNJfyA+dBF7Z1Zwx1LA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "3eed08a074cd2000884a69d448d70da2843f7103", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "slimlock": { + "inputs": { + "nixpkgs": [ + "nci", + "dream2nix", + "purescript-overlay", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688610262, + "narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=", + "owner": "thomashoneyman", + "repo": "slimlock", + "rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "slimlock", + "type": "github" + } + }, + "treefmt": { + "inputs": { + "nixpkgs": [ + "nci", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719887753, + "narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/nci/flake.nix b/examples/nci/flake.nix new file mode 100644 index 0000000..590aace --- /dev/null +++ b/examples/nci/flake.nix @@ -0,0 +1,40 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nci = { + url = "github:yusdacra/nix-cargo-integration"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + }; + outputs = + inputs@{ flake-parts, nci, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" ]; + imports = [ + nci.flakeModule + ./crates.nix + ]; + perSystem = + { pkgs, config, ... }: + let + crateName = "my-crate"; + crateOutputs = config.nci.outputs.${crateName}; + in + { + devShells.default = crateOutputs.devShell; + packages.default = crateOutputs.packages.release; + packages.container = pkgs.dockerTools.streamLayeredImage { + name = crateName; + tag = "latest"; + contents = [ ]; + config = { + Cmd = [ "${crateOutputs.packages.release}/bin/my-crate" ]; + }; + }; + }; + }; +} diff --git a/examples/nci/src/main.rs b/examples/nci/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/examples/nci/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4e1bd71 --- /dev/null +++ b/flake.lock @@ -0,0 +1,162 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1717408969, + "narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=", + "owner": "numtide", + "repo": "devshell", + "rev": "1ebbe68d57457c8cae98145410b164b5477761f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1704161960, + "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63143ac2c9186be6d9da6035fa22620018c85932", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1719876945, + "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1719690277, + "narHash": "sha256-0xSej1g7eP2kaUF+JQp8jdyNmpmCJKRpO12mKl/36Kc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2741b4b489b55df32afac57bc4bfd220e8bf617e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs_2", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1719887753, + "narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3946c47 --- /dev/null +++ b/flake.nix @@ -0,0 +1,54 @@ +{ + description = "Description for the project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + devshell.url = "github:numtide/devshell"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.devshell.flakeModule + inputs.treefmt-nix.flakeModule + ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + treefmt = { + programs.nixfmt.enable = true; + projectRootFile = "flake.nix"; + }; + devshells.default = { + serviceGroups.marp.services.marp.command = "marp --watch"; + commands = [ + { + help = "Build presentation and present"; + name = "present"; + command = "marp && xdg-open ./present/slides.html"; + } + ]; + packages = [ + pkgs.marp-cli + config.treefmt.build.wrapper + ]; + }; + }; + }; +} diff --git a/marp.config.mjs b/marp.config.mjs new file mode 100644 index 0000000..1aeb5ee --- /dev/null +++ b/marp.config.mjs @@ -0,0 +1,13 @@ +const canonicalUrl = process.env.URL || undefined + +/** @type {import('@marp-team/marp-cli').Config} */ +const config = { + allowLocalFiles: true, + themeSet: 'themes', + url: canonicalUrl, + inputDir: "./slides", + output: "./present" + +} + +export default config \ No newline at end of file diff --git a/slides/slides.md b/slides/slides.md new file mode 100644 index 0000000..e976f27 --- /dev/null +++ b/slides/slides.md @@ -0,0 +1,208 @@ +--- +marp: true +lang: en-US +title: Marp CLI example +description: Hosting Marp slide deck on the web +theme: nix_talk +transition: fade +paginate: true +_paginate: false +--- + +# Nix for Rustaceans +#### Kateřina "Kate" Churanová + +--- + +# What is Nix + +- Purely functional programming language +- Package manager +- Linux distribution (NixOS) +- multiplatform (Linux, Mac OS, BSD-ish) + +--- + +# What is Nix NOT + +- Easy to learn +- Well documented +- Opinionated + +--- + +# Nix derivation + +- "Package" +- evaluates to store derivation in `/nix/store/` +- `2n45ikclc8d5fhzkvg1197qlc2zk3s64-rustc-1.77.2.drv` + + +--- + +# Nix flake + +- Unstable, but widely used +- New way of creating nix derivations +- Lock file version pinning +- Allows reproducibility + +--- + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + outputs = + { self, nixpkgs }: + { + packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.hello; + packages.x86_64-linux.foobar = nixpkgs.legacyPackages.x86_64-linux.fortune; + }; +} +``` + +--- + +![bg width:80%](../assets/pictures/flake_relations.svg) + +--- + +# Nix developer shell + +- `nix develop` +- builds all flake dependencies, but not the flake itself +- sets up the development environment + +--- + +# Nix direnv + +- https://github.com/nix-community/nix-direnv +- Activates developer shell automatically + +--- + +# Frameworks + +- Pure nix solution is usable, but tedious with ugly boilerplate +- [Numtide: flake-utils](https://github.com/ursi/numtide-flake-utils) +- [Hercules CI: Flake Parts](https://flake.parts/) + + + +--- + +# Flake parts - Minimal modular framework +## Dev environment management +- Devshell +- Devenv +## Rust project building +- NCI (Nix cargo integration) + +--- +# Basic flake parts project +```nix +{ + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + # Modules go here + ]; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, ... }: { + packages.default = pkgs.hello; + }; + }; +} +``` + +--- + +# Fun begins with Rust +### flake.nix +```nix + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nci = { + url = "github:yusdacra/nix-cargo-integration"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + }; +``` + +--- + +```nix +outputs = inputs @ { + flake-parts, + nci, + ... + }: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux"]; + imports = [ + nci.flakeModule + ./crates.nix + ]; + perSystem = { + pkgs, + config, + ... + }: let + crateName = "my-crate" + crateOutputs = config.nci.outputs.${crateName}; + in { + devShells.default = crateOutputs.devShell; + packages.default = crateOutputs.packages.release; + }; + }; +``` + +--- +### crates.nix +```nix +{...}: { + perSystem = { + pkgs, + config, + ... + }: let + crateName = "my-crate"; + in { + nci.projects."simple".path = ./.; + nci.crates.${crateName} = {}; + }; +} +``` + +--- + +# Why all of this though? + +- Reproducible environment with pinned Rust version +- Predictable dependencies +- Plenty of other tools for your disposal +- Extremely simple generation of lightweight OCI containers + +--- +```nix + packages.container = pkgs.dockerTools.streamLayeredImage { + name = crateName; + tag = "latest"; + contents = [ ]; + config = { + Cmd = [ "${crateOutputs.packages.release}/bin/my-crate" ]; + }; + }; +``` \ No newline at end of file diff --git a/themes/theme.css b/themes/theme.css new file mode 100644 index 0000000..7173b28 --- /dev/null +++ b/themes/theme.css @@ -0,0 +1,10 @@ +/* + *@theme nix_talk + */ + +@import 'default'; + +section { + background: #cef; + color: #135; +} \ No newline at end of file