NixOS - How to use flakes without converting entire system to flakes?

I’ve heard of flake-compat and unflake, but I don’t know how to use them, or if they even solve my issue. I want to use flakes without converting my entire system into a flake. I just learned stable nix and I don’t want to learn flakes.

Is this even possible?

You can use flakes without having your system as a flake. The question is, what exactly do you expect from “using flakes”, as they way you want to use them, will change how we introduce them to you.

{
  nix.settings.experimental-features = [ "flakes" "nix-command" ];
}

in your NixOS config.

But if you don’t want to learn, why use it?

I want to use a specific package that is a flake on Github, from stable nix. In other words, I want to use a flake from Github in my configuration.nix without needing to make a flake.nix.

Which one exactly, is the flake really the only way the distribute that package? And is it really only a package you want to consume?

Yes. It’s only a flake, I think. Package is here, in case I’m wrong.

You can in theory use the repos package.nix directly.

Though using anything hyprland related from a random repo, while not using hyprland nightly itself, is usually deemed to fail.

I would not recommend mixing a stable channels HL, with some nightly repos plugin.

builtins.getFlake exists, but tbh without Override inputs when using `builtins.getFlake` · Issue #9154 · NixOS/nix · GitHub it doesn’t seem very practical to me.

(note that while the issue is old, there is some recent-ish work on it)

How would I go about doing this?

Depends on whether you want to avoid/care for IFD.

But roughly the following should return a package, ready to be installed by whatever means HL plugins or toolings require to be used:

repo = pkgs.fetchFromGitHub {
  owner = "WhySoBad";
  repo = "hyprland-preview-share-picker";
  tag = "…";
  hash = "…";
  fetchSubmodules = true;
};
picker = pkgs.callPackage "${repo}/package.nix" {rev = repo.hash;};
3 Likes

This worked thank you so much.

For noobs (like me), put this in like:

{ pkgs, lib, ... }:

let
  repo = pkgs.fetchFromGitHub {
    owner = "WhySoBad";
    repo = "hyprland-preview-share-picker";
    rev = "344394a8669fb82ff2744d2780327dd402ffb76a";
    hash = "sha256-dreIL3+GfrTxzN5ZoQvLvEc8qFlTs/qwQZjPFJS1eJQ=";
  }
  picker = pkgs.callPackage "${repo}/package.nix" {rev = repo.rev;};
in {
  # for system-wide nix
  environment.systemPackages = with pkgs; [
    picker
  ];
  
  # for home-manager
  home.packages = with pkgs; [
    picker
  ];
}
1 Like