fsquillace / junest

The lightweight Arch Linux based distro that runs, without root privileges, on top of any other Linux distro.
GNU General Public License v3.0
2.08k stars 111 forks source link

Add Nix/NixOS support #282

Closed nayr7 closed 3 months ago

nayr7 commented 2 years ago

Features

This pull request enables Nix and NixOS support via nix flakes

Important Notes

nayr7 commented 2 years ago

Calling junest twice after junest setup will throw an error. It can be worked around with junest -n or by deleting /etc/netgroup inside the junest environment (but the file will be copied again at the next junest execution).

[ieltan@nixbox:~/junest]$ junest -n
cp: cannot create regular file '/home/ieltan/.junest//etc/netgroup': Permission denied
/home/ieltan/.junest/usr/bin/cp: cannot create regular file '/home/ieltan/.junest//etc/netgroup': Permission denied
fsquillace commented 2 years ago

Hi,

Thanks for this pull request. Regarding the issue here:

Calling junest twice after junest setup will throw an error. It can be worked around with junest -n or by deleting /etc/netgroup inside the junest environment (but the file will be copied again at the next junest execution).

[ieltan@nixbox:~/junest]$ junest -n
cp: cannot create regular file '/home/ieltan/.junest//etc/netgroup': Permission denied
/home/ieltan/.junest/usr/bin/cp: cannot create regular file '/home/ieltan/.junest//etc/netgroup': Permission denied

This may be on a separate thread as an Issue. Strangely, it does not have permission to read that file. It never happened to me. Can you check the permissions? Which distro are you using?

ls -l /etc/netgroup

Regarding the pull request I am not sure whether this repository would be the one suitable for having such files. Also, can you tell me how the nixos and flake work (possibly with some snippets) and what's their benefit in the JuNest context?

Thanks!

nayr7 commented 2 years ago

Hello, sorry for the delay, I would be happy to explain how flake.nix and other components of this PR (default.nix / flake.lock) work.

First of all I will establish some definitions: NixOS = the linux distro; Nix = the package manager; inputs = dependencies.

To make a package, even a bash script work on NixOS, you will need to package it because packages don't go in directories like /etc,/bin,/usr/bin, etc... Instead they're all stored in a directory called /nix/store. Here's a very good article that explains why.

The flake.nix file allows Nix users (and by extension, NixOS users) to install junest by using a feature called flake. flake.lock is generated automatically by Nix in order to pin the inputs' versions (declared in flake.nix) to ensure reproducibility, those two will always be used together. For example, if I want to install junest from the github repo, I will either declare it in my system flake inputs :

# flake.nix in a user computer ( note that this is pseudo-code-ish )
inputs = { junest.url = "github:fsquillace/junest"; };

outputs = { self, junest, ... }@inputs: { 
     overlays = [ (final: _:
       let system = final.system;
       in { # Packages provided by flake inputs
             junest = junest.packages.${system}.junest;
           };
     )]};

or if I dont like the declarative method I can install it from the CLI with this command nix profile install github:fsquillace/junest/.

default.nix wraps the flake so that it's usable for Nix users who do not use this feature (it's disabled by default), they clone the repo and run nix-env -iA inside the git repository to install junest, or they use the declarative method too without flakes.

Junest has nothing to lose by supporting one more distro, of course it's absurd to say you should support every unconventional and obscure linux distro in the world, but I am willing to help with this. Junest is also a great tool to escape "the Nix way" of doing things, I use Junest on my NixOS box to install some AppImages and other software that is too complicated to package for Nix as a user.

This may be on a separate thread as an Issue. Strangely, it does not have permission to read that file. It never happened to me. Can you check the permissions? Which distro are you using?

I opened an issue about this: 284

Regarding the pull request I am not sure whether this repository would be the one suitable for having such files.

Those files only serve to tell Nix how to install Junest on the nix store, since junest checks for some commands in /etc or /bin that does not exist* on NixOS, you can tell Nix how to patch junest during evaluation time to replace them with the correct paths. It makes it easy to install and ready to go without headaches for newcomers.

fsquillace commented 2 years ago

I might say that this is very specific to the given Nix space and, supporting the packaging of JuNest codebase is not part of what this repository is supposed to be. Otherwise, this will require to add more code to support addtitional package managers in the future. I think each code repo should follow a single responsibility principle as much as possible. For this reason, I do see this useful though as part of a separate repository which describe the Nix package only and pull the JuNest code to it even if from a different git repo (I do not know if this is feasible with Nix but there are other package managers that allows that).

As side note: talking about (universal) package managers, you might be interested on Pearl package manager which help define custom environments (programs, dotfiles, etc) on different systems (linux distro or OSX). Be aware though that I might be bias given that I am maintaining it ;)

jdev082 commented 3 months ago

Junest has been added to Nixpkgs and is available in unstable

https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/ju/junest/package.nix

Tested and confirmed working!

nayr7 commented 3 months ago

Thanks @jdev082 ! I relied on my personal module but it's nice to see a proper one made. Closed.