From 4bdff9dedf0c1868bb04bbe2a7db1148f5bb2411 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Fri, 20 Nov 2020 10:08:15 +0200 Subject: [PATCH] Switch to flakes Use VERSION file to define version for both Makefile and flake.nix. --- .gitignore | 1 + Makefile | 2 +- VERSION | 1 + default.nix | 9 ++++++++ flake.lock | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 40 +++++++++++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 VERSION create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 5164e2c..1569f8e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ # End of https://www.gitignore.io/api/go /cmd/pistol/pistol /pistol +result diff --git a/Makefile b/Makefile index 01f3b46..3b7f12b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. NAME := pistol -VERSION := v0.1.6 +VERSION := v$(shell cat VERSION)-git build: go build -ldflags "-X 'main.Version=$(VERSION)'" ./cmd/pistol diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..c946ee6 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.6 diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..f8a169d --- /dev/null +++ b/default.nix @@ -0,0 +1,9 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3abfb97 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1603796912, + "narHash": "sha256-6ayqpH/4XiEXylNdWI3AghubqS6XuiPg3Y60jY8RTo4=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "19576c2aea7f074ff0da818b21a8b0950ff6ec86", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1605370193, + "narHash": "sha256-YyMTf3URDL/otKdKgtoMChu4vfVL3vCMkRqpGifhUn0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5021eac20303a61fafe17224c087f5519baed54d", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1605447878, + "narHash": "sha256-gvO1uqPhXOT9k5Gggfll0ZMipPIJuRu9+NFMkTfOya8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "069f183f16c3ea5d4b6e7625433b92eba77534f7", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..26f3b15 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "General purpose file previewer designed for Ranger, Lf to make scope.sh redundant"; + + # To make user overrides of the nixpkgs flake not take effect + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + # https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix + inputs.flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + + outputs = { self, nixpkgs, flake-utils, flake-compat }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + pistol = pkgs.pistol.overrideAttrs(oldAttrs: rec { + version = "${builtins.readFile ./VERSION}-flake"; + buildFlagsArray = [ + "-ldflags=-s -w -X main.Version=${version}" + ]; + }); + in rec { + devShell = pkgs.mkShell { + buildInputs = pistol.buildInputs ++ [ + pkgs.w3m + ]; + }; + packages.pistol = pistol; + defaultPackage = pistol; + apps.pistol = { + type = "app"; + program = "${pistol}/bin/pistol"; + }; + defaultApp = apps.pistol; + } + ); +}