gabrielzschmitz / Tomato.C

A pomodoro timer written in pure C.
GNU General Public License v3.0
315 stars 19 forks source link

❄️ Fetching source from remote repository + pkgs import via ternary operator #13

Closed luisnquin closed 1 year ago

luisnquin commented 1 year ago

Personally, I don't think that src = ./. gets too useful for now, this new .nix file version installs tomato from GitHub

You only will need to update the sha256 and rev with the data from the generated JSON in nix-prefetch-git <repo-url> for each big change that you do in the program

Example:

$ nix-prefetch-git https://github.com/gabrielzschmitz/Tomato.C
git revision is dda8e0ffe0b8612691ed336962f33580fb3a6038
path is /nix/store/q251xbkaixg6h5d8r405ngpr6lx6hqxk-Tomato.C
git human-readable version is -- none --
Commit date is 2023-01-25 20:49:09 -0300
hash is 193xr63s4700bsamac0zjff0l6n8bcm60f546jfxqaafz126f9zv
{
  "url": "https://github.com/gabrielzschmitz/Tomato.C",
  "rev": "dda8e0ffe0b8612691ed336962f33580fb3a6038",
  "date": "2023-01-25T20:49:09-03:00",
  "path": "/nix/store/q251xbkaixg6h5d8r405ngpr6lx6hqxk-Tomato.C",
  "sha256": "193xr63s4700bsamac0zjff0l6n8bcm60f546jfxqaafz126f9zv",
  "fetchLFS": false,
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

Now there are two ways of installation

I guess that's it, maybe later if I find it useful I'll add a flake.nix, but for now this is enough

gabrielzschmitz commented 1 year ago

How can I get this data without using NixOS as I need to update the rev and sha256?

luisnquin commented 1 year ago

Well, there's a Python app that also does that, I think that is even simpler, its name is nix-prefetch-github

Install it by using: pip install nix-prefetch-github or pipx install nix-prefetch-github

Usage example:

$ nix-prefetch-github gabrielzschmitz Tomato.C
{
    "owner": "gabrielzschmitz",
    "repo": "Tomato.C",
    "rev": "dda8e0ffe0b8612691ed336962f33580fb3a6038",
    "sha256": "+ydnRPhOKdydNKQ4YCpbyBoKnJMfMFWVXgAcoofJfaQ="
}
gabrielzschmitz commented 1 year ago

Ok, thanks. Will implement

gabrielzschmitz commented 1 year ago

Oh no:

$ nix-prefetch-github gabrielzschmitz Tomato.C
Traceback (most recent call last):
  File "/home/gabrielzschmitz/.local/bin/nix-prefetch-github", line 8, in <module>
    sys.exit(main())
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/cli/fetch_github.py", line 9, in main
    controller.process_arguments(sys.argv[1:])
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/controller/nix_prefetch_github_controller.py", line 29, in process_arguments
    self._use_case.prefetch_github_repository(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/use_cases/prefetch_github_repository.py", line 38, in prefetch_github_repository
    prefetch_result = self.prefetcher.prefetch_github(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/prefetch.py", line 38, in prefetch_github
    return self._prefetch_github(repository, revision, prefetch_options)
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/prefetch.py", line 46, in _prefetch_github
    calculated_hash = self._calculate_sha256_sum(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/prefetch.py", line 82, in _calculate_sha256_sum
    return self.url_hasher.calculate_sha256_sum(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/url_hasher/url_hasher_selector.py", line 39, in calculate_sha256_sum
    return hasher.calculate_sha256_sum(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/url_hasher/nix_build.py", line 28, in calculate_sha256_sum
    status_code, output = self.run_fetch_command(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/url_hasher/nix_build.py", line 57, in run_fetch_command
    result = self.command_runner.run_command(
  File "/home/gabrielzschmitz/.local/lib/python3.10/site-packages/nix_prefetch_github/command/command_runner.py", line 25, in run_command
    process = subprocess.Popen(
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'nix-build'
luisnquin commented 1 year ago

Lol

luisnquin commented 1 year ago

@gabrielzschmitz I was investigating more about that and apparently is a feature that is only available for Nix machines, even I wanted to create a bash script for that but the above answer was repeated

You could try to install Nix package manager for your computer, maybe it should be an upgrade for you regardless of this

Here's the download link: https://nixos.org/download.html

Once you have Nix installed then you can type nix-env -iA nixpkgs.nix-prefetch-git to of course, install the package

You can also search for more packages here, start by searching something like I don't know ¿docker?

Anyway, I don't have problems by updating the file just for relevant updates, let me know what you will do

gabrielzschmitz commented 1 year ago

I will install a NixOS VM so I can get a better support for all NixOS users. But I will be very happy if you could update it until then!

gabrielzschmitz commented 1 year ago

maintimer-19:38:56 Let's gooo