From c34f93a1f83d297da8c3cb8737f6d3e4b40d2577 Mon Sep 17 00:00:00 2001 From: Liassica <115422798+Liassica@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:37:27 -0500 Subject: [PATCH] feat: nixify --- .gitignore | 2 + LICENSE | 21 ++++ README.md | 238 ++++------------------------------------ flake.lock | 27 +++++ flake.nix | 18 +++ grub2/grub.cfg | 2 +- nix/package/default.nix | 110 +++++++++++++++++++ 7 files changed, 198 insertions(+), 220 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/package/default.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..750baeb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +result-* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a69c511 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Liassica + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 0ae6838..89c019f 100644 --- a/README.md +++ b/README.md @@ -1,230 +1,30 @@ -GRUB2 Live ISO Multiboot -======================== +# glim-flake -https://github.com/thias/glim | http://glee.thias.es/GLIM +A flake for [glim](https://github.com/thias/glim) with a couple of customizations. +## Overview -Overview --------- +I've Nixified the upstream glim script, so it should work out of the box on systems with Nix. I've also added a few customizations like enabling Secure Boot support and switching the default theme out for [Catppuccin Frappe](https://github.com/catppuccin/grub). -GLIM is a set of grub configuration files to turn a simple VFAT formatted USB -memory stick with many GNU/Linux distribution ISO images into a neat device -from which many different Live environments can be used. +## Installation -Advantages over extracting files or using special Live USB creation tools : +Follow the upstream instructions for setting up your USB device. - * A single USB memory can hold all Live environments (the limit is its size) - * ISO images stay available to burn real CDs or DVDs - * ISO images are quick to manipulate (vs. hundreds+ files) +Then, install glim to your USB by running `nix run github:Liassica/glim-flake`. You can override the theme by adding this repo as a flake input and overriding the 'theme' input. -Disadvantages : +E.g, to use the Breeze GRUB theme: - * There is no persistence overlay for distributions which normally support it - * Setting up isn't as easy as a simple cat from the ISO image to a block device - -My experience has been that the safest filesystem to use is FAT32 -(surprisingly!), though it will mean that ISO images greater than 4GB won't be -supported. Other filesystems supported by GRUB2 also work, such as ext3/ext4, -NTFS and exFAT, but the boot of the distributions must also support it, which -isn't the case for many with NTFS (Ubuntu does, Fedora doesn't) and exFAT -(Ubuntu doesn't, Fedora does). So FAT32 stays the safe bet. - - -Screenshots ------------ - -![Main Menu](https://github.com/thias/glim/raw/master/screenshots/GLIM-3.0-shot1.png) -![Ubuntu Submenu](https://github.com/thias/glim/raw/master/screenshots/GLIM-3.0-shot2.png) - - -Installation ------------- - -Once you have your USB memory with a single partition formatted as FAT32 with -the filesystem label 'GLIM', mount it, clone this git repository and just run -(as a normal user) : - - ./glim.sh - -Once finished, you may change the filesystem label to anything you like. - -The supported `boot/iso/` sub-directories (in alphabetical order) are : - -[//]: # (distro-list-start) - -* [`almalinux`](https://almalinux.org/) - _Live Media only_ -* [`antix`](https://antixlinux.com/) -* [`arch`](https://archlinux.org/) -* [`artix`](https://artixlinux.org/) -* [`bodhi`](https://www.bodhilinux.com/) -* [`calculate`](https://wiki.calculate-linux.org/desktop) -* ~~[`centos`](https://www.centos.org/)~~ - _Live was discontinued_ -* [`clonezilla`](https://clonezilla.org/) -* [`debian`](https://www.debian.org/CD/live/) - _live & `mini.iso`_ -* [`elementary`](https://elementary.io/) -* [`fedora`](https://fedoraproject.org/) -* [`finnix`](https://www.finnix.org/) -* [`gentoo`](https://www.gentoo.org/) -* [`gparted`](https://gparted.org/) -* [`grml`](https://grml.org/) -* [`ipxe`](https://ipxe.org/) - _.iso or .efi_ -* [`kali`](https://www.kali.org/) -* [`kubuntu`](https://kubuntu.org/) -* [`libreelec`](https://libreelec.tv/) -* [`linuxmint`](https://linuxmint.com/) -* [`lubuntu`](https://lubuntu.me/) -* [`manjaro`](https://manjaro.org/) -* [`memtest`](https://memtest.org/) - _Only .bin/.efi, not .iso_ -* [`mxlinux`](https://mxlinux.org/) -* [`netrunner`](https://www.netrunner.com/) -* [`openbsd`](https://www.openbsd.org/) -* [`opensuse`](https://www.opensuse.org/) - _Live from Alternative Downloads only_ -* [`peppermint`](https://peppermintos.com/) -* [`popos`](https://pop.system76.com/) -* [`porteus`](http://www.porteus.org/) -* [`rhel`](https://www.redhat.com/rhel) - _Installation only_ -* [`rockylinux`](https://rockylinux.org/) -* [`slitaz`](https://slitaz.org/) -* [`supergrub2disk`](https://www.supergrubdisk.org/) -* [`systemrescue`](https://www.system-rescue.org/) -* [`tails`](https://tails.net/) -* [`ubuntubudgie`](https://ubuntubudgie.org/) -* [`ubuntu`](https://ubuntu.com/) -* [`void`](https://voidlinux.org/) -* [`xubuntu`](https://xubuntu.org/) -* [`zorinos`](https://zorin.com/os/) - -[//]: # (distro-list-end) - -Any unpopulated directory will have the matching boot menu entry automatically -disabled, so to skip any distribution, just don't copy any files into it. - -Download the right ISO image(s) to the matching directory. If you require -boot parameter tweaks, edit the appropriate `boot/grub2/inc-*.cfg` file. - -Items order in the menu ------------- - -Menu items for a distro are ordered by modification time of the iso files -starting from the most recent ones. If some iso files have the same mtime, their -menu items are ordered alphabetically. - -Here is a generic idea how to keep it nicely ordered when you have multiple -releases of some distro: - -- touch your **release** iso files with the release date -- touch your **point release** iso files with the original release date plus a - day per point. This is a way to ensure point releases never pop above the next - release like Debian 10.13.0 (released 10 Sep 2022) would still be below Debian - 11.0.0 (released 14 August 2021) -- in case there are multiple flavours of some iso but the version is the same, - touch all of them with the same date for the whole group to be ordered - alphabetically - -Sample ordered menu: - -| | iso mtime | -|------------------------------------|-------------------------| -| Debian Live 12.0.0 amd64 standard | 10 June 2023 | -| Debian Live 11.7.0 amd64 gnome | 14 August 2021 + 7 days | -| Debian Live 11.7.0 amd64 kde | 14 August 2021 + 7 days | -| Debian Live 11.7.0 amd64 standard | 14 August 2021 + 7 days | -| Debian Live 11.0.0 amd64 gnome | 14 August 2021 | -| Debian Live 11.0.0 amd64 kde | 14 August 2021 | -| Debian Live 11.0.0 amd64 standard | 14 August 2021 | -| Debian Live 10.13.0 amd64 standard | 6 July 2019 + 13 days | -| Debian Live 9.13.0 amd64 standard | 17 June 2017 + 13 days | - -Special Cases -------------- - -### iPXE - -The `.iso` files don't work when booting using EFI, you simply need to use -`.efi` files instead. - -### LibreELEC - -LibreELEC isn't provided as ISO images, nor is it able to find the `KERNEL` and -`SYSTEM` files it needs anywhere else than at the root of a filesystem. -But it's useful to enable booting the installer by just copying both -files to the root of the USB memory stick. -Live booting is also supported, and the first launch will create a 512MB file -as /STORAGE. - -### Memtest86+ - -The `.iso` file doesn't work. Use either the `.bin` or the `.efi` depending on -the boot mode used. - -### Ubuntu - -Recent Ubuntu desktop iso images bundle multiple versions on the Nvidia -driver. With that, the images are over 4GB, the FAT32 max file size. For example -`ubuntu-20.04.6-desktop-amd64.iso` is 4.1GB, `ubuntu-22.04.2-desktop-amd64.iso` -is 4.6GB. The driver is not required in a live system, it can be removed to make -an image fit into 4GB. For example, with 22.04.2 image in the current dir: - -``` -mkdir slim -iso=ubuntu-22.04.2-desktop-amd64.iso - -xorriso -indev "$iso" -outdev slim/"$iso" \ - -boot_image any replay -rm_r /pool/restricted/{l,n} -- +```nix +{ pkgs, glim, ...}: +{ + environment.systemPackages = [ + glim.packages.x86_64-linux.glim.override { + theme = "${pkgs.kdePackages.breeze-grub}/grub/themes/breeze"; + }; + ]; +} ``` -Now you can copy `slim/ubuntu-22.04.2-desktop-amd64.iso` to your FAT32 formatted -GLIM USB stick. - -Some Ubuntu flavours also bundle the Nvidia driver (like Kubuntu), some don't -(like Xubuntu). The same trick can be used with the former. - - -Testing -------- - -With KVM it should "just work". The `/dev/sdx` device should be configured as -an IDE or SATA disk (for some reason, as USB disk didn't work for me on Fedora -17), that way you can easily and quickly test changes. -Make sure you unmount the disk from the host OS before you start the KVM -virtual machine that uses it. -For UEFI testing, you'll need to use one of the `/usr/share/edk2/ovmf/*.fd` -firmwares. - - -Troubleshooting ---------------- - -If you have any problem to boot, for instance stuck at the GRUB prompt before -the menu, try re-installing. -If you have other exotic GRUB errors, such as garbage text read instead of the -configuration directives, try re-formatting your USB memory from scratch. -I've seen weird things happen... - - -Contributing ------------- - -If you find GLIM useful but the configuration of the OS you require is missing -or simply outdated, please feel free to contribute! What you will need is to -create a GitHub pull request which includes : - * All changes properly and fully tested. - * New entries added similarly to the existing ones : - * In alphabetical order. - * With all possible variants supported (i.e. not just the one spin you want). - * An original icon of high quality, and a shrunk 24x24 png version. Using - `convert -size 24x24 -background 'rgba(0,0,0,0)' original.svg small.png` - may work. - * An updated supported directories list in this README file. - - ---- -Copyleft 2012-2023 Matthias Saou http://matthias.saou.eu/ - -All configuration files included are public domain. Do what you want with them. -The invader logo was made by me, so unless the exact shape is covered by -copyright somewhere, do what you want with it. -The background is "Wallpaper grey" © 2008 payalnic (DeviantArt) -The `ascii.pf2` font comes from GRUB, which is GPLv3+ licensed. For more -details as well as the source code, see http://www.gnu.org/software/grub/ +## License +MIT, with the exception of some theme files. See the upstream repository's license for details. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5e857ba --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1723637854, + "narHash": "sha256-med8+5DSWa2UnOqtdICndjDAEjxr5D7zaIiK4pn0Q7c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c3aa7b8938b17aebd2deecf7be0636000d62a2b9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..dcbda1f --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages.${system} = { + glim = pkgs.callPackage ./nix/package { + theme = (pkgs.catppuccin-grub.override { flavor = "frappe"; }).outPath; + }; + default = self.packages.${system}.glim; + }; + }; +} diff --git a/grub2/grub.cfg b/grub2/grub.cfg index a434e20..c3ec631 100644 --- a/grub2/grub.cfg +++ b/grub2/grub.cfg @@ -20,7 +20,7 @@ terminal_output gfxterm loadfont unicode insmod png -set theme=${prefix}/themes/invader/theme.txt +set theme=${prefix}/themes/theme/theme.txt set isopath=/boot/iso probe --set rootuuid --fs-uuid $root diff --git a/nix/package/default.nix b/nix/package/default.nix new file mode 100644 index 0000000..2b07850 --- /dev/null +++ b/nix/package/default.nix @@ -0,0 +1,110 @@ +{ + lib, + util-linux, + coreutils-full, + grub2_efi, + rsync, + writeShellScriptBin, + theme, +}: +let + cfg = ../../grub2; +in +writeShellScriptBin "glim" '' + export PATH=${ + lib.makeBinPath [ + util-linux + coreutils-full + grub2_efi + rsync + ] + }:$PATH + + # Check that we are *NOT* running as root + if [[ `id -u` -eq 0 ]]; then + echo "ERROR: Don't run as root, use a user with full sudo access." + exit 1 + fi + + # Find GLIM device (use the first if multiple found, you've asked for trouble!) + USBDEV1=`blkid -L GLIM | head -n 1` + + # Sanity check : we found one partition to use with matching label + if [[ -z "$USBDEV1" ]]; then + echo "ERROR: no partition found with label 'GLIM', please create one." + exit 1 + fi + echo "Found partition with label 'GLIM' : ''${USBDEV1}" + + # Sanity check : our partition is the first and only one on the block device + USBDEV=''${USBDEV1%1} + if [[ ! -b "$USBDEV" ]]; then + echo "ERROR: ''${USBDEV} block device not found." + exit 1 + fi + echo "Found block device where to install GRUB2 : ''${USBDEV}" + if [[ `ls -1 ''${USBDEV}* | wc -l` -ne 2 ]]; then + echo "ERROR: ''${USBDEV1} isn't the only partition on ''${USBDEV}" + exit 1 + fi + + # Sanity check : our partition is mounted + if ! grep -q -w ''${USBDEV1} /proc/mounts; then + echo "ERROR: ''${USBDEV1} isn't mounted" + exit 1 + fi + USBMNT=`grep -w ''${USBDEV1} /proc/mounts | cut -d ' ' -f 2` + if [[ -z "$USBMNT" ]]; then + echo "ERROR: Couldn't find mount point for ''${USBDEV1}" + exit 1 + fi + echo "Found mount point for filesystem : ''${USBMNT}" + + # Sanity check : human will read the info and confirm + read -n 1 -s -p "Ready to install GLIM. Continue? (Y/n) " PROCEED + if [[ "$PROCEED" == "n" ]]; then + echo "n" + exit 2 + else + echo "y" + fi + + # Install GRUB2 + GRUB_TARGET="--target=x86_64-efi --efi-directory=''${USBMNT} --removable --modules='tpm' --disable-shim-lock" + echo "Running grub-install ''${GRUB_TARGET} --boot-directory=''${USBMNT}/boot (with sudo)..." + sudo grub-install ''${GRUB_TARGET} --boot-directory=''${USBMNT}/boot ''${USBDEV} + if [[ $? -ne 0 ]]; then + echo "ERROR: grub-install returned with an error exit status." + exit 1 + fi + + # Copy GRUB2 configuration + echo "Running rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts ${cfg}/ ''${USBMNT}/boot/grub ..." + rsync -rt --delete --exclude=i386-pc --exclude=x86_64-efi --exclude=fonts ${cfg}/ ''${USBMNT}/boot/grub + if [[ $? -ne 0 ]]; then + echo "ERROR: the rsync copy returned with an error exit status." + exit 1 + fi + + # Set up theme + echo "Copying theme..." + rsync -rt --delete ${theme} ''${USBMNT}/boot/grub/themes/theme + if [[ $? -ne 0 ]]; then + echo "ERROR: the rsync copy returned with an error exit status." + exit 1 + fi + + # Be nice and pre-create the directory, and mention it + [[ -d ''${USBMNT}/boot/iso ]] || mkdir ''${USBMNT}/boot/iso + echo "GLIM installed! Time to populate the boot/iso/ sub-directories." + + # Now also pre-create all supported sub-directories since empty are ignored + args=( + -E -n + '/\(distro-list-start\)/,/\(distro-list-end\)/{s,^\* \[`([a-z0-9]+)`\].*$,\1,p}' + ) + + for DIR in $(sed "''${args[@]}" "$(dirname "$0")"/README.md); do + [[ -d ''${USBMNT}/boot/iso/''${DIR} ]] || mkdir ''${USBMNT}/boot/iso/''${DIR} + done +''