From 87f75201e1fae46ea377f38a95e4546e52bd01b7 Mon Sep 17 00:00:00 2001 From: sshine Date: Wed, 16 Jul 2025 13:12:30 +0200 Subject: [PATCH 1/5] feat: Add default.nix --- default.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 default.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..10b5613 --- /dev/null +++ b/default.nix @@ -0,0 +1,29 @@ +{ + lib, + buildGoModule, +}: +buildGoModule rec { + pname = "hcloud-upload-image"; + version = + builtins.head (builtins.match ".*version = \"([0-9.]+)\".*" + (builtins.readFile ./internal/version/version.go)); + + src = ./.; + vendorHash = "sha256-HPskDotHX5GnbuL2KkoqRiY4G1MxOvwJBMBPDCIzHvE="; + env.GOWORK = "off"; + subPackages = ["."]; + + ldflags = [ + "-s" + "-w" + "-X main.version=${version}" + ]; + + meta = { + description = "Quickly upload any raw disk images into your Hetzner Cloud projects"; + homepage = "https://github.com/apricote/hcloud-upload-image"; + license = lib.licenses.mit; + maintainers = []; + mainProgram = "hcloud-upload-image"; + }; +} From f188c584f3009e2406750f0dbfc35a6e27c0a727 Mon Sep 17 00:00:00 2001 From: sshine Date: Wed, 16 Jul 2025 13:38:59 +0200 Subject: [PATCH 2/5] feat: Add shell.nix --- shell.nix | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..3031ec1 --- /dev/null +++ b/shell.nix @@ -0,0 +1,9 @@ +{pkgs ? import {}}: +pkgs.mkShell { + buildInputs = with pkgs; [ + go + gopls + gotools + go-tools + ]; +} From a0075b8a94600c284fa905eb40c2c8eb72c98a86 Mon Sep 17 00:00:00 2001 From: sshine Date: Wed, 16 Jul 2025 13:35:03 +0200 Subject: [PATCH 3/5] feat: Add flake.nix --- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 34 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7b8f00b --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1751413152, + "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1752480373, + "narHash": "sha256-JHQbm+OcGp32wAsXTE/FLYGNpb+4GLi5oTvCxwSoBOA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "62e0f05ede1da0d54515d4ea8ce9c733f12d9f08", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1751159883, + "narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cc90a51 --- /dev/null +++ b/flake.nix @@ -0,0 +1,34 @@ +{ + description = "hcloud-upload-image - Quickly upload any raw disk images into your Hetzner Cloud projects"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + perSystem = {pkgs, ...}: let + pkg = pkgs.callPackage ./default.nix {}; + app = { + type = "app"; + program = "${pkg}/bin/hcloud-upload-image"; + }; + in { + packages.default = pkg; + packages.hcloud-upload-image = pkg; + + apps.default = app; + apps.hcloud-upload-image = app; + + devShells.default = pkgs.callPackage ./shell.nix {}; + }; + }; +} From b93920e6213c413bfc634a56db3f0e9edf18c806 Mon Sep 17 00:00:00 2001 From: sshine Date: Wed, 16 Jul 2025 19:35:51 +0200 Subject: [PATCH 4/5] doc: Add Nix/NixOS section README.md --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/README.md b/README.md index 04a2999..994a92b 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,63 @@ If you already have a recent Go toolchain installed, you can build & install the go install github.com/apricote/hcloud-upload-image@latest ``` +#### Nix/NixOS + +To run directly without installing (assumes flakes are enabled): + +```shell +# Run the application directly +nix run github:apricote/hcloud-upload-image + +# Start a shell with `hcloud-upload-image` in $PATH +nix shell github:apricote/hcloud-upload-image +``` + +To install on your system (assumes flakes are enabled): + +```nix +# flake.nix +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.hcloud-upload-image.url = "github:apricote/hcloud-upload-image"; + inputs.hcloud-upload-image.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, nixpkgs, hcloud-upload-image }: { + nixosConfigurations.my-system = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + { + environment.systemPackages = [ + hcloud-upload-image.packages.x86_64-linux.default + ]; + } + ]; + }; + }; +} +``` + +To install on your system (using a non-flake version manager): + +```shell +# Using npins +npins add github apricote hcloud-upload-image + +# Using niv +niv add apricote/hcloud-upload-image +``` + +Then in your Nix expressions: + +```nix +let + sources = import ./npins; # For npins + # sources = import ./nix/sources.nix; # For niv +in +(pkgs.callPackage sources.hcloud-upload-image {}) +``` + #### Docker There is a docker image published at `ghcr.io/apricote/hcloud-upload-image`. From 40c06556a12f58dd2d7f6ca1ab60e8d1b30b983a Mon Sep 17 00:00:00 2001 From: sshine Date: Wed, 16 Jul 2025 19:36:55 +0200 Subject: [PATCH 5/5] chore: Ignore 'result' artifact from 'nix build' --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0e33ea6..dc0b2f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist/ completions/ +result