NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.7k stars 13.15k forks source link

Snap support #30336

Open alesya-h opened 6 years ago

alesya-h commented 6 years ago

Currently, there's no way to either repackage or directly install software packaged in a snap and flatpak formats. Because apps packaged in this formats can run unmodified on all major Linux distributions, their popularity grows, and we seem to be missing out.

Flatpak apps can be installed on Alpine, Arch, Debian, Endless OS, Fedora, Gentoo, Mageia, openSUSE, Solus, and Ubuntu.

Snap apps can be installed on Arch, Debian, Fedora, Gentoo, Mint, Manjaro, OpenEmbedded/Yocto, openSUSE, OpenWrt, Solus, and Ubuntu.

Ideally, I'd wish we can do something like this

buildFlatpakPackage {
  src = fetchUrl {
    url = "https://git.gnome.org/browse/gnome-apps-nightly/plain/gnome-builder.flatpakref?h=stable
    sha="..."
  }
}
matthewbauer commented 6 years ago

We should be able to get flatpak and snap runtimes packaged and have NixOS modules I think. They don’t require anything.

On the packaging side it should be possible but maybe not as straightforward as you think. Nix packages are not easily relocatable- it needs to be installed in /nix/store/... and you can’t just move it to another directory. We’d need either provide our own chroot or see if snap/flatpak can provide one for us so that the paths still work in the package. I wonder if it’s easier to just tell users to install Nix and then install from the binary cache? The user friendliness isn’t quite there though.

vyp commented 6 years ago

It seems like snap and flatpak are very similar to nix/nixpkgs in their goals? I wonder what is the point of supporting snap and flatpak when you could just package the applications for nix itself? Are these containerization technologies? Because if not, my worry for the long run is eventually having reproducibility issues by letting a 'middle man' build a package, and therefore potentially being a waste of time to support anyway? 😬

jpotier commented 6 years ago

