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: adding examples

+189
+5
README.md
··· 1 1 # Unsurprising 2 + 3 + # Lecture 4 + 5 + - The Purely Functional Software Deployment Model 6 + - https://jonathanlorimer.dev/posts/nix-thesis.html
+67
examples/flake.rs
··· 1 + use pkgs; 2 + // use pkgs::prelude::*; 3 + 4 + use gitignore; 5 + // not from pkgs, as more specialized 6 + use rust as rust_external; 7 + 8 + // formatter already exist by default 9 + 10 + let packages = { 11 + let lspelling: Drv = /* import lspelling package */; // { inherit gitignore; }; 12 + 13 + Packages::new_default(lspelling, { lspelling }) 14 + } 15 + 16 + let apps = { 17 + let lspelling = super::packages::lspelling::build().bin.lspelling; 18 + 19 + Packages::new_default(lspelling, { lspelling }) 20 + } 21 + 22 + let shells: std::???::Shells = { 23 + let rust_toolchain: Drv = rust_external::from_rustup_toolchain_file("./rust-toolchain.toml"); 24 + // shadowing :eyes: 25 + let rust_toolchain: Drv = rust_toolchain.override({ extensions: [ "rust-analyzer" ]; }); 26 + // -- other, cleaner imo, way 27 + let rust_toolchain: Drv = rust_external::from_rustup_toolchain_file("./rust-toolchain.toml", /* to_add: */ _ { extensions: [ "rust-analyzer" ] }); 28 + 29 + let dev = Shell::new { 30 + host_packages: [ 31 + // with pkgs; ??? 32 + pkgs::pkg_config, 33 + rust_toolchain, 34 + pkgs::act, 35 + 36 + pkgs::cargo_workspaces, 37 + ], 38 + target_packages: [ 39 + pkgs::hunspell, 40 + pkgs::libclang, 41 + pkgs::cc // stdenv.cc.cc 42 + ], 43 + 44 + env: { 45 + RUST_SRC_PATH: rust_toolchain.rust_lib_source as Str, 46 + LD_LIBRARY_PATH: makeLibraryPath buildInputs, 47 + 48 + RUST_LOG: "lspelling_lsp=debug,lspelling_wordc=debug,debug", 49 + LOG_FILE: "/tmp/lspelling.log", 50 + 51 + HUNSPELL_DICT: "${pkgs::hunspell_dicts::en_us_large.build()}/share/hunspell/en_US", 52 + } as Map<Str, impl ToString | Arr<impl ToString>>, 53 + // } as Map<Str, impl ToString>, 54 + }; 55 + 56 + Shells::new({ dev }) 57 + } 58 + 59 + // Flake::new(_ { 60 + // packages: { lspelling: lspelling_pkgs }, 61 + // packages: { lspelling: pkgs::lspelling }, 62 + // apps, // same 63 + // shells: { dev: dev_shell }, 64 + // }) 65 + 66 + // this is returned 67 + Flake::new(_ { packages, apps, shells })
+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 + }
+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()