Skip to content

Instantly share code, notes, and snippets.

@kuuote
Created February 15, 2025 17:40
Show Gist options
  • Save kuuote/377d939bf6966e32e8bbc041db345662 to your computer and use it in GitHub Desktop.
Save kuuote/377d939bf6966e32e8bbc041db345662 to your computer and use it in GitHub Desktop.
{
description = "latte PoC";
outputs =
{
nixpkgs,
...
}:
let
inherit (nixpkgs) lib;
eachSystem =
fn: lib.genAttrs lib.systems.flakeExposed (system: fn nixpkgs.legacyPackages.${system});
in
{
latte = eachSystem (pkgs: {
default = {
gen =
args:
pkgs.linkFarm "template" {
"flake.nix" = ./flake.nix;
"flake.lock" = ./flake.lock;
text = pkgs.writeText "text" args.text or "no text";
};
};
});
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
}
#!/usr/bin/env bash
set -eu
flake=${1:-.}
if [[ ! $flake =~ ":" ]]; then
flake=$(realpath $flake)
fi
system=$(nix eval --impure --raw --expr builtins.currentSystem)
cat > /tmp/latte.nix << EOS
let
flake = builtins.getFlake "${flake}";
in
(flake.latte.${system}.default.gen { text = "hoge"; })
EOS
outPath=$(nix build --no-link --print-out-paths --file /tmp/latte.nix)
cd $outPath
rm -rf /tmp/latte
mkdir -p /tmp/latte
find -L . -type f | sort | while read path; do
mkdir -p $(dirname /tmp/latte/$path)
cat $path > /tmp/latte/$path
echo Wrote $path
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment