#!/bin/bash export N=$HOME/nix # real install to ~/nix #export N=/dev/shm/nix # temp install to RAM { oops() { echo "$0:" "$@" >&2; exit 1; } title() { echo "$*"; sleep 0.5; printf "\033]0;%s\007" "$*"; } USER=$(id -u -n) if [ -d "$N" ]; then echo "Nix already installed. Entering environment." echo "In future enter nix by running:" echo echo " $N/enter" echo exec "$N/enter" fi mkdir "$N" "$N/root-nix" "$N/home" "$N/home/.config" "$N/home/.config/nix" "$N/home/.config/home-manager" || oops "Unable to create directories" ln -s "$HOME" "$N/home/$USER" || oops "unable to create $USER symlink" title "Downloading nix-user-chroot" wget -O "$N/nix-user-chroot" https://github.com/nix-community/nix-user-chroot/releases/download/1.2.2/nix-user-chroot-bin-1.2.2-x86_64-unknown-linux-musl || oops "Failed to download nix-user-chroot" chmod u+x "$N/nix-user-chroot" || oops "Unable to make $N/nix-user-chroot executable" title "Downloading nixos.org/nix/install" wget -O "$N/nix.install" https://nixos.org/nix/install || oops "Failed to download nixos.org/nix/install" title "Downloading pinokio package files" wget -O "$N/home/.config/home-manager/pinokio.nix" https://raw.githubusercontent.com/ThomasEricB/pinokio-with-user-nix/refs/heads/main/pinokio.nix || oops "Failed to download pinokio.nix" wget -O "$N/home/.config/home-manager/pinokio-flake.nix" https://raw.githubusercontent.com/ThomasEricB/pinokio-with-user-nix/refs/heads/main/pinokio-flake.nix || oops "Failed to download pinokio-flake.nix" title "Creating files" cat < "$N/home/README" Q1. How do I enter the nix environment? Run: $N/enter Q2. How do I run a program without installing it? nix run nixpkgs#ncdu nix run nixpkgs#vlc or nix shell nixpkgs#ncdu ncdu Q3. How do I find a program to run? nix search nixpkgs ncdu Q4. How do I install a program? Add the name of the program to home.nix's home.packages line. For example: home.packages = (with pkgs; [ nix nettools bashInteractive ncdu vlc ]); Then rebuild with: home-manager switch Q5. Where is the home.nix and flake.nix? $N/home/.config/home-manager/home.nix $N/home/.config/home-manager/flake.nix Q6. How do I rebuild after editing home.nix or flake.nix? Run: home-manager switch Note: After initial setup, always use "home-manager switch" to rebuild. The bootstrap activation script is only used during first install. Q7. How do I update the programs? nix flake update --flake ~/.config/home-manager home-manager switch Note: The flake.lock file pins exact package versions. "nix flake update" bumps all inputs (nixpkgs, home-manager) to their latest commits. Q8. How do I reclaim disk space? nix-collect-garbage -d nix-store --optimise The first command removes old generations and unreferenced packages. The second deduplicates identical files in the store (can save 25-35%). Run both periodically, especially on limited storage. Q9. What is the layout of this install? dir $N enter script $N/enter pinokio $N/pinokio.sh home $N/home README $N/home/README pinokio pkg $N/home/.config/home-manager/pinokio.nix nix store $N/root-nix/store Q10. How do I remove everything, including the nix home directory? chmod -R u+w '$N' rm '$N' -r WARNING: Never run "nix profile install" or "nix profile remove" commands. These permanently corrupt the profile format used by home-manager and nix-env. If you accidentally ran one, delete ~/.nix-profile and rebuild: rm -f ~/.nix-profile home-manager switch Q11. Where are these instructions stored? $N/home/README Q12. How do I enter the nix environment again? Run: $N/enter Q13. How do I launch Pinokio? $N/pinokio.sh This runs the installed Pinokio through the nix-user-chroot. You can also launch it from inside the nix environment with: pinokio EOF cat < "$N/home/.config/nix/nix.conf" experimental-features = nix-command flakes max-jobs = auto auto-optimise-store = true warn-dirty = false EOF cat < "$N/home/.config/home-manager/flake.nix" { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; hm = { url = "github:nix-community/home-manager/release-25.11"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, hm }: { homeConfigurations.$USER = hm.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [ ./home.nix ]; }; }; } EOF cat < "$N/home/.config/home-manager/home.nix" # After editing this file, run: # # home-manager switch # { config, pkgs, ... }: let pinokio = pkgs.callPackage ./pinokio.nix {}; in { home.username = "$USER"; home.homeDirectory = "$N/home"; # DO NOT CHANGE. This must stay at the version you first installed. # Changing it can break your configuration. See: # https://nix-community.github.io/home-manager/release-notes.xhtml home.stateVersion = "22.05"; home.packages = (with pkgs; [ nix nettools bashInteractive glibcLocales # To find more packages, use: # # nix search nixpkgs NAME # ]) ++ [ pinokio ]; # Required for locale support inside the nix-user-chroot. # Without this, bash warns about missing pt_BR.UTF-8 (or your locale). home.sessionVariables = { LOCALE_ARCHIVE = "\${pkgs.glibcLocales}/lib/locale/locale-archive"; }; #To find more home-manager programs use: # # man home-configuration.nix # programs.home-manager.enable = true; programs.bash = { enable = true; profileExtra = '' . "\${config.home.profileDirectory}/etc/profile.d/nix.sh" ''; }; } EOF cat < "$N/enter" #!/bin/bash export HOME=$N/home cd ~/ du -hs $N echo "home:" \$HOME export LOCALE_ARCHIVE=\$HOME/.nix-profile/lib/locale/locale-archive exec $N/nix-user-chroot $N/root-nix ~/.nix-profile/bin/bash -l EOF chmod u+x "$N/enter" || oops "Unable to make $N/enter executable" cat < "$N/pinokio.sh" #!/bin/bash export HOME=$N/home export LOCALE_ARCHIVE=\$HOME/.nix-profile/lib/locale/locale-archive exec $N/nix-user-chroot $N/root-nix \$HOME/.nix-profile/bin/pinokio "\$@" EOF chmod u+x "$N/pinokio.sh" || oops "Unable to make $N/pinokio.sh executable" cat < "$N/home-manager-flake.install" oops() { echo "$0:" "$@" >&2; exit 1; } title() { printf "\033]0;%s\007" "$*"; } title "Loading ~/.nix-profile/etc/profile.d/nix.sh" . ~/.nix-profile/etc/profile.d/nix.sh || oops "failed to source ~/.nix-profile/etc/profile.d/nix.sh" title "nix registry pin nixpkgs" nix registry pin nixpkgs || oops "failed to: nix registry pin nixpkgs" title "Building home-manager configuration" nix-env --set-flag priority 10 nix || oops "failed to: nix-env --set-flag priority 10 nix" nix build --no-link ~/.config/home-manager#homeConfigurations.$USER.activationPackage || oops "failed to build ~/.config/home-manager#homeConfigurations.$USER.activationPackage" title "Activating home-manager configuration" "\$(nix path-info ~/.config/home-manager#homeConfigurations.$USER.activationPackage)"/activate || oops "failed to activate home-manager config" title "Removing nix-env's nix command" nix-env -e nix || oops "failed to remove nix-env's version of the nix command" title "nix-collect-garbage -d" nix-collect-garbage -d || oops "failed to nix-collect-garbage -d" EOF title "Running nixos.org/nix/install" HOME="$N/home" "$N/nix-user-chroot" "$N/root-nix" /bin/bash "$N/nix.install" || oops "nixos.org/nix/install failed" title "Installing home-manager" HOME="$N/home" "$N/nix-user-chroot" "$N/root-nix" /bin/bash "$N/home-manager-flake.install" || oops "home-manager-flake.install failed" echo du -hs "$N" echo cat "$N/home/README" "$N/enter" }