-
-
Notifications
You must be signed in to change notification settings - Fork 37
Add Nix Flake #272
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
Draft
jeff-hykin
wants to merge
3
commits into
zen-fs:main
Choose a base branch
from
jeff-hykin:flake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Nix Flake #272
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| { | ||
| 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 | ||
| projectName = "zen-fs_core"; # used as directory name (e.g. no slashes) | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| overlays = [ | ||
| ]; | ||
| config = { | ||
| allowUnfree = true; | ||
| allowInsecure = false; | ||
| permittedInsecurePackages = []; | ||
| }; | ||
| }; | ||
| inputPackages = [ | ||
| pkgs.nodejs | ||
| pkgs.cacert # needed for installing npm packages | ||
| pkgs.nodePackages.typescript | ||
| pkgs.nodePackages.prettier | ||
| ]; | ||
| in | ||
| { | ||
| # 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/${projectName}"; | ||
| 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 | ||
|
|
||
| # without this npm (from nix) will not keep a reliable cache (it'll be outside of the xome home) | ||
| export npm_config_cache="$HOME/.cache/npm" | ||
|
|
||
| if ! [ -d "node_modules" ] | ||
| then | ||
| printf "\n\nI don't see node modules, want me to install them (default=yes)? [y/n]\n";answer="" | ||
| while true; do | ||
| echo "$question"; read response | ||
| case "$response" in | ||
| [Yy]* ) answer='yes'; break;; | ||
| [Nn]* ) answer='no'; break;; | ||
| * ) echo "Please answer yes or no.";; | ||
| esac | ||
| done | ||
|
|
||
| if [ "$answer" = 'yes' ]; then | ||
| npm install | ||
| else | ||
| echo "skipping" | ||
| fi | ||
| fi | ||
|
|
||
| echo | ||
| echo "NOTE: if you want to use sudo/git/vim/etc (anything impure) do: sys <that command>" | ||
| ''; | ||
| }; | ||
| starship = { | ||
| enable = true; | ||
| enableZshIntegration = true; | ||
| settings = { | ||
| character = { | ||
| success_symbol = "[∫](bold green)"; | ||
| error_symbol = "[∫](bold red)"; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| # as an automated reproducible dependency | ||
| packages.default = ( | ||
| let | ||
| # The path to the npm project | ||
| src = ./.; | ||
|
|
||
| # Read the package-lock.json as a Nix attrset | ||
| packageLock = builtins.fromJSON (builtins.readFile (src + "/package-lock.json")); | ||
|
|
||
| # Create an array of all (meaningful) dependencies | ||
| deps = builtins.attrValues (removeAttrs packageLock.packages [ "" ]) | ||
| ++ ( | ||
| if (builtins.hasAttr "dependencies" packageLock) then | ||
| builtins.attrValues (removeAttrs packageLock.dependencies [ "" ]) | ||
| else | ||
| [] | ||
| ) | ||
| ; | ||
|
|
||
| # Turn each dependency into a fetchurl call | ||
| tarballs = map (p: pkgs.fetchurl { url = p.resolved; hash = p.integrity; }) deps; | ||
|
|
||
| # Write a file with the list of tarballs | ||
| tarballsFile = pkgs.writeTextFile { | ||
| name = "tarballs"; | ||
| text = builtins.concatStringsSep "\n" tarballs; | ||
| }; | ||
| in | ||
| pkgs.stdenv.mkDerivation { | ||
| inherit (packageLock) name version; | ||
| inherit src; | ||
| buildInputs = inputPackages; # needed for https | ||
|
|
||
| buildPhase = '' | ||
| # ensure TMPDIR is defined, fallback to /tmp | ||
| : ${TMPDIR:=/tmp} | ||
| echo "Using TMPDIR=$TMPDIR" | ||
|
|
||
| # define writable npm locations | ||
| export HOME="$PWD/.home" | ||
| export NPM_CONFIG_CACHE="$HOME/.cache/npm" | ||
| export npm_config_cache="$NPM_CONFIG_CACHE" | ||
| export NPM_CONFIG_TMP="$HOME/.npm-tmp" | ||
| export NPM_CONFIG_PREFIX="$out" | ||
|
|
||
| # ensure dirs exist and are writable | ||
| mkdir -p "$NPM_CONFIG_CACHE" "$NPM_CONFIG_TMP" "$NPM_CONFIG_PREFIX" | ||
|
|
||
| js_path="$out/src" | ||
| mkdir -p "$js_path" | ||
| cp -r "$src/." "$js_path" | ||
| # make locks writable | ||
| chmod +w "$js_path/yarn.lock" 2>/dev/null || true | ||
| chmod +w "$js_path/package-lock.json" 2>/dev/null || true | ||
|
|
||
| cd "$js_path" | ||
| while read package | ||
| do | ||
| echo "caching $package" | ||
| npm cache add "$package" | ||
| done <${tarballsFile} | ||
|
|
||
| npm ci --no-save --no-audit --no-fund | ||
| echo "npm run build" | ||
| npm run build | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| # uncomment below if the project creates binaries to share | ||
| # ln -s "$js_path/node_modules/.bin" "$out/bin" | ||
| mkdir -p "$out/dist" | ||
| cp -r dist/* "$out/dist" | ||
| ''; | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Leftover from yarn