diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04ba295..2c6bb0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,19 @@ jobs: - name: Run tests run: go test ./... + nix-build: + name: Nix Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v21 + + - name: Build flake package + run: nix build . + coverage: name: Test and Coverage if: github.event_name == 'push' && github.ref == 'refs/heads/main' diff --git a/README.md b/README.md index c405f13..cab22bd 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ ec (easy-conflict) is a 3-way terminal native Git merge conflict resolver. Suppo brew install chojs23/tap/ec ``` +### Nix + +Run without installing: + +```bash +nix run github:chojs23/ec +``` + +Install into your profile: + +```bash +nix profile add github:chojs23/ec +``` + ### Install script You can run the installer through Make: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3e38940 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1772963539, + "narHash": "sha256-9jVDGZnvCckTGdYT53d/EfznygLskyLQXYwJLKMPsZs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9dcb002ca1690658be4a04645215baea8b95f31d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fef2f18 --- /dev/null +++ b/flake.nix @@ -0,0 +1,93 @@ +{ + description = "ec: terminal Git mergetool with a 3-way TUI"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: + let + lib = nixpkgs.lib; + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = lib.genAttrs systems; + tagRef = + if self ? ref then + self.ref + else if self ? sourceInfo && self.sourceInfo ? ref then + self.sourceInfo.ref + else + null; + versionDate = + if self ? lastModifiedDate then + builtins.substring 0 8 self.lastModifiedDate + else + null; + dirtyRevision = + if self ? dirtyShortRev then + lib.removeSuffix "-dirty" self.dirtyShortRev + else + null; + tagVersion = + if !builtins.isNull tagRef && lib.hasPrefix "refs/tags/" tagRef then + lib.removePrefix "refs/tags/" tagRef + else if !builtins.isNull tagRef && builtins.match "v[0-9].*" tagRef != null then + tagRef + else + null; + version = + if !builtins.isNull tagVersion then + tagVersion + else if self ? rev && self ? shortRev && !builtins.isNull versionDate then + "${versionDate}-${self.shortRev}" + else if !builtins.isNull dirtyRevision && !builtins.isNull versionDate then + "dirty-${versionDate}-${dirtyRevision}" + else if self ? shortRev && !builtins.isNull versionDate then + "${versionDate}-${self.shortRev}" + else if !builtins.isNull versionDate then + "dirty-${versionDate}" + else + "dirty"; + in + { + packages = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + rec { + ec = pkgs.buildGoModule { + pname = "ec"; + inherit version; + src = ./.; + vendorHash = "sha256-bV5y8zKculYULkFl9J95qebLOzdTT/LuYycqMmHKZ+g="; + subPackages = [ "cmd/ec" ]; + ldflags = [ + "-s" + "-w" + "-X main.version=${version}" + ]; + + meta = { + description = "Terminal-native 3-way git mergetool vim-like workflow"; + homepage = "https://github.com/chojs23/ec"; + license = pkgs.lib.licenses.mit; + mainProgram = "ec"; + platforms = pkgs.lib.platforms.unix; + }; + }; + + default = ec; + } + ); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/ec"; + }; + }); + }; +}