@vyp A way to answer your concern is: what can you do in the short term, when a very complicated software is available as a flatpak/snap but not in NixOS? (I'm thinking of you steam) Being able to pull a flatpak can help.

alesya-h commented 6 years ago

@vyp their goals are quite different. Their goal is to create distribution-agnostic packages, so "package the applications for nix itself" is the opposite of that. Also, unlike nix-packaged apps, snap and flatpak apps are sandboxed (chroot/cgroups/namespaces). As far as I understand snap/flatpak apps are designed to not be used as dependencies for other software - apps are self-contained, standalone and independent. In that regard, reproducibility is not more an issue than with other nix packages that fetch/use proprietary binary blobs.

vyp commented 6 years ago

@alesguzik That makes sense, thank you. My my first thoughts looking at their websites were that nix can already seem to do what they advertise, so I wasn't seeing much advantages, but I see now that the way nix would handle these, and a lot of the potential problems I was thinking about, could be sort of analogous to nix fetching binary applications (e.g. a lot of the unfree packages in nixpkgs), I think.

@jpotier Yes of course if flatpak/snap has a package for something that nix doesn't, it has an immediate advantage. The same could be theoretically true the other way, so the argument just comes down to what is currently available. But my point was less practical and more theoretically, what if these package formats don't work well with nix, and then in the end we would have been better off just packaging it with nix, i.e. long term solutions. Currently nix (and nixpkgs) does have a problem with manpower imo (not to say the current team isn't doing great, they are!), and will probably do so for a while at least, so nonetheless it's still a good point you bring up. :+1:

etu commented 6 years ago

@vyp One of the advantages that snap could bring is that for example Solus have done extensive work on making Steam work well on their OS. And now they started building a base-snap of Solus to be able to ship a Steam-snap that depends on the Solus base snap. And then all the work that Solus have done would benefit other distros. For sure it's possible to reproduce all the work, but I guess that that's a lot of work...

abbradar commented 6 years ago

Actually we can run any application which expects FHS-based hierarchy in FHS chrootenvs. Our Steam is implemented in this way and it's fairly straightforward. We also have steam-run and steam-run-native which allow you to easily run applications in FHS-like environment with libraries from Steam Runtime available. I imagine that out of the box or with little tweaks we can get vanilla Snap/Flatpak applications running -- depends on how exactly are they installed and what do they expect (I don't know much about them).

lukateras commented 6 years ago

Progress on flatpak is now tracked in https://github.com/NixOS/nixpkgs/issues/32807.

xeji commented 6 years ago

Flatpak support was just merged in #33371

benley commented 5 years ago

Has anyone started work on supporting Snap? I've run into a few things that more-or-less require it, like https://anbox.io/ so I'm finding myself interested again.

(aside: there is also progress on anbox itself in #42076)

matthew-piziak commented 5 years ago

Snap support is also required to run the Aether client.

tbenst commented 4 years ago

I just packaged Tusk.AppImage, and it was trivial (https://github.com/NixOS/nixpkgs/pull/66710). It seems like we could implement buildAppImagePackage now? Only need url and sha to fill in the derivation template from pull request that is also used by ~5 other AppImage packages. Seems needless to create a new nix pkg for each.

freeman42x commented 4 years ago

Anyone working on implementing snap support under Nix / NixOS?

saksmt commented 4 years ago

Any progress on snap? It becomes more and more important since there are packages only available in snap and they are pretty much important: microk8s to start with...

mkg20001 commented 4 years ago

IMO:

I think the end goal shouldn't be to be able to re-package software from snap to nix (because we'd be better off just using the standard nix building procedure, so pulling from a snap would be no more different than extracting files from a .deb and replicating the build process because everything would need a rebuild anways to account for the /nix/store prefix), but instead the goal should be to provide a snapd/flaptpak daemon that the user can use to pull apps from the stores.

If it becomes an issue that snapd/flatpak is too deterministic for the user, then re-packaging properly for nix is the only good option, everything else just would be a hack.

pbogdan commented 4 years ago

From when I last checked one big issue with snap is that it assumes to have a total control over the system it's running on including but probably not limited to ability to manage systemd services, dbus services, global configuration files under /etc which would make it very difficult to integrate with NixOS using the stock snapd daemon.

saksmt commented 4 years ago

From user point of view it is irrelevant if it is hack or not, it should just work and that's it. But from dev point of view we probably should just be able to parse snap package and translate it as nix one to be able to control whats going on

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
tbenst commented 4 years ago

Still important to me

ptman commented 4 years ago

Isn't flatpak supported? So this should be retitled to only be about snap.

tbenst commented 4 years ago

@ptman yes you are right

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

benley commented 3 years ago

Not stale.

auscyber commented 3 years ago

Not Stale. This is very useful As some apps arent on nixpkgs but are on Snap and are proprietary

nixos-discourse commented 3 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/installing-a-snap-package/11468/3

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

pio2398 commented 2 years ago

Not Stale.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

pbogdan commented 2 years ago

Not stale.

zoedsoupe commented 2 years ago

there are any started work/idea to solve snap/flatpak issue? i know we can install flatpak but seems to be more intuitity to build declaritevely with nix

io12 commented 1 year ago

there are any started work/idea to solve snap/flatpak issue? i know we can install flatpak but seems to be more intuitity to build declaritevely with nix

I started working on this recently and there are a few issues.

  1. Building a Flatpak app and all its runtimes from scratch is surprisingly hard, so it's probably worth starting with prebuilt binaries from Flathub.
  2. Flatpak doesn't have the equivalent of PATH (or if it does, I can't find it). It installs everything into the same directory (by default /var/lib/flatpak) and you can change the default by setting an environment variable, but you can't have multiple directories used at once. I have a wrapper script around Flatpak that emulates PATH-like behavior with OverlayFS, but there might be a better solution.
  3. I don't know of an easy way to get hashes for Nix's fixed-output derivations. My understanding is that Flathub is an OSTree repo where each branch is a runtime or app, and you download apps/runtimes by fetching to your local OSTree repo in /var/lib/flatpak/repo. Unfortunately it seems harder than downloading a tarball where you can just get the sha256 from the website. The only way I came up with is to download every app and runtime and hash each one, but Flathub stores lots of data and that takes a long time (my Python script seems like it will finish in about a week at the current rate).
  4. Every file in a Flatpak app/runtime is hard linked to a content-addressed object store in the OSTree repo. This is how flatpak deduplicates files. If two files in separate apps/runtimes have the same hash, they will both be hard linked to the same file in the OSTree repo. My current OverlayFS hack doesn't do any deduplication. One idea is to replace OSTree's content-addressed file store /var/lib/flatpak/repo/objects with Nix's /nix/store. Every file in every app/runtime would have its own Nix store entry and be hard linked to files in other entries for the runtime and app file trees. This might be hard to implement but possible I think?
Code so far (very WIP)

```nix let pkgs = import { }; inherit (pkgs) stdenv fetchurl python39Packages bubblewrap fuse ostree git lzip writeShellApplication runCommand flatpak cacert writeText stdenvNoCC writeShellScript mount util-linux lib; buildbox-casd = stdenv.mkDerivation { pname = "buildbox-casd"; version = "x86_64-linux-20191104-598100dd"; src = fetchurl { url = "https://buildbox-casd-binaries.nyc3.cdn.digitaloceanspaces.com/buildbox-casd-x86_64-linux-20191104-598100dd.tar.xz"; sha256 = "fa9b46ec50b6abb6177c53d78b0ebe4d2544f1131c2d962f13685fd736d34f09"; }; sourceRoot = "."; installPhase = '' mkdir -p $out/bin cp buildbox-casd $out/bin ''; }; buildstream = python39Packages.buildPythonPackage rec { pname = "buildstream"; version = "1.6.6"; src = fetchurl { url = "https://github.com/apache/buildstream/archive/refs/tags/${version}.tar.gz"; sha256 = "sha256-bfQUHWBRm/3otPEAZVO5GARUVQ9HCqfhmKHrkiOYu4k="; }; doCheck = false; nativeBuildInputs = [ bubblewrap ]; propagatedBuildInputs = [ bubblewrap ] ++ (with python39Packages; [ pytest-runner click pluginbase ujson grpcio jinja2 ruamel-yaml psutil setuptools ]); postPatch = '' substituteInPlace requirements/requirements.in \ --replace 'ruamel.yaml < 0.17' 'ruamel.yaml' ''; preFixup = '' wrapProgram $out/bin/bst \ --prefix LD_LIBRARY_PATH ":" "${fuse}/lib" ''; }; buildstream-external = python39Packages.buildPythonPackage rec { pname = "BuildStream-external"; version = "0.28.1"; src = python39Packages.fetchPypi { inherit pname version; sha256 = "sha256-sUf97hvPeZaRlVBiOEGPaxUdYXrKUrjMUSz8CDHgNzQ="; }; doCheck = false; nativeBuildInputs = with python39Packages; [ setuptools_scm pytest-runner requests ]; propagatedBuildInputs = with python39Packages; [ toml ]; }; freedesktop-sdk = stdenv.mkDerivation rec { pname = "freedesktop-sdk"; version = "21.08.14"; src = fetchurl { url = "https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/archive/freedesktop-sdk-${version}/freedesktop-sdk-freedesktop-sdk-${version}.tar.gz"; sha256 = "sha256-uCe3pJ0DVdZgjL0MOL8iDCwCKdwz3Wp1SKvfn9DBbaU="; }; nativeBuildInputs = [ buildstream buildstream-external ostree git lzip ]; }; wrappedFlatpakScriptRoot = writeShellScript "wrapped-flatpak-script-root" '' set -eu tmp=$(mktemp -d) mnt=$tmp/mnt out=$tmp/out scratch=$tmp/scratch mkdir $mnt $out $scratch if [ -n "''${NIX_FLATPAK_PATH:-}" ] && [ -n "''${NIX_FLATPAK_OUT:-}" ] then ${util-linux}/bin/mount -t overlay overlay \ -o lowerdir="$NIX_FLATPAK_PATH",upperdir="$out",workdir="$scratch" \ "$mnt" elif [ -n "''${NIX_FLATPAK_PATH:-}" ] && [ -z "''${NIX_FLATPAK_OUT:-}" ] then if grep --silent ":" <<< "$NIX_FLATPAK_PATH" then ${util-linux}/bin/mount -t overlay overlay -o lowerdir="$NIX_FLATPAK_PATH" "$mnt" else ${util-linux}/bin/mount --bind $NIX_FLATPAK_PATH $mnt fi elif [ -z "''${NIX_FLATPAK_PATH:-}" ] && [ -n "''${NIX_FLATPAK_OUT:-}" ] then ${util-linux}/bin/mount --bind $out $mnt fi cmd="$1" shift FLATPAK_SYSTEM_DIR=/dev/null FLATPAK_USER_DIR=$mnt \ ${flatpak}/bin/flatpak "$cmd" --user "$@" ${util-linux}/bin/umount --quiet $mnt || true if [ -n "''${NIX_FLATPAK_OUT:-}" ] then mkdir -p $NIX_FLATPAK_OUT cp -r $out/* "$NIX_FLATPAK_OUT" fi rm -rf "$tmp" ''; wrappedFlatpakScript = writeShellScript "wrapped-flatpak-script" '' ${util-linux}/bin/unshare -rm ${wrappedFlatpakScriptRoot} "$@" ''; wrappedFlatpak = stdenvNoCC.mkDerivation { name = "wrapped-flatpak"; setupHook = writeText "wrapped-flatpak-setup-hook" '' addNixFlatpakPath () { addToSearchPath NIX_FLATPAK_PATH "$1/flatpak" } addEnvHooks "$hostOffset" addNixFlatpakPath addEnvHooks "$targetOffset" addNixFlatpakPath ''; dontUnpack = true; dontPatch = true; dontConfigure = true; dontBuild = true; installPhase = '' mkdir -p $out/bin cp ${wrappedFlatpakScript} $out/bin/wrapped-flatpak ''; }; flathubRef = fetchurl { url = "https://flathub.org/repo/flathub.flatpakrepo"; hash = "sha256-M3HdJQ5h2eFjNjAHP+/aFTzUQm9y9K+gwzc64uj+oDo="; }; # flathub = runCommand "flathub" { # src = flathubRef; # nativeBuildInputs = [ wrappedFlatpak cacert ]; # outputHashMode = "recursive"; # outputHash = "sha256-Yg6nULmySnFtYFTnOqS8EjiFZzj08VHsolg4oFjXSSU="; # } '' # FLATPAK_USER_DIR=$out/flatpak wrapped-flatpak remote-add --no-use-for-deps flathub $src # ''; getFromFlathub = { kind ? "app", id, arch ? "x86_64", branch ? "stable", runtime ? null, commit, hash }: assert lib.assertOneOf "kind" kind ["app" "runtime"]; let isApp = kind == "app"; in stdenvNoCC.mkDerivation rec { name = "flathub-${kind}-${id}-${arch}-${branch}"; propagatedBuildInputs = [ wrappedFlatpak ] ++ lib.optional isApp runtime; data = runCommand "${name}-data" { nativeBuildInputs = [ wrappedFlatpak cacert ] ++ lib.optional isApp runtime; outputHashMode = "recursive"; outputHash = hash; } (let ref = "${kind}/${id}/${arch}/${branch}"; in '' tmp=$(mktemp -d) flathub=$tmp/flathub latest=$tmp/latest mkdir $flathub $latest NIX_FLATPAK_OUT=$flathub wrapped-flatpak remote-add flathub ${flathubRef} NIX_FLATPAK_PATH=$flathub NIX_FLATPAK_OUT=$latest \ wrapped-flatpak install --noninteractive flathub ${ref} NIX_FLATPAK_PATH=$latest:$flathub NIX_FLATPAK_OUT=$out \ wrapped-flatpak upgrade --noninteractive --commit=${commit} ${ref} rm -rf $tmp chmod --recursive 755 $out/repo rm -rf $out/repo ${lib.optionalString isApp "rm -rf $out/runtime"} ''); dontUnpack = true; dontPatch = true; dontConfigure = true; dontBuild = true; installPhase = '' mkdir $out cp -r $data $out/flatpak ''; dontStrip = true; dontMoveSbin = true; dontPatchELF = true; dontPatchShebangs = true; dontPruneLibtoolFiles = true; forceShare = [ ]; }; flathub = map (attrs: getFromFlathub (attrs // { hash = "sha256-8kClhHDeMxVuLB9pTlqJ0W1azvfOc8NDuwMXE3ilfu8="; })) (lib.importJSON ./generated.json); flathub-org-kde-platform = getFromFlathub { id = "org.kde.Platform"; branch = "5.15-21.08"; commit = "3c43f9d549f9296bdbde365db039e4c8d6dff8c5fd6ff189385de176ac5cfd2e"; hash = "sha256-8kClhHDeMxVuLB9pTlqJ0W1azvfOc8NDuwMXE3ilfu8="; }; flathub-org-flatpak-qtdemo = getFromFlathub { id = "org.flatpak.qtdemo"; runtime = flathub-org-kde-platform; commit = "35ca03c3a7d951314f9e877044db554424bc803206e95c0b77a316e36aafc3d3"; hash = "sha256-yQZa/f3BvNp/VOa3kCmt7kmTIhyqR2Zk78sqFIzU6ow="; }; in builtins.head flathub ``` ```python import tempfile import subprocess import os import json import shutil import pathlib from tqdm import tqdm import gi gi.require_version("Flatpak", "1.0") from gi.repository import Flatpak, GLib GENERATED_PATH = "generated.json" def setup_env(): os.environ["FLATPAK_SYSTEM_DIR"] = "/dev/null" os.environ["FLATPAK_USER_DIR"] = tempfile.TemporaryDirectory().name def add_flathub(): subprocess.run( [ "flatpak", "remote-add", "--user", "flathub", "https://flathub.org/repo/flathub.flatpakrepo", ] ) def get_ref_metadata(ref): key_file = GLib.KeyFile() key_file.load_from_bytes(ref.get_metadata(), GLib.KeyFileFlags.NONE) return key_file def get_sha256(ref, info): subprocess.run( [ "flatpak", "install", "--user", "--noninteractive", "flathub", ref, ] ) subprocess.run( [ "flatpak", "upgrade", "--user", "--noninteractive", "--commit", info["commit"], ref, ] ) dir = pathlib.Path(os.environ["FLATPAK_USER_DIR"]) shutil.rmtree(dir / "repo") if Flatpak.Ref.parse(ref).get_kind() == Flatpak.RefKind.APP: shutil.rmtree(dir / "runtime") sha256 = subprocess.run( ["nix-hash", "--type", "sha256", dir], stdout=subprocess.PIPE ).stdout.decode("utf-8") shutil.rmtree(dir) add_flathub() return sha256 def get_ref_info(ref): metadata = get_ref_metadata(ref) return { "runtime": metadata.get_string("Application", "runtime") if metadata.has_group("Application") else None, "commit": ref.get_commit(), } def get_refs_info(refs): return {ref.format_ref_cached(): get_ref_info(ref) for ref in refs} def main(): setup_env() add_flathub() refs = Flatpak.Installation.new_user().list_remote_refs_sync("flathub") refs_info = get_refs_info(refs) if os.path.exists(GENERATED_PATH): with open(GENERATED_PATH, "r") as f: old_refs_info = json.load(f) updated_refs = { ref: info for (ref, info) in refs_info.items() if info["commit"] != old_refs_info[ref]["commit"] } for ref, info in tqdm(updated_refs.items()): info["sha256"] = get_sha256(ref, info) else: for ref, info in tqdm(refs_info.items()): info["sha256"] = get_sha256(ref, info) with open(GENERATED_PATH, "w") as f: json.dump(refs_info, f, indent=4) if __name__ == "__main__": main() ```

iavael commented 1 year ago

@io12

  1. Flatpak has PATH at ${installation_base}/export/bin per installation. Also remember that there may be multiple installations (default for "system" is /var/lib/flatpak and for "user" is $XDG_DATA_DIR/flatpak), which are defined at /etc/flatpak/installations.d (https://docs.flatpak.org/en/latest/tips-and-tricks.html)
io12 commented 1 year ago

Thanks @iavael.

Also, apparently Nix doesn't let build outputs hard link to dependencies (https://github.com/NixOS/nix/issues/1272), so deduplication might be hard. It might be better to just rely on nix-store --optimize for now.

Also, I made a repo at https://github.com/io12/nix-flatpak. I think it mostly works, but it's really slow. It takes ~5 hours for me to install a Flatpak vs a few minutes without Nix. I'm not really sure why, maybe something about how fetchOstree is implemented? The build also hits the open file limit, but running ulimit -n unlimited before building fixes this.

yawnt commented 1 year ago

I took a bit of a different approach from @io12 (although big inspiration, thanks!!)

https://github.com/yawnt/declarative-nix-flatpak

seems to work and is quite fast. doesn't really much deal with dedup because if you update a runtime, all apps under that runtime are supposed to be compatible so you only ever need one copy of each "branch" (i think).

it's kinda a rough PoC but if there's some interest i'm happy to maybe clean it up?

vividn commented 1 year ago

Thanks @yawnt. I have interest. What would help me the most is a README detailing how to get this integrated with an existing NixOS configuration and then install some example flatpak using it.

yawnt commented 1 year ago

I've added a readme with a flake example, I don't want to hijack the discussion so if you have any other questions, please kindly open an issue :)

pmarreck commented 1 year ago

I couldn't get the majority of my Steam games to work in the "native" Steam install, but they all work fine via the flatpak (or at least, the same ones that are known to work fine on the Steam Deck or via Proton, now work fine on my NixOS install). That's how I found this thread.

I'm still holding out hope, though, and to that end I bind-mounted the expected flatpak location to the original "native" steam root 😊 (this also prevented me from having to re-download everything, although I could have just copied/moved...):

  # to get both flatpak steam and native steam to use the same install directory
  fileSystems."/home/pmarreck/.var/app/com.valvesoftware.Steam/.local/share/Steam" = {
    device = "/home/pmarreck/.local/share/Steam";
    options = [ "bind" ];
  };
RyzeNGrind commented 1 year ago

Hey everyone, fellow n00b here. I am looking to consider using either NixOS or Talos in order to reprovision and redeploy my microk8s home lab cluster. I was wondering if there are any updates on Snap support as it seems to be a bottleneck in order for me to choose between NixOS or Talos as the base OS for the cluster. Based on my limited understanding of Nix to date, it seems Nix is well on its way to being an industry leader in declaratively configured and reproducible build environments but we still seem to be in progress on some major pain points.

I would like to contribute to building and testing microk8s snap support where possible as I am on the line between choosing to commit to NixOS or Talos as my base OS. It seems Nix can easily do what Talos does plus more. Thoughts?

pmarreck commented 1 year ago

@RyzeNGrind What do you need to/intend to install via snap/flatpak/appimage?

Note that all those solutions I just mentioned are comparatively weak attempts to solve the problem that Nix/NixOS solves definitively. So there is, fundamentally, a philosophical hurdle to surmount, as any Nix[OS] developer/believer will tell you that any energy spent on bringing better snap/flatpak/appimage compatibility is literally better spent figuring out how to get the relevant apps up natively on nixpkgs.

It would be like going to the Cadbury chocolate factory and asking when they will have better carob chip support. :laughing: "Hey Elon, when will you come out with a car that has a gas generator? We still have a few use cases where gas is more plentiful than high voltage."

That all said, like I said recently, I'm currently using Steam via Flatpak. This is absolutely a less than ideal situation, but I was struggling with some games, and I unfortunately don't have the time to help track down the missing configurations that would make those work (context: I have a 17 month old kid. Kiss your freetime goodbye, in case you aren't a parent yet! I hear it gets easier "in a few years"... sigh) Since I now love NixOS AND games, I would absolutely be willing to help the devs responsible for the Steam derivation figure out any remaining hurdles as soon as I have the time (hmmm, is it possible to lend games to steam friends? I have... A LOT of games)... but I don't.

Note that the other advantage of figuring out how to get a given app up on Nix[OS] is that once it's up, it's quite possible that it will be up for good, since updates breaking unrelated things ::cough:: glibc, ssl ::cough:: is virtually non-existent (notable exceptions include: things like graphics drivers, which everything in the GUI has to share, or window managers, of which you can only run 1 at a time). Maybe that's why nixpkgs has (I think) the largest number of available Linux packages across all Linux distros- The stuff that breaks from updates in those other distros takes labor to fix, and that's (almost) completely eliminated labor here.

firestack commented 1 year ago

What do you need to/intend to install via snap/flatpak/appimage?

@pmarreck just so you know, I think this was stated already.

I would like to contribute to building and testing microk8s snap support

Although related, I feel like maybe the workflow for developing snaps might be different then "simply" installing one? I don't use them so I don't know what difference there is between dev and deploy, and nix minimizes the difference anyway.

RyzeNGrind commented 1 year ago

@pmarreck thanks for the detailed Q/A Peter. I guess I should have lead with the motivations when asking my initial question so my bad for that, lol.

I'm currently running an arm64/amd64 hybrid kubernetes cluster in my homelab thanks to Ubuntu and Canonical's snapcraft microk8s snap. Since it minimizes a lot of overhead to run production ready k8s with minimal to zero ops I was planning to try running a similar micro kubernetes cluster but on NixOS instead.

I was able to use microk8s and Ubuntu to date to learn everything I needed to secure my career path into DevOps while attempting to solidify my skillset and play around developing personal projects.

I guess based on my current limited understanding of Nix, i can see how valuable a tool it will become as part of the dev toolchain and wanted to see how i could migrate my existing cluster or create a new baremetal m-k8s cluster based on Nix. Hope my comment provided the insight or clarity needed.

I guess my end goal is to have a zero-minimal ops k8s cluster out of my homelab for running my self hosted services and maybe exposing a few endpoints or services to the web for friends, family, school stuff, projects, etc.

pmarreck commented 1 year ago

@RyzeNGrind Well I can tell you a few things as a guy who's been messing with Nix[OS] for a few months now, to illustrate my perspective. I think your intuition about Nix is largely correct; that's why a lot of us came here, and additionally I think it's cool that you were drawn here as a devops person, because mastering Nix[OS] (or Guix, just to be fair) would be a powerful tool in your toolbox. One possible place to start seeing how K8s might fit into the Nix[OS] picture might be https://nixos.wiki/wiki/Kubernetes (note: I haven't personally messed with k8s on nix, just steering you there!).

A few things to keep your expectations realistic:

1) The learning curve is not flat, it's rather steep, and lots of things are (under)documented, so you may need to spend time on google, forums, or nix-focused chat channels (there's a discord, and a matrix, and other locations) to get what you need to get done or earn the understanding you seek.

