Here is a handy bash script I wrote called watchlater. There are many more of those tiny helpers that I usually write to prevent repeating myself. For the ease of deployment on multiple machines I also wrote a sort of package managing script called ownscript that cloned the repo and symlinked the script file to a place in my $PATH. Good stuff for the old days of me using ordinary Linux computers.
Now that I am using NixOS, I want to learn how this is done the right way here. From my understanding, the modern way to go is to write a flake for this. There are plenty of posts on the web about how to write flakes, but either I am still misunderstanding or most of them are talking about something else then what I am trying to achieve. I did see this thread, but there as well I think they are not really talking about the same thing. Also the term “legacy” appears a lot within their snippets, which makes me doubt being on the right track there.
What I am trying to achieve:
- use
watchlater …as a regularly available shell command in my NixOS - keep the original git repository as it is, i.e. no
flake.nixinside there
What I think needs to be done:
- create a separate place for a
flake.nixthat defines what needs to be done to have that bash script installed - add “install this flake/package” to my NixOS config (not sure if I am using the correct terms here)
However, for reasons of decentralization and the future health of the internet, I do not want to mess with the great nixpkgs repo on Github. From my understanding, it is possible to have multiple nixpkgs repos side by side.
So my approach would be to have e.g. a git repo codeberg.org/mcnesium/nixpkgs with e.g. ./tools/watchlater/flake.nix that I assume it looks like this:
description = "A flake for the watchlater script";
inputs = {
# declare the original source repo
watchlater.url = https://codeberg.org/mcnesium/watchlater.git;
};
outputs = { watchlater }:
# the tricky part: what is needed here to get it done?
# * clone the repo to whereever nixos wants it to
# * symlink `watchlater.sh` to my `$PATH` as `watchlater` without extension
# * install dependencies `yt-dlp` and `ffmpeg`
To include this in my NixOS Setup I would go ahead and add this to the flake.nix like this:
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = { … };
ownpkgs.url = git+https://codeberg.org:mcnesium/nixpkgs";
};
outputs = inputs@{ self, nixpkgs, home-manager, ownpkgs ... }: { … };
and in my configuration.nix I would write something like
users.users.mcnesium = {
packages = with pkgs;
[
ownpkgs.watchlater
];
};
Am I on the right track to achieve what I want? How would the flakes.nix really look like? How would I append this the correct and modern flakes-way to my system?