The Nix package manager

Moderator: BarryK

Post Reply
Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

The Nix package manager

Post by Caramel »

Nix is an alternative to Flatpak.

Note 1 : there is no isolation of Nix and the programs it installs from the rest of EasyOS in my test
Note 2 : Nix creates a very large number of files (Saving to session or taking a snapshot of Easy is long)

EDIT : For a first or a speed reading go after METHOD I RECOMMEND

Some links :
https://en.wikipedia.org/wiki/Nix_(package_manager)
https://nixos.wiki/wiki/Nix_package_manager
https://nixos.org/learn.html
https://wiki.archlinux.org/title/Nix
https://nix-tutorial.gitlabpages.inria. ... arted.html
https://nixos.org/guides/how-nix-works.html
https://zero-to-nix.com/
https://nixos.org/guides/nix-pills/index.html
https://ianthehenry.com/posts/how-to-le ... roduction/

The documentation for Nix is very complicated but here i just want a very basic use : install and remove binaries packages available in the default channel (a channel for Nix is like a repository for distributions)

Summary of several weeks of testing.

To install Nix i found three sources:
https://nixos.org/download.html#download-nix
https://zero-to-nix.com/start/install
https://github.com/DavHau/nix-portable

The first is the official installer

The second is "The Determinate Nix Installer" (see https://github.com/determinateSystems/nix-installer and https://determinate.systems/posts/zero-to-nix).
It installs Nix with parts announced as still experimental (https://zero-to-nix.com/concepts/nix and https://zero-to-nix.com/concepts/nix-installer)

The third would be a portable version of Nix. I don't really understand and in quick tests don't seem to bring utility for a basic use.

****************
Official installer :
Two installation methods: multi-user or single-user

-In single-user installation, the script don't be run as root. So i created an new user named nix (this name was just a choice, probably not a good idea to avoid confusion) .As the environment variable XDG_CACHE_HOME of nix was /root/.cache and not /home/nix/.cache(EDIT : not exact see viewtopic.php?p=95149#p95149), we need to trick :

Code: Select all

adduser -D nix
mkdir /nix
chown nix /nix
mkdir /home/nix/.cache
mkdir /home/nix/.cache/nix
chown nix /home/nix/.cache/nix
ln -s /home/nix/.cache/nix /root/.cache/nix

Seem to work but at each boot /root/.cache/nix was deleted. As that time I didn't know how to launch a script at boot, so i give up

-In multi-user installation, the script wants to create new users and groups. It call the commands useradd and groupadd that don't exist in EasyOS.
We need to add lines to configurations files :

In /etc/group

Code: Select all

nixbld:x:30000:nixbld1,nixbld2,nixbld3,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld30,nixbld31,nixbld32

in /etc/gshadow

Code: Select all

nixbld:!::nixbld1,nixbld2,nixbld3,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld30,nixbld31,nixbld32

in /etc/password

Code: Select all

nixbld1:x:30001:30000:Nix build user 1,,,:/var/empty:/sbin/nologin
nixbld2:x:30002:30000:Nix build user 2,,,:/var/empty:/sbin/nologin
nixbld3:x:30003:30000:Nix build user 3,,,:/var/empty:/sbin/nologin
nixbld4:x:30004:30000:Nix build user 4,,,:/var/empty:/sbin/nologin
nixbld5:x:30005:30000:Nix build user 5,,,:/var/empty:/sbin/nologin
nixbld6:x:30006:30000:Nix build user 6,,,:/var/empty:/sbin/nologin
nixbld7:x:30007:30000:Nix build user 7,,,:/var/empty:/sbin/nologin
nixbld8:x:30008:30000:Nix build user 8,,,:/var/empty:/sbin/nologin
nixbld9:x:30009:30000:Nix build user 9,,,:/var/empty:/sbin/nologin
nixbld10:x:30010:30000:Nix build user 10,,,:/var/empty:/sbin/nologin
nixbld11:x:30011:30000:Nix build user 11,,,:/var/empty:/sbin/nologin
nixbld12:x:30012:30000:Nix build user 12,,,:/var/empty:/sbin/nologin
nixbld13:x:30013:30000:Nix build user 13,,,:/var/empty:/sbin/nologin
nixbld14:x:30014:30000:Nix build user 14,,,:/var/empty:/sbin/nologin
nixbld15:x:30015:30000:Nix build user 15,,,:/var/empty:/sbin/nologin
nixbld16:x:30016:30000:Nix build user 16,,,:/var/empty:/sbin/nologin
nixbld17:x:30017:30000:Nix build user 17,,,:/var/empty:/sbin/nologin
nixbld18:x:30018:30000:Nix build user 18,,,:/var/empty:/sbin/nologin
nixbld19:x:30019:30000:Nix build user 19,,,:/var/empty:/sbin/nologin
nixbld20:x:30020:30000:Nix build user 20,,,:/var/empty:/sbin/nologin
nixbld21:x:30021:30000:Nix build user 21,,,:/var/empty:/sbin/nologin
nixbld22:x:30022:30000:Nix build user 22,,,:/var/empty:/sbin/nologin
nixbld23:x:30023:30000:Nix build user 23,,,:/var/empty:/sbin/nologin
nixbld24:x:30024:30000:Nix build user 24,,,:/var/empty:/sbin/nologin
nixbld25:x:30025:30000:Nix build user 25,,,:/var/empty:/sbin/nologin
nixbld26:x:30026:30000:Nix build user 26,,,:/var/empty:/sbin/nologin
nixbld27:x:30027:30000:Nix build user 27,,,:/var/empty:/sbin/nologin
nixbld28:x:30028:30000:Nix build user 28,,,:/var/empty:/sbin/nologin
nixbld29:x:30029:30000:Nix build user 29,,,:/var/empty:/sbin/nologin
nixbld30:x:30030:30000:Nix build user 30,,,:/var/empty:/sbin/nologin
nixbld31:x:30031:30000:Nix build user 31,,,:/var/empty:/sbin/nologin
nixbld32:x:30032:30000:Nix build user 32,,,:/var/empty:/sbin/nologin

NB : /sbin/nologin don't exist in Easy, we can create it with :

Code: Select all

ln -s /bin/false /sbin/nologin

and finally in /etc/shadow

Code: Select all

nixbld1:!:19471:0:99999:7:::
nixbld2:!:19471:0:99999:7:::
nixbld3:!:19471:0:99999:7:::
nixbld4:!:19471:0:99999:7:::
nixbld5:!:19471:0:99999:7:::
nixbld6:!:19471:0:99999:7:::
nixbld7:!:19471:0:99999:7:::
nixbld8:!:19471:0:99999:7:::
nixbld9:!:19471:0:99999:7:::
nixbld10:!:19471:0:99999:7:::
nixbld11:!:19471:0:99999:7:::
nixbld12:!:19471:0:99999:7:::
nixbld13:!:19471:0:99999:7:::
nixbld14:!:19471:0:99999:7:::
nixbld15:!:19471:0:99999:7:::
nixbld16:!:19471:0:99999:7:::
nixbld17:!:19471:0:99999:7:::
nixbld18:!:19471:0:99999:7:::
nixbld19:!:19471:0:99999:7:::
nixbld20:!:19471:0:99999:7:::
nixbld21:!:19471:0:99999:7:::
nixbld22:!:19471:0:99999:7:::
nixbld23:!:19471:0:99999:7:::
nixbld24:!:19471:0:99999:7:::
nixbld25:!:19471:0:99999:7:::
nixbld26:!:19471:0:99999:7:::
nixbld27:!:19471:0:99999:7:::
nixbld28:!:19471:0:99999:7:::
nixbld29:!:19471:0:99999:7:::
nixbld30:!:19471:0:99999:7:::
nixbld31:!:19471:0:99999:7:::
nixbld32:!:19471:0:99999:7:::

We can now launch the installation script :

Code: Select all

sh <(curl -L https://nixos.org/nix/install) --daemon

We can use /root/Startup to launch the nix-daemon at boot as requested by the script (I think it useless for a basic use of Nix)

****************
Determinate Nix installer

(METHOD I RECOMMEND)

Script to launch

Code: Select all

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux --init none

EDIT : deletion of the idea to replace the folder /nix by a symbolic link. It's not allowed by Nix !

Then to subscribe to the nixkpgs-unstable channel (This part is automatic in the official nix installer) :

Code: Select all

nix-channel --add https://nixos.org/channels/nixpkgs-unstable
nix-channel --update

Installation terminated !

The documentation on the zero-to-nix site is clear but very incomplete.

I will use nix in the same way as with the official installer (The concept of Flake highlighted by zero-to-nix is set aside here)

****************
Basic commands

Before starting :

Code: Select all

echo $PATH

to verify that nix is in the PATH
If not open a new terminal

The principal command is nix-env with options (see https://github.com/tldr-pages/tldr/blob ... nix-env.md for details) :

To search an available package : (example here with the search of "name")
nix-env -qaP | grep -i name (very slow, long time to wait the answer)
Alternately, it's faster using the site https://search.nixos.org/packages (choose the channel unstable) (More on searching packages : https://nixos.wiki/wiki/Searching_packages)

To install the package named "example"
nix-env -iA nixpkgs.example

If "example" is an application, we can run it in a terminal by simply typing example. If another version of example is installed in Easy,it's the version provided by Nix that run

To remove "example" of the user environment (if "example" is an application, example get out of the PATH and typing example no longer work or launch the version installed in Easy) :
nix-env -e example

When we install or remove a pckage, we create a new generation of the user-environment.

To really delete a package (after it was removed), we need to delete the old generations where it was installed. and then tu run the garbage collector

Code: Select all

nix-env --delete-generations old

delete all the generations other that the last (For more choice see https://nixos.org/manual/nix/unstable/p ... ction.html)

To run the garbage collector :

Code: Select all

nix-store --gc

To delete all the old generations and run the garbage collector in an unique command :

Code: Select all

$ nix-collect-garbage -d

EDIT : to remove Nix all its components and programms it has installed :

Code: Select all

/nix/nix-installer uninstall
Last edited by Caramel on Tue Aug 22, 2023 8:56 am, edited 7 times in total.
williwaw
Posts: 1952
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 369 times

Re: The Nix package manager

Post by williwaw »

what have you found that would make Nix a better choice than appimage, snaps, flatpacks etc?

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Re: The Nix package manager

Post by Caramel »

williwaw wrote: Sat Jun 10, 2023 5:59 pm

what have you found that would make Nix a better choice than appimage, snaps, flatpacks etc?

I never tested Snap.
AppImages are good but there are not enough available applications.
Flatpak needs very very big space

The real problem with Nix is that it is not sandboxed (I think, not sure)

Last edited by Caramel on Sat Jun 10, 2023 6:25 pm, edited 1 time in total.
bullpup
Posts: 67
Joined: Sat Jul 18, 2020 7:37 am
Has thanked: 22 times
Been thanked: 3 times

Re: The Nix package manager

Post by bullpup »

This all seems awfully complicated to me.

"Get a pup", they said. "It'll be fun", they said. They where right!
(Various Pups with save folder in QEMU/KVM)

williwaw
Posts: 1952
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 369 times

Re: The Nix package manager

Post by williwaw »

Note 1 : there is no isolation of Nix and the programs it installs from the rest of EasyOS in my test

possibly a good candidate to run in a container?

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Re: The Nix package manager

Post by Caramel »

bullpup wrote: Sat Jun 10, 2023 6:25 pm

This all seems awfully complicated to me.

If you want all the possibilities of Nix , yes it's very complicated. But for a basic use all is in my first post after "METHOD I RECOMMEND"

The only difficulty is the use of command lines

The links are only for interessed and competent people

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Re: The Nix package manager

Post by Caramel »

I made little corrections to my first post.

In particular i added the command for completely uninstalled nix (If it was installed with the Determinate Nix installer)

I removed the idea of use symlink to relocate the /nix folder (it not wotks)

In fact to move the contents of /nix elsewhere we need to use the command mount (see https://nixos.org/manual/nix/stable/com ... LINK_STORE)
For example if we place /nix in root of the partition /mnt/sda2 , the command

Code: Select all

mount -o bind /mnt/sda2/nix /nix

must be executed before the use of nix or of a program it has installed
The best is to create a script with this command in /root/Startup. (Edit : must start before possible other script using nix)
I'm know it's not so easy

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Localisation in nix

Post by Caramel »

Reference : https://nixos.wiki/wiki/Locales

To use applications installed by Nix in a language other than English, you have to set the environmental variable LOCALE_ARCHIVE

Code: Select all

export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive

The file locale-archive don't exist in EasyOS.
You can create it with the command localedef. Unfortunately I don't have found good documentation for localedef

Usage :
localedef -i langset -f charset NAME
"langset" is the lang (it's the beginning of $LANG, before the dot if there is one), "charset" is provided by "locale charmap"
NAME is ?

Example that works with LANG=fr-FR.UTF-8 :
localedef -i fr_FR -f UTF-8 fr_FR.utf8

Or You can also use the file locale-archive of another distribution

williwaw
Posts: 1952
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 369 times

Re: The Nix package manager

Post by williwaw »

williwaw wrote: Sat Jun 10, 2023 6:28 pm

Note 1 : there is no isolation of Nix and the programs it installs from the rest of EasyOS in my test

possibly a good candidate to run in a container?

after looking over nix and seeing your post in the other thread, maybe not a good candidate for a container.

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Nix in Container(with not maximum security )

Post by Caramel »

This container is only for test by curious people. It is not as easy to use as EasyOS. It works with command line.

Download link : https://www.swisstransfer.com/d/afec382 ... 3db0a96015 (93 MB)

I don't have added a pixmap so the icon is the default icon for containers, a hammer

The three files (.sfs, .specs and .png) must be moved to /mnt/wkg/sfs/easyos/oe/kirkstone.
You install the container with SFSget in PKGget (icon PKG or entry in menu, configuration section) by choosing nix (in easyos/oe/kirkstone)

After installation clicking the hammer icon on the desk opens (after several secondes) a sakura console. (only usable for the container)
This console is used for the nix commands (nix-env, nix-collect-garbage) and for launching the programs installed by nix (The programs stay in the container)
(For usage of nix see my first message.)

By default the container is less secure than a normal container. It's necessary for adding or removing programs by a nix command. To only use programs installed by nix, the container can be configurated with normal settings

(The security is configured via Easy_Containers in the files section of the menu. To restore the normal settings, you check the file box in tab Expert. It's also possible to directly edit the configuration file in the container folder )
(NB the modification of the configuration is impossible when the container runs)

To uninstall the nix container and the programs inside, use Easy_Containers. Then the folder /mnt/wkg/container/nix must have been deleted. If not, it is a problem of unmounting. You will be able to delete it after a reboot.

User avatar
mouldy
Posts: 592
Joined: Tue Dec 08, 2020 3:53 pm
Has thanked: 39 times
Been thanked: 170 times

Re: The Nix package manager

Post by mouldy »

If you want to try Nix without the complexity just to see what its like, the website does offer a NixOS-gnome iso. My old desktop is not UEFI so just burned it to dvd and booted. Ok gnome desktop, bleh, but functional. It however immediately goes to installer without asking, though it offers live dvd functionality with no way to save anything if you cancel install. It then says it cant install without a internet connection. Bleh again. My internet requires Easytether or Azilink to share my phone internet and this NixOS comes with neither the necessary adb or openvpn so I gave up at that point rather than statically adding all that which does work, but.... But the installer does do all the hard work downloading and setting up all the extra NIX stuff, if you have usual ethernet or wifi. I suspect the easiest way for me to do this is create a hotspot on an existing linux install and connecting via that on installation computer. Once its installed then I can add adb and openvpn via Nix.

Yea nothing to do with Nix in Easy, but I've always found its easier to install something if you know what the heck you are installing and how it works. In other words having some experience with it. No better way than where its set up for such in first place. Oh the NixOS live dvd does include very nice manual on installing and using it.

Nix is definitely interesting and they have a LOT of pkgs that appimage doesnt and without all the bloat of flatpak/snap. This is probably the better engineered mousetrap. They do need to make interface lot more user friendly. and I still dont know why either they dont build actual Nix functionality into the live dvd, or at least let the silly thing install without needing an internet connection.

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Re: The Nix package manager

Post by Caramel »

mouldy wrote: Fri Jul 14, 2023 5:54 pm

If you want to try Nix without the complexity just to see what its like, the website does offer a NixOS-gnome iso. My old desktop is not UEFI so just burned it to dvd and booted. Ok gnome desktop, bleh, but functional. It however immediately goes to installer without asking, though it offers live dvd functionality with no way to save anything if you cancel install. It then says it cant install without a internet connection. Bleh again. My internet requires Easytether or Azilink to share my phone internet and this NixOS comes with neither the necessary adb or openvpn so I gave up at that point rather than statically adding all that which does work, but.... But the installer does do all the hard work downloading and setting up all the extra NIX stuff, if you have usual ethernet or wifi. I suspect the easiest way for me to do this is create a hotspot on an existing linux install and connecting via that on installation computer. Once its installed then I can add adb and openvpn via Nix.

Yea nothing to do with Nix in Easy, but I've always found its easier to install something if you know what the heck you are installing and how it works. In other words having some experience with it. No better way than where its set up for such in first place. Oh the NixOS live dvd does include very nice manual on installing and using it.

I did not try the NixOS iso (that I didn't know existed, thanks for this information). But, in view of the documentation, NixOS seems very difficult to configure if you are not a computer scientist

Here, I was hoping interest someone much more competent than me to make (the basic usage of) Nix more user-friendly.

User avatar
mouldy
Posts: 592
Joined: Tue Dec 08, 2020 3:53 pm
Has thanked: 39 times
Been thanked: 170 times

Re: The Nix package manager

Post by mouldy »

I agree with you on both points. It is very complex, but also lot reward for the effort I think, especially if one of smart people here get interested enough to make a friendlier interface for an average user. I have to be in right mood to jump all the hoops to give the live dvd an internet connection, and I need to find a spare SSD to let it install to. But do think its worth the effort, just like to see what its like in real world. By way the installer gives options other than gnome for a desktop or you can opt out of a graphic desktop and install your own windows manager. I am really not a gnome fan, gnome is set up to make several clicks to do something when one should suffice. Their website let me search for available packages, and yet to find any major ones it doesnt have, including WINE. Of course then making it work well in Easy or one of the Puppies, most likely not so easy.

williwaw
Posts: 1952
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 369 times

Re: The Nix package manager

Post by williwaw »

I did not try the NixOS iso (that I didn't know existed, thanks for this information). But, in view of the documentation, NixOS seems very difficult to configure if you are not a computer scientist

I tried the nixos minimal iso hoping I could build what I needed from the basic install, but not knowing how to set up the config file and electing the offered defaults. it installed gnome and presumably everthing that is included in the full desktop .iso. I didnt have a spare disk to use. so I followed your tutorial and installed your sfs on the main desktop of a new dedicated frugal alongside 2 other easys on my HD.

Nice of you to do the heavy lifting and make the sfs! The few apps I installed worked well.

Going to explore the repo a bit and try to learn some more basic commands next.

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Re: The Nix package manager

Post by Caramel »

Just for correct an assertion of my first message :

Caramel wrote: Sat Jun 10, 2023 3:59 pm

-In single-user installation, the script don't be run as root. So i created an new user named nix (this name was just a choice, probably not a good idea to avoid confusion) .As the environment variable XDG_CACHE_HOME of nix was /root/.cache and not /home/nix/.cache, we need to trick :

In fact the environment variable XDG_CACHE_HOME of the user nix is /home/nix/.cache.
I typed "su nix" for launch commands as nix. I should have typed "su -l nix" or "su --login nix"

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Nix42b: User-friendly interface for the Nix package manager ?

Post by Caramel »

First tests with nix42b, a gui for nix (for nix on non Nixos)

Link of the project (not updated since 3 years) : https://gitlab.com/juliendehos/nix42b
Small presentation : https://discourse.nixos.org/t/nix42b-us ... nager/5377
Video : https://gitlab.com/juliendehos/nix42b/- ... r/demo.mp4 (really start at the 18th second)

The command in the gitlab page only installs nix42b if nix is not yet installed (the script (https://gitlab.com/juliendehos/nix42b/- ... install.sh) start by installing nix).

So i only used the lines :

# install nix42b
nix-env -iA nixpkgs.cachix
cachix use nix42b
nix-env -if https://gitlab.com/juliendehos/nix42b/- ... ter.tar.gz

of the script

"Cachix (https://www.cachix.org/) makes it easy to manage a personal cache of binary packages. Concretely, it is a cloud service and client software, all based on the Nix package manager. " (excerpt from the page (in french) https://linuxfr.org/news/gestion-de-paq ... me-manager )

Nix42b is not in the cache of binaries available by the command nix-env -iA.
If i unsterstand , the binary is available at cachix.org, on a cache named nix42b (the line "cachix use nix42b" configure nix to use this cache)

Unfortunaly this command leads to an error :

Binary cache 42b doesn't exist or it's private and you need a token: Start by visiting https://app.cachix.org and create a personal/cache auth token.

Then I created a cache and a token at app.cachix.org and obviously this token doesn't work.

Nevertheless the third command :

Code: Select all

        nix-env -if https://gitlab.com/juliendehos/nix42b/-/archive/master/nix42b-master.tar.gz

worked but the binary was compiled.

Now with all the dependencies for the compilation the Nix store occupies more than 7Gb !

(Sorry for my bad English)

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Nix-dialog

Post by Caramel »

To compil Nix42b directly in Easy, I I tried to install GHCup (https://www.haskell.org/ghcup/) for the haskell language.
Message error : Unable to figure out the distribution of the host

I tried with MX Linux . GHCup successfully installed. But no documentation for compil from a git folder. Abort.

Next step : recreate the interface de nix42b with bash, Easy Containers (Files section of the Menu , code : /usr/local/easy-containers/easy-containers ) serving as an inspiration.
Too difficult without documentation.

Try with yad that is fairly well documented with many examples.
Difficult. But after hundreds typing errors and misunderstandings, hours of research, some progress.

The page https://stackoverflow.com/questions/520 ... d-notebook was important by showing how to retrieve a value provided by a tab in a yad notebook window

Somes changes from nix42b :
- Removal of the option "collect-garbage" (the collect-garbage was added in the code after remove or update)
- Nix42b uses the command "nix search" as slow as "nix-env -qaP" for find a package. That command was changed by the binary nix-search (note the dash). The presentation of results is also less good (still needs work)

This is the result : a file script nix-dialog to make executable and place in a folder present in the PATH (by example /usr/bin) with also the binary "nix-search" ("nix-search-linux-amd64" (https://github.com/peterldowns/nix-search-cli) renamed nix-search and made executable)

Code: Select all

#!/bin/bash
#very much inspired by nix42b (https://gitlab.com/juliendehos/nix42b)

function principal_window
{
	> /tmp/nixdialog/listapps
	> /tmp/nixdialog/listinstalled

	nix-env -q | grep -v ^nix- | grep -v ^nss-cacert- > /tmp/nixdialog/listinstalled

	for APP in $(ls $HOME/.nix-profile/bin| grep -v ^nix)
	do
	 cd /root/.nix-profile/share/applications/
	 find . $APP*.desktop -type f
	 if [ $? = 0 ]; then
	  echo $APP >> /tmp/nixdialog/listapps
	 fi
	done # create a list (listapps) of the programs installed by nix that are associated with a .desktop file

	
	yad --plug=$keyyadnix --tabnum=1 --text="Double-click on the name of an application to open it \n" --list --no-headers --column=list < /tmp/nixdialog/listapps --dclick-action="sh -c %s"  > /tmp/nixdialog/Return1 | > /tmp/nixdialog/res1 |

	yad --plug=$keyyadnix --tabnum=2 --text="Enter the name of the package you are looking for and then click on FIND \n \n" --form --field="NAME":CE "" --field="FIND":FBTN 'sh -c " nix-dialog choice "' > /tmp/nixdialog/Return2 | > /tmp/nixdialog/res2 |

	yad --plug=$keyyadnix --tabnum=3 --text="Double-click on the name of the package you want to remove \n" --list --no-headers --column=list < /tmp/nixdialog/listinstalled  --dclick-action='sh -c "nix-env -e %s ; nix-collect-garbage -d "'  > /tmp/nixdialog/Return3 | > /tmp/nixdialog/res3 |

	yad --plug=$keyyadnix --tabnum=4 --text="Warning: Updates are very slow and generally not necessary.\n \n Click on UPDATE DATABASE to fetch information about the most recent set of the available packages, so that the new versions can be downloaded.\n \n Click on UPDATE PACKAGES to update the database and all the packages installed by Nix.\n \n" --form --field="UPDATE DATABASE":FBTN 'sh -c "nix-dialog updatabase"' --form --field="UPDATE PACKAGES":FBTN 'sh -c "nix-dialog uppackages"' > /tmp/nixdialog/Return4 | > /tmp/nixdialog/res4 |

	yad --notebook --title="Nix Package Manager"  --key=$keyyadnix --width=300 --height=400 --tab="Run" --tab="Install" --tab="Remove" --tab="Update" --button=gtk-quit:1 2>/dev/null

}

function choice_window
{
	> /tmp/nixdialog/listresults

	NAME0=$(cat /tmp/nixdialog/Return2)
	NAME1=$(echo "$NAME0" | awk 'BEGIN {FS="|" } { print $1 }')

	if [[ $NAME1 == "" ]]; then
	 yad --title="Nix message" --text="The form field was empty" --form --field="Return to nix-dialog":FBTN 'sh -c "nix-dialog principal $YAD_PID"' --button=gtk-quit:1
	else
	 nix-search -n $NAME1 | awk '{print $1;}' >> /tmp/nixdialog/listresults
	 yad --title="Nix Package Manager" --text="Double-click on the name of a package to install it" --list --no-headers --column=list < /tmp/nixdialog/listresults --dclick-action='sh -c " CHOICE=%s ; nix-dialog install $YAD_PID $CHOICE "' 
	fi
}


# The execution of the script starts here
keyyadnix=123456789 # key used by yad for the notebook window (the principal window)

if [ $# -eq 0 ]; then 
 mkdir -p /tmp/nixdialog
 > /tmp/nixdialog/Return2
 principal_window # launch of the yad notebook window
fi

if [[ $1 == "choice" ]]; then
 for pid in $(ps aux | grep -v grep | grep =$keyyadnix | awk '{print $2}')
 do 
  kill -USR1 $pid
 done # closure of the yad notebook window (the principal window)
 sleep 2 # waiting to make sure /tmp/nixdialog/Return2 is modified by the closure of the yad notebook window
 choice_window # launch of the choice window
fi

if [[ $1 == "install" ]]; then
 kill -USR2 $2 # close the previous yad window (the choice window)
 yad --title="Nix message" --text="installation in progress" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-env -ibA nixpkgs.$3 && kill -USR2 $LASTPID # install the package and close the Nix message ($3=CHOICE)
 nix-dialog # relaunch the program after the installation
fi

if [[ $1 == "principal" ]]; then
 kill -USR2 $2 # close the Nix message
 #kill -USR2 $3 # close the previous yad window (the choice window)
 principal_window
fi

if [[ $1 == "updatabase" ]]; then
 yad --title="Nix message" --text="database update in progress" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-channel --update &&  kill -USR2 $LASTPID # update database and close the Nix message
 
 yad --title="Nix message" --text="freeing up space on the device" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-collect-garbage -d && kill -USR2 $LASTPID
fi

if [[ $1 == "uppackages" ]]; then
 yad --title="Nix message" --text="database update in progress" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-channel --update &&  kill -USR2 $LASTPID # update database and close the Nix message
 
 yad --title="Nix message" --text="packages update in progress" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-env --leq -bu "*" &&  kill -USR2 $LASTPID # option u to upgrade packages 
 #, flag --leq to synchronise packages that don't change version with the release of nixpkgs in the local database
 #, flag -b to prevent building from source if a package is inaccessible

 yad --title= "Nix message" --text="freeing up space on the device" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-collect-garbage -d && sleep 1 && kill -USR2 $LASTPID
fi

Feel free to correct the errors in code or in English.

To fully test you need to have nix installed (directly or in a container)

NB : I don't know how to "internationalize" the script.

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Re: The Nix package manager

Post by Caramel »

Definitive version of the script nix-dialog ( Internationalization with gettext copied from /etc/rc.d/rc.shutdown ) :

EDIT 1: correction line 11 , added / forgot
EDIT 2: deletion of a line of test (it was line 89 at this time)
EDIT 3: the packages that do not provide a program (according to nix-search) are no longer displayed in the choice list to install a package. (By means of many AWK commands)
EDIT 4: slight modification of the text in tab About

Code: Select all

#!/bin/bash
#very much inspired by nix42b (https://gitlab.com/juliendehos/nix42b)

. /usr/bin/gettext.sh # enables use of eval_gettext (several named variables) and ngettext (plurals)
export TEXTDOMAIN=nix-dialog
export OUTPUT_CHARSET=UTF-8

function principal_window
{
	> /tmp/nixdialog/listapps # create a empty file /tmp/nixdialog/listapps
	> /tmp/nixdialog/listinstalled

	nix-env -q | grep -v ^nix- | grep -v ^nss-cacert- > /tmp/nixdialog/listinstalled

	for APP in $(ls $HOME/.nix-profile/bin | grep -v ^nix)
	do
	 cd /$HOME/.nix-profile/share/applications/
	 find . -iname "*$APP*.desktop" > /tmp/nixdialog/resultfind
	 if [ -s /tmp/nixdialog/resultfind ]; then
	  echo $APP >> /tmp/nixdialog/listapps
	 fi
	done # create a list (listapps) of the programs installed by nix that are associated with a .desktop file

	
	yad --plug=$keyyadnix --tabnum=1 --text="$(gettext 'Double-click on the name of an application to open it') \n" --list --no-headers --column=list < /tmp/nixdialog/listapps --dclick-action="sh -c %s"  > /tmp/nixdialog/Return1 | > /tmp/nixdialog/res1 |

	yad --plug=$keyyadnix --tabnum=2 --text="$(gettext 'Enter the name of the package you want to install then click on FIND') \n \n" --form --field="NAME":CE "" --field="$(gettext 'FIND')":FBTN 'sh -c " nix-dialog choice "' > /tmp/nixdialog/Return2 | > /tmp/nixdialog/res2 |

	yad --plug=$keyyadnix --tabnum=3 --text="$(gettext 'Double-click on the name of the package you want to remove') \n" --list --no-headers --column=list < /tmp/nixdialog/listinstalled  --dclick-action='sh -c " CHOICEREMOVE=%s ; echo 2$CHOICEREMOVE >> /root/test ; nix-dialog remove $CHOICEREMOVE "'  > /tmp/nixdialog/Return3 | > /tmp/nixdialog/res3 |

	yad --plug=$keyyadnix --tabnum=4 --text="$(gettext 'Warning: Updates can be very slow.\n \n Click on UPDATE DATABASE to fetch information about the most recent set of the available packages.\n \n Click on UPDATE PACKAGES to update the database and all the packages installed by Nix').\n \n" --form --field="$(gettext 'UPDATE DATABASE')":FBTN 'sh -c "nix-dialog updatabase"' --form --field="$(gettext 'UPDATE PACKAGES')":FBTN 'sh -c "nix-dialog uppackages"' > /tmp/nixdialog/Return4 | > /tmp/nixdialog/res4 |

	yad --plug=$keyyadnix --tabnum=5 --text="$(gettext 'Nix is a set of commands for building, installing, removing or updating software packages on a Linux system.\n\nA large number of applications are available on the site http://cache.nixos.org in the form of packages compatible with Nix.\n\nNix-dialog is an program to install, remove or update these applications.\n\nIt does not have all the options of Nix such as rollbacks or channel management.\n\nThe interface de nix-dialog is based on Nix42b \(https://gitlab.com/juliendehos/nix42b\) ')" > /tmp/nixdialog/Return5 | > /tmp/nixdialog/res5 |

	yad --notebook --window-icon=/nix/nix.png --title="Nix-dialog"  --key=$keyyadnix --width=500 --height=400 --tab="$(gettext 'Run')" --tab="$(gettext 'Install')" --tab="$(gettext 'Remove')" --tab="$(gettext 'Update')" --tab="$(gettext 'About')" --button=gtk-quit:1 2>/dev/null

}

function choice_window
{
	cd /tmp/nixdialog
	echo yes > relaunch # if the user closes the choice windows without to have double-click on an entry, the file relaunch is not empty and nix-dialog restarts

	NAME=$(cat Return2 | awk 'BEGIN {FS="|" } { print $1 }')

	if [[ $NAME == "" ]]; then
	 yad --title="$(gettext 'Nix-dialog message')" --window-icon=/nix/nix.png --text="$(gettext 'No result found')" --form --field="$(gettext 'Return to nix-dialog')":FBTN 'sh -c " > relaunch ; nix-dialog principal $YAD_PID"' --no-buttons
	else
	 nix-search -n $NAME --details > listresults
	 if [ ! -s listresults ]; then # if listresults is empty
	  yad --title="$(gettext 'Nix-dialog message')" --window-icon=/nix/nix.png --text="$(gettext 'No result found')" --form --field="$(gettext 'Return to nix-dialog')":FBTN 'sh -c " > relaunch ; nix-dialog principal $YAD_PID"' --no-buttons
	 else
	  awk 'NR % 6 == 1 {print $1}' listresults > listnames
	  awk 'NR % 6 == 3 {$1=""; print substr($0,2);}' listresults > listprograms0
	  awk 'NF{$0="program123"}1' listprograms0 > listprograms1
	  awk '!NF{$0=">abc>"}1' listprograms1 > listprograms
	  awk 'NR % 6 == 4 {$1=""; print substr($0,2);}' listresults > listdescriptions
	  paste listnames listprograms listdescriptions > fileresults0
	  awk '!/>abc>/' fileresults0 > fileresults1
	  awk '{print $1; $1=""; $2="";print substr($0,3);}' fileresults1 > fileresults
	  if [ ! -s fileresults ]; then
	   yad --title="$(gettext 'Nix-dialog message')" --window-icon=/nix/nix.png --text="$(gettext 'No result found')" --form --field="$(gettext 'Return to nix-dialog')":FBTN 'sh -c " > relaunch ; nix-dialog principal $YAD_PID"' --no-buttons
	  else	  
	   yad --title="Nix-dialog" --window-icon=/nix/nix.png --width=800 --height=400 --text="$(gettext 'Packages matching your search. \n \n Double-click on the name of a package to install it.\n')" --list --column=$(gettext 'Name') --column=$(gettext 'Description') < fileresults --dclick-action='sh -c " > relaunch ; echo %s > choice ; nix-dialog install $YAD_PID "' --no-buttons
      fi
      if [ -s relaunch ]; then
       nix-dialog
      fi      
	 fi
	fi
}


# The execution of the script starts here
keyyadnix=123456 # key used by yad for the notebook window (the principal window)

if [ $# -eq 0 ]; then 
 mkdir -p /tmp/nixdialog
 > /tmp/nixdialog/Return2
 principal_window # launch of the yad notebook window
fi

if [[ $1 == "choice" ]]; then
 for pid in $(ps aux | grep -v grep | grep =$keyyadnix | awk '{print $2}')
 do 
  kill -USR1 $pid
 done # closure of the yad notebook window (the principal window)
 sleep 2 # waiting to make sure /tmp/nixdialog/Return2 is modified by the closure of the yad notebook window
 choice_window # launch of the choice window
fi

if [[ $1 == "install" ]]; then
 kill -USR2 $2 # close the previous yad window (the choice window)
 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettext 'Installation in progress')" --no-buttons &>/dev/null &
 LASTPID=$!
 CHOICE=$(cat choice | awk '{ print $1 }')
 nix-env -ibA nixpkgs.$CHOICE && kill -USR2 $LASTPID # install the package then close the Nix message
 yad --title="$(gettext 'Nix-dialog message')" --window-icon=/nix/nix.png --text="$(gettext 'Search for identical files in the Nix install folder')" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-store --optimise && kill -USR2 $LASTPID # reduces Nix store disk space usage by finding identical files in the store and hard-linking them to each other then close the Nix message
 nix-dialog # relaunch the program after the installation and freeing up space
fi

if [[ $1 == "remove" ]]; then
 for pid in $(ps aux | grep -v grep | grep =$keyyadnix | awk '{print $2}')
 do 
  kill -USR1 $pid
 done # closure of the yad notebook window (the principal window)
 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettext 'Removal in progress')" --no-buttons &
 LASTPID=$!
 nix-env -e $2 && nix-collect-garbage -d && kill -USR2 $LASTPID 
 nix-dialog
fi

if [[ $1 == "principal" ]]; then
 kill -USR2 $2 # close the Nix message
 principal_window
fi

if [[ $1 == "updatabase" ]]; then
 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettext 'Database update in progress')" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-channel --update &&  kill -USR2 $LASTPID # update database and close the Nix message
 
 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettex 'Freeing up space on the device')" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-collect-garbage -d && kill -USR2 $LASTPID
fi

if [[ $1 == "uppackages" ]]; then
 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettext 'Database update in progress')" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-channel --update &&  kill -USR2 $LASTPID # update database and close the Nix message
 
 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettext 'Packages update in progress')" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-env --leq -bu "*" &&  kill -USR2 $LASTPID # option u to upgrade packages 
 #, flag --leq to synchronise packages that don't change version with the release of nixpkgs in the local database
 #, flag -b to prevent building from source if a package is inaccessible

 yad --title="$(gettext 'Nix-dialog message')" --width=400 --window-icon=/nix/nix.png --text="$(gettext 'Freeing up disk space')" --no-buttons &>/dev/null &
 LASTPID=$!
 nix-collect-garbage -d && nix-store --optimise && kill -USR2 $LASTPID
fi

Curiosity with yad :

yad as spot (with su -l or login -f) doesn't work

yad as spot (with run-as-spot) :

capture13009.png
capture13009.png (6.57 KiB) Viewed 2061 times

yad as root :

capture13414.png
capture13414.png (7.03 KiB) Viewed 2061 times
Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

A tool to build an Appimage from a program by means of Nix

Post by Caramel »

Source : https://github.com/ralismark/nix-appimage

Command to create an appimage from a Nix flake (I'm not sure flake is the good term here)

Code: Select all

nix bundle --bundler github:ralismark/nix-appimage nixpkgs#hello

The experimental features must be allowed (NB They are with the Determinate Nix installer)

Need a lot of available space

nixpkgs#hello is the only example provided and there is no explanation.

Tested with nixpkgs#okular; it has worked while when you install okular with nix-env -iA , you must enter nixpkgs.libsForQt5.okular ( the "libsForQt5.okular" is provided by search.nixos.org or nix-search -n)

Instead of nixpkgs#hello you can use a expression as github:nixos/nixpkgs/REV#hello (where REV is a revision number of nixpkgs) for use a specific version of hello

See lazamar.co.uk/nix-versions/ to understand and obtain revision number

Remark 1 :

If you get a main program ... does not exist error, or want to specify a different binary to run, you can instead use the ./bundle script:

$ ./bundle dnsutils /bin/dig # or ./bundle dnsutils dig
$ ./dig-x86_64.AppImage -v
DiG 9.18.14

I'm not understood. But the trick of creating a symlink works ( see https://github.com/ralismark/nix-appimage/issues/7)

Remark 2 :
The AppImage obtained is not internationalized
EDIT To display the programm (provided by the appimage) in the local language, the file locale-archive must exist and LOCALE_ARCHIVE must be setted as /usr/lib/locale/locale-achive (see https://forum.puppylinux.com/viewtopic. ... 509#p93509 above)
In many distributions these conditions must be met by default but not in EasyOS.

EDIT 2:
Remark 3
From the github page nix-appimage :

The produced file isn't a fully conforming AppImage. For example, it's missing the relevant .desktop file and icons -- this doesn't affect the running of bundled apps in any way

Caramel
Posts: 476
Joined: Sun Oct 02, 2022 6:25 pm
Location: France
Has thanked: 100 times
Been thanked: 78 times

Guix, another Nix

Post by Caramel »

Guix(https://guix.gnu.org) is a package manager inspired by Nix (see https://en.wikipedia.org/wiki/GNU_Guix)

For install in EasyOS you must modify the installation script (adduser do not exist in Easy, see https://lists.gnu.org/archive/html/bug- ... 00095.html for the same problem on Alpine Linux)

To download "substitutes" (binaries packages already builded), you need to add the lines

Code: Select all

https		443/tcp				# http protocol over TLS/SSL
https		443/udp				# HTTP/3

in the file /etc/services

I have tried the command guix pack to make a "portable" application with okular. I had to increase the /tmp folder (mount -o remount,size=3G /tmp/ for a size of 3GB for example) for the command to complete and the result is too big (less big than the Appimage build by Nix but the portable app must be unpacked)

To be brief, Guix is simplier than Nix for full use, but for basic use Nix has more options (like nix-appimage)

User avatar
BarryK
Posts: 2692
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 132 times
Been thanked: 738 times

Re: The Nix package manager

Post by BarryK »

Yes, I discovered Guix yesterday, see blog post:

https://bkhome.org/news/202409/guix-wor ... asyos.html

disciple
Posts: 18
Joined: Fri Dec 18, 2020 5:54 am

Re: A tool to build an Appimage from a program by means of Nix

Post by disciple »

Caramel wrote: Sat Sep 23, 2023 9:34 am

Source : https://github.com/ralismark/nix-appimage

Command to create an appimage from a Nix flake (I'm not sure flake is the good term here)

Code: Select all

nix bundle --bundler github:ralismark/nix-appimage nixpkgs#hello

Apparently AppImages potentially have dependency issues, but this tool can create AppImages which use musl to avoid those problems - see https://discourse.nixos.org/t/nix-bundl ... ns/22827/2

disciple
Posts: 18
Joined: Fri Dec 18, 2020 5:54 am

Re: The Nix package manager

Post by disciple »

I've been setting up a Nixos system recently, after many years running Puppy (only machine in regular use here for the last few years runs Fatdog, but it just gets used to play stuff on the TV), several years of Arch, and only real experience of other distros being via WSL.
I was attracted by the fact it has the most massive and most up-to-date package repository.
Arch has a lot of packages when you include the AUR, but most of those have to be built from source, and they are often out-of-date and possibly unmaintained and/or broken.
On Nixos you don't typically need to build anything from source, even if you install from the (quite small) NUR.

I assumed the best experience would be running Nixos rather than using nix in another distro, but the problem is it's more like building your own distro. Even if you install a desktop environment like KDE it isn't really complete, with a full set of sane defaults - there are all sorts of little things I had to find out how to set up, and because you have to do things the Nix way, it can be very hard to find out. It feels like the opposite of the Arch Linux "KISS", and I often end up back using the Arch wiki to get me on the path to finding out how to do something.

What I do really like about the declarative approach in Nix is that everything is in one place, and I can comment everything - todos, why I've installed something, what dependencies it uses, what else I've tried or might want to try, etc.

disciple
Posts: 18
Joined: Fri Dec 18, 2020 5:54 am

Re: The Nix package manager

Post by disciple »

What I do really like about the declarative approach in Nix is that everything is in one place, and I can comment everything - todos, why I've installed something, what dependencies it uses, what else I've tried or might want to try, etc.

Of course, I do also miss the imperative approach of just saying "install this", and more importantly, being shown all the dependencies that will be installed and how big they are.

Post Reply

Return to “EasyOS”