2) That said, you will probably hit a magic moment on this incline where you have things basically working, you understand enough to at least get something working, and then this happens: OMG. EVERY. MACHINE. I. OWN. NEEDS. TO. RUN. THIS. OS. :smile: I've seen this happen in myself, I've seen others online realize the same thing... The sheer leverage you get with declarative deterministic trivially-rollback-able config, like being able to just push builds to any of your machines over the wire or being able to just reboot into a previous configuration if something gets borked, or just having separate projects that all have their own dependency hierarchies without conflicting with each other, it's huge. I had a drive go bad for example a couple months ago and thanks to having the essential files in my home directory backed up and my machine config checked into source control, I was back up and running in under 2 hours (and that's mostly because I had to rebuild the custom ZFS-on-root config that is documented here: https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS.html)

3) The Nix language. You can get by for a while barely understanding it and just copying/pasting other people's configs, but eventually you'll want to understand what's going on there. It's been summarized as "JSON with pure functions" but it's a bit more than that and has a few quirky things about it (one that comes to mind is that assigning a list to an attribute actually appends those values to the existing list value of the attribute; you have to assign an empty list to clear it); a good interactive guide I found online is here: https://nixcloud.io/tour/ and the nixos search page has an "options" section that lets you search for any config option: https://search.nixos.org/options?

4) The word "derivation" scared me for a while. Do you understand the concept of "lockfiles"? (used in node, ruby and elixir, among other stacks)? A derivation is basically a lockfile for a particular app/component. Instead of just expressing the names and/or versions of any dependencies, it computes the actual hashes of the relevant commits or binaries (which encompasses EVERYTHING that piece of software needs to run) and stores them in a file called a "derivation" (extension .drv). There, you can now move on. ;) Regarding writing your own derivations in nix-lang, for now just find other people's code for something similar and modify it as needed. Expect to experiment.

On the "everything I own needs to run NixOS" front, here's a guy who built his own home router using nixos and loves it: https://skogsbrus.xyz/blog/2022/06/12/router/

Here's someone who came up with a MicroVM scheme that seems to work great: https://github.com/astro/microvm.nix

Anyway, I think you'll like it and can make it work for you, just expect to wade into the deep end for a while.

Back to regarding snaps specifically, this discussion mentions how Spotify is only reliably distributed as a snap currently, and provides a link to a recipe for it which might be helpful: https://discourse.nixos.org/t/installing-a-snap-package/11468/2 (I have Spotify installed and can attest to the fact that it runs well!)

Sepero commented 1 year ago

The reason we need snapcraft (and flatpak) support is because there are more and more snap packages being added by developers every day. Nix does not have the human power to repackage and stay up to date with all the programs that developers are releasing as prepackaged

