this repo has no description usp.wiro.world
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: restructure examples

authored by

Milo Moisson and committed by
Milo Moisson
0d0d7293 8d209382

+226 -118
+17 -1
README.md
··· 1 1 # Unsurprising 2 2 3 + As of today, this repository is exclusively to play around and think about a toy language with a goal close to Nix. 4 + 5 + # Parts 6 + 7 + ## Examples 8 + 9 + Examples are split into different use-cases. You can check the files in `examples`. 10 + 11 + - `core`: contains definitions of builtins 12 + 13 + - `cur`: cristal user repository 14 + 15 + - `machine`: contains a crystal (flake) definition for a machine definition 16 + 17 + - `project`: contains a crystal (flake) definition for a project 18 + 3 19 # Lecture 4 20 5 - - The Purely Functional Software Deployment Model 21 + - The Purely Functional Software Deployment Model — Eelco Dolstra 6 22 - https://jonathanlorimer.dev/posts/nix-thesis.html
+104
examples/core/lib.rs
··· 1 + // # Ressources 2 + // https://github.com/NixOS/nixpkgs/blob/master/doc/stdenv/stdenv.chapter.md 3 + // --- 4 + 5 + //! In separate crates/projects 6 + 7 + /// tools for transforming data, building derivations 8 + mod core { 9 + // lib, build, install, etc. 10 + 11 + // equivalent for flake 12 + mod cristal { 13 + 14 + } 15 + 16 + mod derivation { 17 + struct Drv<I, O> { 18 + pub meta: DrvMeta, 19 + pub source: Source, 20 + pub plan: BuildPlan, 21 + 22 + // this can be overridden when building 23 + inputs: I, 24 + 25 + // this can be accessed after building 26 + outputs: O, 27 + } 28 + 29 + impl Drv<I, O> { 30 + fn build(self, patch_inputs: Partial<I>) -> Result<O> { 31 + // path the default inputs with custom ones 32 + let current_inputs = self.inputs.override(patch_inputs); 33 + 34 + // <large snip> 35 + // execute build plan with 36 + } 37 + } 38 + 39 + let _ = || { 40 + let whatever_drv: Drv<I, O> = Drv::new /* ... */; 41 + let whatever: O = pkgs::whatever_drv.build {}; 42 + 43 + // whatever is 44 + { 45 + bin: { 46 + path: "store:<hash>-whatever-0.0.0-bin", 47 + // join pathes 48 + whatever: "store:<hash>-whatever-0.0.0-bin" + "whatever", 49 + }, 50 + man: { 51 + path: "store:<hash>-whatever-0.0.0-man", 52 + }, 53 + } 54 + 55 + let my_bin = make_new_script { 56 + name: "hello", 57 + script: || { 58 + let res = Command::new(whatever.bin.whatever).exec(); 59 + 60 + println(res); 61 + }, 62 + }; 63 + 64 + let screenshot_bin = std::make_script("lock-screenshot.sh", || { 65 + let tmp_img = Cmd::new(coreutils.bin.mktemp).arg("/tmp/lock-bg.XXX").exec()?; 66 + 67 + // Give some time to hide the bar 68 + std::sleep_milis(1); 69 + 70 + Cmd::new(grim.bin.grim).arg(tmp_img).exec()?; 71 + Cmd::new(swaylock.bin.swaylock).args(&["--image", tmp_img]).exec()?; 72 + 73 + std::remove(tmp_img)?; 74 + }); 75 + }; 76 + 77 + struct DrvMeta { 78 + name: String, 79 + version: String, 80 + description: String, 81 + 82 + platforms: Platforms, 83 + 84 + license: License, 85 + homepage: Uri, 86 + 87 + maintainers: List<Maintainers>, 88 + } 89 + } 90 + 91 + mod build { 92 + let unpack = BuildStep(|| { 93 + let src: PathBuf = std::build::source(); 94 + 95 + // unpack in cwd 96 + match src.ext() { 97 + ".tar.gz" | ".tgz" | ".tar.Z" => gzip(src), 98 + ".tar.bz2" | ".tbz2" | ".tbz" => bzip2(src), 99 + ".tar.xz" | ".tar.lzma" | ".txz" => xz(src), 100 + _ => panic!("could not unpack") 101 + } 102 + }); 103 + } 104 + }
+6
examples/cur/crystal.rs
··· 1 + /// all package derivations 2 + mod pkgs { 3 + mod hello; 4 + mod libxkbcommon; 5 + mod sway; 6 + }
+68
examples/cur/pkgs/hello.rs
··· 1 + use std::derivation::{Derivation, DerivationMeta, BuildStep, Source}; 2 + 3 + // none 4 + let build_step = BuildStep::new || { 5 + // call `./configure` 6 + std::build::???::configure(); 7 + // call `make` 8 + std::build::make::???(); 9 + }; 10 + 11 + // special imperative block to act 12 + let install_step = BuildStep::new || { 13 + let out: PathBuf = std::build::request_output_dir(); 14 + 15 + std::install::make::install(); 16 + }; 17 + 18 + let out = derivation.out(); 19 + 20 + pub let bin = out.join() 21 + 22 + // special imperative block to act 23 + let install_check = BuildStep::new || { 24 + let out: PathBuf = std::build::request_output_dir(); 25 + let hello_bin = out.join("bin/hello"); 26 + 27 + std::check::is_present(hello_bin)?; 28 + 29 + std::check::exec(hello_bin, []); 30 + }; 31 + 32 + // ability to document derivations 33 + pub let hello = Derivation::new { 34 + meta: DrvMeta::new { 35 + name: "hello", 36 + version: "2.12.1", 37 + description: "Program that produces a familiar, friendly greeting", 38 + 39 + license: License::Gpl3Plus | License::Apache, 40 + 41 + // changelog, maintainers, platforms, etc. 42 + // `mainProgram` makes no sense 43 + }, 44 + 45 + source: Source::fetch_url { 46 + // interpolation vvvvvvvvvvvv 47 + url: "mirror://gnu/hello/hello-{meta.version}.tar.gz", 48 + // keep hash in source? 49 + hash: "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA=", 50 + }, 51 + 52 + // no hash in source 53 + source: Source::fetch_url("mirror://gnu/hello/hello-{meta.version}.tar.gz"), 54 + 55 + // new starts from empty plan, could have `unpack` with first being unpack phase, `stdenv` for configure make make install workflows 56 + steps: BuildPlan::new([ 57 + // see example down below 58 + std::build::unpack(), 59 + // patch step 60 + // configure step 61 + build_step, 62 + // build check step 63 + install_step, 64 + // fixup step, patches files to work in nix??? envs 65 + install_check, // could do some `bin/<name> -v` to ensure that linking worked fine 66 + // distribution step 67 + ]), 68 + };
+1
examples/cur/pkgs/module.rs
··· 1 +
examples/flake.rs examples/project/cristal.rs
-48
examples/lib.rs
··· 1 - // # Ressources 2 - // https://github.com/NixOS/nixpkgs/blob/master/doc/stdenv/stdenv.chapter.md 3 - // --- 4 - 5 - //! In separate crates/projects 6 - 7 - /// tools for transforming data, building derivations 8 - mod std/core { 9 - // lib, build, install, etc. 10 - 11 - mod derivation { 12 - // e.g. X is lspelling 13 - struct Drv<X> { 14 - meta: DrvMeta, 15 - source: Src, 16 - build_plan: BuildPlan, 17 - 18 - more: X, 19 - } 20 - } 21 - 22 - mod build { 23 - let unpack = BuildStep(|| { 24 - let src: PathBuf = std::build::source(); 25 - 26 - // unpack in cwd 27 - match src.ext() { 28 - ".tar.gz" | ".tgz" | ".tar.Z" => gzip(src), 29 - ".tar.bz2" | ".tbz2" | ".tbz" => bzip2(src), 30 - ".tar.xz" | ".tar.lzma" | ".txz" => xz(src), 31 - _ => panic!("could not unpack") 32 - } 33 - }); 34 - } 35 - } 36 - 37 - /// all package derivations 38 - mod pkgs { 39 - mod hello; 40 - mod libxkbcommon; 41 - mod sway; 42 - } 43 - 44 - /// options definitions 45 - mod options { 46 - mod machine { } 47 - mod user { } 48 - }
+30
examples/machine/cristal.rs
··· 1 + //! This whole file is an experiment to show how I would translate my own Nix 2 + //! laptop config available at <https://github.com/mrnossiom/dotfiles/blob/main/flake.nix> 3 + 4 + // this looks like deno http imports 5 + // See <https://docs.deno.com/runtime/fundamentals/modules/#https-imports> 6 + use "github:nixos/nixpkgs/nixos-24.11" as nixpkgs; 7 + use "github:nixos/nixpkgs/nixos-unstable" as nixpkgs_unstable; 8 + use "github:nix-community/home-manager/release-24.11" as home_manager; 9 + 10 + // versions of dependencies are frozen in a lockfile 11 + 12 + use "github:LnL7/nix-darwin" as nix_darwin; 13 + use "github:ryantm/agenix" as agenix; 14 + use "github:nix-community/disko" as disko; 15 + use "github:nixos/nixos-hardware" as nixos_hardware; 16 + 17 + /// options definitions 18 + mod options { 19 + mod machine {} 20 + mod user {} 21 + } 22 + 23 + // could having `default` as a kw would be useful for many things 24 + 25 + // should we explicitly export the item (like rust)? e.g. pub crystal = ... 26 + // should files return the last item (like nix)? 27 + // should we provide a default export (like js)? pub default = ... (where default is a kw) 28 + Crystal::new({ 29 + 30 + })
-69
examples/pkgs/hello.rs
··· 1 - use std::derivation::{Derivation, DerivationMeta, BuildStep, Source}; 2 - 3 - pub let meta = DerivationMeta.new { 4 - name: "hello", 5 - version: "2.12.1", 6 - description: "Program that produces a familiar, friendly greeting", 7 - 8 - license: License::Gpl3Plus | License::Apache, 9 - 10 - // changelog, mainteners, platforms, etc. 11 - // `mainProgram` makes no sense 12 - }; 13 - 14 - let source = Source::fetch_url(_ { 15 - // interpolation vvvvvvvvvvvv 16 - url: "mirror://gnu/hello/hello-{meta.version}.tar.gz", 17 - // keep hash in source? 18 - hash: "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA=", 19 - }); 20 - 21 - // none 22 - let build_step = BuildStep::new(|| { 23 - // call `./configure` 24 - std::build::???::configure(); 25 - // call `make` 26 - std::build::make::???(); 27 - }); 28 - 29 - // special imperative block to act 30 - let install_step = BuildStep::new(|| { 31 - // type is opt, just to show here 32 - let out: PathBuf = std::build::request_output_dir(); 33 - 34 - std::install::make::install(); 35 - }); 36 - 37 - // special imperative block to act 38 - let install_check = BuildStep::new(|| { 39 - let out: PathBuf = std::build::request_output_dir(); 40 - let hello_bin = out.join("bin/hello"); 41 - 42 - std::check::is_present(hello_bin)?; 43 - 44 - std::check::exec(hello_bin, []); 45 - }); 46 - 47 - // ability to document derivations 48 - pub let derivation = Derivation::new(_ { 49 - meta, 50 - source, 51 - 52 - // new starts from empty plan, could have `unpack` with first being unpack phase, `stdenv` for configure make make install workflows 53 - steps: BuildPlan::new([ 54 - // see example down below 55 - std::build::unpack(), 56 - // patch step 57 - // configure step 58 - build_step, 59 - // build check step 60 - install_step, 61 - // fixup step, patches files to work in nix??? envs 62 - install_check, // could do some `bin/<name> -v` to ensure that linking worked fine 63 - // distribution step 64 - ]), 65 - }); 66 - 67 - let out = derivation.out(); 68 - 69 - pub let bin = out.join()