From e7bd9714519b6083ab06b32a2fb711e62ebf1463 Mon Sep 17 00:00:00 2001 From: Lyle Mantooth Date: Sun, 17 Dec 2023 16:50:49 -0500 Subject: [PATCH] Refactor to flake-utils. Reduce boilerplate and add `apps` and `devShells`. --- flake.lock | 42 +++++++++++++++++++-- flake.nix | 105 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 97 insertions(+), 50 deletions(-) diff --git a/flake.lock b/flake.lock index d56f3d9..ee7f40b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,24 +1,58 @@ { "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1702645756, - "narHash": "sha256-qKI6OR3TYJYQB3Q8mAZ+DG4o/BR9ptcv9UnRV2hzljc=", + "lastModified": 1702846620, + "narHash": "sha256-45K8VhHgE8cSPUgm5ixOTtmplWGXJN4ozNvjmEVSYGc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "40c3c94c241286dd2243ea34d3aef8a488f9e4d0", + "rev": "50b80afb13c6bcf8cc4be7e1fbd7719a85c487cb", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-23.11", + "ref": "release-23.11", "type": "indirect" } }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index d613104..53b7c95 100644 --- a/flake.nix +++ b/flake.nix @@ -2,70 +2,83 @@ description = "Super Nintendo Interface"; # Nixpkgs / NixOS version to use. - inputs.nixpkgs.url = "nixpkgs/nixos-23.11"; + inputs.nixpkgs.url = "nixpkgs/release-23.11"; + inputs.flake-utils.url = "github:numtide/flake-utils"; outputs = { self, nixpkgs, + flake-utils, }: let # to work with older version of flakes lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; version = "0.0.95"; + in + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + # Provide some binary packages for selected system types. + packages = rec { + default = sni; - # System types to support. - supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; + sni = pkgs.buildGoModule { + pname = "sni"; + inherit version; - # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + src = pkgs.fetchFromGitHub { + owner = "alttpo"; + repo = "sni"; + rev = "v${version}"; + hash = "sha256-lk4RIeObwdyTJzPcDYhSxkT9VG8Y6FWnsHQcjGJdfwI="; + }; - # Nixpkgs instantiated for supported system types. - nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;}); - in { - # Provide some binary packages for selected system types. - packages = forAllSystems (system: let - pkgs = nixpkgsFor.${system}; - in rec { - default = sni; + buildInputs = with pkgs; [ + gtk3.dev + libayatana-appindicator.dev + ]; + nativeBuildInputs = [ + pkgs.pkg-config + ]; - sni = pkgs.buildGoModule { - pname = "sni"; - inherit version; + subPackages = "./cmd/sni"; - src = pkgs.fetchFromGitHub { - owner = "alttpo"; - repo = "sni"; - rev = "v${version}"; - hash = "sha256-lk4RIeObwdyTJzPcDYhSxkT9VG8Y6FWnsHQcjGJdfwI="; + # This hash locks the dependencies of this package. It is + # necessary because of how Go requires network access to resolve + # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for + # details. Normally one can build with a fake sha256 and rely on native Go + # mechanisms to tell you what the hash should be or determine what + # it should be "out-of-band" with other tooling (eg. gomod2nix). + # To begin with it is recommended to set this, but one must + # remeber to bump this hash when your dependencies change. + vendorHash = "sha256-hvIfGu7SQ+OV5iPYlvuOIpE9OqMLRCuUpl5YCpsmBWI="; + + meta = with pkgs.lib; { + description = "An interface that allows multiple concurrent applications to access various kinds of Super Nintendo devices connected to the computer"; + homepage = "https://github.com/alttpo/sni"; + license = licenses.mit; + maintainers = with maintainers; [island_usurper]; + }; }; - buildInputs = with pkgs; [ - gtk3.dev - libayatana-appindicator.dev - ]; - nativeBuildInputs = [ - pkgs.pkg-config - ]; + apps = rec { + sni = { + type = "app"; + program = "${self.packages.${system}.sni}/bin/sni"; + }; + default = sni; + }; - subPackages = "./cmd/sni"; - - # This hash locks the dependencies of this package. It is - # necessary because of how Go requires network access to resolve - # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for - # details. Normally one can build with a fake sha256 and rely on native Go - # mechanisms to tell you what the hash should be or determine what - # it should be "out-of-band" with other tooling (eg. gomod2nix). - # To begin with it is recommended to set this, but one must - # remeber to bump this hash when your dependencies change. - vendorHash = "sha256-hvIfGu7SQ+OV5iPYlvuOIpE9OqMLRCuUpl5YCpsmBWI="; - - meta = with pkgs.lib; { - description = "An interface that allows multiple concurrent applications to access various kinds of Super Nintendo devices connected to the computer"; - homepage = "https://github.com/alttpo/sni"; - license = licenses.mit; - maintainers = with maintainers; [island_usurper]; + devShells = { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + go + gtk3.dev + libayatana-appindicator.dev + pkg-config + ]; + }; }; }; }); - }; }