bayazidbh commented 1 year ago

At the very least, I think a simple option of with.flatpakPkg and with.snapPkg (or maybe services.flatpak.install = []; if we go with existing options) to install the flatpak and snap apps declaratively would be convenient.

I don't think it should be that hard either -- for flatpak, you can do flatpak list --app --columns=application and check for app IDs that are present / not present, install the ones not present, and remove the ones not declared in the config file. Installing specific version of flatpak apps declaratively should be as easy as providing the commit version.

Snaps are probably more challenging, because of the specific orders they may ask for install / uninstall. A user may install firefox through snap (maybe for testing) and then remove it -- the unusued snap dependencies that came with firefox would need to be uninstalled but it has to be done in order, which is a bit more complex.

I'm mostly a home-manager user, but an option to declaratively install flatpak, snap, and maybe even AppImages would be very convenient and useful.

iavael commented 1 year ago

@bayazidbh that approach implies that nix would manage flatpak/snap storage. But nix manages only it's own /nix/store. And anyway making nix change installed flatpak apps doesn't look very robust.

bayazidbh commented 1 year ago

@iavael

Well, my main desire is for a simple way to manage flatpak declaratively, having everything be done declaratively makes it very convenient for me.

But other than that, I was thinking of it more as a tentative support. I'd love to have Nix be able to use flatpak-build and have a way to automatically build flatpak apps instead of just installing them from flathub or other repo.

But for some apps, I'd probably not care and just want it to pull a binary from a repo -- just that the install process be declarative so I can put them inside my home-manager config.

Edit: Found someone who've made a module for declarative-flatpak, though not soon enough that I didn't spend a day trying to work out my own way of doing it (oh, well, I learned a lot at least).

dnkmmr69420 commented 1 year ago

We already got flatpaks but now we need a way to install snaps.

orxngc commented 10 months ago

Flatpaks are working.. how about snaps?

nixos-discourse commented 10 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/enable-snap-and-install-snap-applications/32834/2

io12 commented 8 months ago

I have an initial attempt at https://github.com/io12/nix-snapd. So far it works with most of the snaps I've been using for testing.