diff options
| author | Fuwn <[email protected]> | 2024-10-15 17:20:21 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-15 17:20:24 -0700 |
| commit | cb55fdc17bab297a16cf47acc850dce58e8ced87 (patch) | |
| tree | 291c616a33f14c5da4168c423d424271a3ed48fc | |
| parent | 27eefbc75f85d44bdf70addfef67319d840141eb (diff) | |
| download | yae-cb55fdc17bab297a16cf47acc850dce58e8ced87.tar.xz yae-cb55fdc17bab297a16cf47acc850dce58e8ced87.zip | |
docs: add nixpkgs examples
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | README.md | 19 | ||||
| -rw-r--r-- | examples/nixpkgs-simple/flake.nix | 18 | ||||
| -rw-r--r-- | examples/nixpkgs-simple/yae.json | 10 | ||||
| -rw-r--r-- | examples/nixpkgs/flake.nix | 47 | ||||
| -rw-r--r-- | examples/nixpkgs/yae.json | 10 |
6 files changed, 104 insertions, 2 deletions
@@ -1,4 +1,4 @@ /yae .pre-commit-config.yaml result -yae.json +/yae.json @@ -109,12 +109,28 @@ exported `inputs.yae.packages.${pkgs.system}.yae` package. To add Yae support to your Nix expression after running `yae init`, just read from the Yae environment file. See the example below for more details. -### Nix Example +### Examples + +Check out [`examples/nixpkgs`](./examples/nixpkgs) for a pure Nix example of Yae +in action. This example is a little large since it constrains itself to **zero** +inputs and manually constructs multi-system support. In a real-world scenario, +you'd actually use something like [flake-utils](https://github.com/numtide/flake-utils) +to replace all of the boilerplate. For this reason, [`examples/nixpkgs-simple`](./examples/nixpkgs-simple) +exists, which functions identically, but uses `builtins.currentSystem` to +populate the `nixpkgs.system` attribute. (requires `--impure`) + +If Nixpkgs ever goes out of date in these theorectical examples, just run +`yae update`! + +#### Real-world Example Here's an example snippet taken from Tsutsumi's [`zen-browser-bin` package](https://github.com/Fuwn/tsutsumi/blob/main/pkgs/zen-browser-bin.nix) and [`yae.json`](https://github.com/Fuwn/tsutsumi/blob/main/yae.json#L59-L67) showcasing Yae in action. +<details closed> + <summary>Expand this!</summary> + ```nix # pkgs/zen-browser-bin.nix @@ -146,6 +162,7 @@ import "${self}/lib/zen-browser-bin.nix" { # inherit (yae.zen-browser-twilight-bin) sha256 version; } { inherit pkgs; } ``` +</details> ## `--help` diff --git a/examples/nixpkgs-simple/flake.nix b/examples/nixpkgs-simple/flake.nix new file mode 100644 index 0000000..2903230 --- /dev/null +++ b/examples/nixpkgs-simple/flake.nix @@ -0,0 +1,18 @@ +{ + outputs = + { self }: + let + nixpkgs = (builtins.fromJSON (builtins.readFile "${self}/yae.json")).nixpkgs; + + pkgs = + import + (builtins.fetchTarball { + inherit (nixpkgs) url sha256; + }) + { + }; + in + { + packages.${pkgs.system}.hello = pkgs.hello; + }; +} diff --git a/examples/nixpkgs-simple/yae.json b/examples/nixpkgs-simple/yae.json new file mode 100644 index 0000000..54b371c --- /dev/null +++ b/examples/nixpkgs-simple/yae.json @@ -0,0 +1,10 @@ +{ + "nixpkgs": { + "url": "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz", + "sha256": "1wn29537l343lb0id0byk0699fj0k07m1n2d7jx2n0ssax55vhwy", + "unpack": true, + "type": "git", + "version": "nixos-unstable", + "url_template": "https://github.com/NixOS/nixpkgs/archive/{version}.tar.gz" + } +} diff --git a/examples/nixpkgs/flake.nix b/examples/nixpkgs/flake.nix new file mode 100644 index 0000000..7dd28a4 --- /dev/null +++ b/examples/nixpkgs/flake.nix @@ -0,0 +1,47 @@ +{ + outputs = + { self }: + let + nixpkgs = (builtins.fromJSON (builtins.readFile "${self}/yae.json")).nixpkgs; + + systemsFlakeExposed = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "armv6l-linux" + "armv7l-linux" + "i686-linux" + "aarch64-darwin" + "powerpc64le-linux" + "riscv64-linux" + "x86_64-freebsd" + ]; + + forEachSystem = + systems: action: + builtins.listToAttrs ( + map (system: { + name = system; + value = action system; + }) systems + ); + in + { + packages = (forEachSystem systemsFlakeExposed) ( + system: + let + pkgs = + import + (builtins.fetchTarball { + inherit (nixpkgs) url sha256; + }) + { + inherit system; + }; + in + { + hello = pkgs.hello; + } + ); + }; +} diff --git a/examples/nixpkgs/yae.json b/examples/nixpkgs/yae.json new file mode 100644 index 0000000..54b371c --- /dev/null +++ b/examples/nixpkgs/yae.json @@ -0,0 +1,10 @@ +{ + "nixpkgs": { + "url": "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz", + "sha256": "1wn29537l343lb0id0byk0699fj0k07m1n2d7jx2n0ssax55vhwy", + "unpack": true, + "type": "git", + "version": "nixos-unstable", + "url_template": "https://github.com/NixOS/nixpkgs/archive/{version}.tar.gz" + } +} |