-
-
Notifications
You must be signed in to change notification settings - Fork 37
WIP: Multi Root Contexts #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e97fc1f
bf93add
ec682e4
c4f385d
94b2719
837bd24
953e334
05daf81
e3e2791
cb8f75b
0effbc9
0e582f6
9860d4c
80e08e8
93433ba
f35774b
12ff9bf
046d336
2d03216
67c1d3c
a35426a
35e686b
5bae834
773bc65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| { | ||
| description = "ZenFS"; | ||
| inputs = { | ||
| libSource.url = "github:divnix/nixpkgs.lib"; | ||
| flake-utils.url = "github:numtide/flake-utils"; | ||
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; | ||
| home-manager.url = "github:nix-community/home-manager/release-25.05"; | ||
| home-manager.inputs.nixpkgs.follows = "nixpkgs"; | ||
| xome.url = "github:jeff-hykin/xome"; | ||
| xome.inputs.nixpkgs.follows = "nixpkgs"; | ||
| xome.inputs.home-manager.follows = "home-manager"; | ||
| }; | ||
| outputs = { self, flake-utils, nixpkgs, xome, ... }: | ||
| flake-utils.lib.eachSystem flake-utils.lib.defaultSystems (system: | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| overlays = [ | ||
| ]; | ||
| config = { | ||
| allowUnfree = true; | ||
| allowInsecure = false; | ||
| permittedInsecurePackages = [ | ||
| ]; | ||
| }; | ||
| }; | ||
| inputPackages = [ | ||
| pkgs.nodejs | ||
| pkgs.esbuild | ||
| pkgs.graphviz | ||
| pkgs.nodePackages.typescript | ||
| pkgs.nodePackages.prettier | ||
| ]; | ||
| in | ||
| { | ||
| # this is how the package is built (as a dependency) | ||
| packages.default = pkgs.stdenv.mkDerivation { | ||
| name = "my-ts-app"; | ||
| src = ./.; | ||
|
|
||
| buildInputs = inputPackages; | ||
|
|
||
| buildPhase = '' | ||
| export HOME=$(mktemp -d) # Needed by npm to avoid global install warnings | ||
| npm install | ||
| tsc | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| mkdir -p $out | ||
| cp -r dist/* $out/ | ||
| ''; | ||
| }; | ||
|
|
||
| # development environment for contributions | ||
| devShells = xome.simpleMakeHomeFor { | ||
| inherit pkgs; | ||
| pure = true; | ||
| homeModule = { | ||
| # for home-manager examples, see: | ||
| # https://deepwiki.com/nix-community/home-manager/5-configuration-examples | ||
| # all home-manager options: | ||
| # https://nix-community.github.io/home-manager/options.xhtml | ||
| home.homeDirectory = "/tmp/virtual_homes/zenfs"; | ||
| home.stateVersion = "25.05"; | ||
| home.packages = inputPackages ++ [ | ||
| # vital stuff | ||
| pkgs.dash # provides "sh" | ||
| pkgs.coreutils-full | ||
|
|
||
| # optional stuff | ||
| pkgs.gnugrep | ||
| pkgs.findutils | ||
| pkgs.wget | ||
| pkgs.curl | ||
| pkgs.unixtools.locale | ||
| pkgs.unixtools.more | ||
| pkgs.unixtools.ps | ||
| pkgs.unixtools.getopt | ||
| pkgs.unixtools.ifconfig | ||
| pkgs.unixtools.hostname | ||
| pkgs.unixtools.ping | ||
| pkgs.unixtools.hexdump | ||
| pkgs.unixtools.killall | ||
| pkgs.unixtools.mount | ||
| pkgs.unixtools.sysctl | ||
| pkgs.unixtools.top | ||
| pkgs.unixtools.umount | ||
| pkgs.git | ||
| pkgs.htop | ||
| pkgs.ripgrep | ||
| ]; | ||
|
|
||
| programs = { | ||
| home-manager = { | ||
| enable = true; | ||
| }; | ||
| zsh = { | ||
| enable = true; | ||
| enableCompletion = true; | ||
| autosuggestion.enable = true; | ||
| syntaxHighlighting.enable = true; | ||
| shellAliases.ll = "ls -la"; | ||
| history.size = 100000; | ||
| # this is kinda like .zshrc | ||
| initContent = '' | ||
| # lots of things need "sh" | ||
| ln -s "$(which dash)" "$HOME/.local/bin/sh" 2>/dev/null | ||
|
|
||
| # this enables some impure stuff like sudo, comment it out to get FULL purity | ||
| # export PATH="$PATH:/usr/bin/" | ||
| echo | ||
| echo "NOTE: if you want to use sudo/git/vim/etc (anything impure) do: sys <that command>" | ||
| ''; | ||
| }; | ||
| starship = { | ||
| enable = true; | ||
| enableZshIntegration = true; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,29 @@ const contents = fs.readFileSync('/test.txt', 'utf-8'); | |
| console.log(contents); | ||
| ``` | ||
|
|
||
| #### Mount Namespaces | ||
|
|
||
| If making middleware, and the downstream consumer isn't providing a file system, you can make an isolated file system. This prevents accidental conflict if multiple middlewares use ZenFS. | ||
|
|
||
| ```js | ||
| import { configureIsolated, fs as globalThisFs } from '@zenfs/core'; | ||
|
|
||
| // create a local fs | ||
| const {fs, path} = await configureIsolated({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally the context examples use |
||
| pwd: '/home', | ||
| credentials: { uid: 1000, gid: 1000 }, | ||
| mounts: { | ||
| '/': InMemory, | ||
| '/home': InMemory, | ||
| }, | ||
| }); | ||
|
|
||
| fs.writeFileSync('/home/test.txt', 'isolated'); | ||
| globalThisFs.writeFileSync('/home/test.txt', 'global'); | ||
| // still says "isolated" | ||
| console.log(fs.readFileSync('/home/test.txt', 'utf8')); | ||
| ``` | ||
|
|
||
| #### FS Promises | ||
|
|
||
| The FS promises API is exposed as `promises`. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
configureIsolateddoesn't actually exist. Also, I'd like to avoiding creating yet anotherconfigurefunction.Let's adopt a similar approach as Linux where creating a new context (e.g. with
boundContext) can include a new set ofmounts(no new function needed). Maybe we should also have a flag for sharing subtrees (see mount_namespaces(7).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yeah my readme edit is completely out of date. I'll add that to the cleaning list