Refactor to flake-utils.

Reduce boilerplate and add `apps` and `devShells`.
This commit is contained in:
Lyle Mantooth 2023-12-17 16:50:49 -05:00
parent d869a9e31f
commit e7bd971451
Signed by: IslandUsurper
GPG key ID: 6DB52EAE123A5789
2 changed files with 97 additions and 50 deletions

View file

@ -1,24 +1,58 @@
{ {
"nodes": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1702645756, "lastModified": 1702846620,
"narHash": "sha256-qKI6OR3TYJYQB3Q8mAZ+DG4o/BR9ptcv9UnRV2hzljc=", "narHash": "sha256-45K8VhHgE8cSPUgm5ixOTtmplWGXJN4ozNvjmEVSYGc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "40c3c94c241286dd2243ea34d3aef8a488f9e4d0", "rev": "50b80afb13c6bcf8cc4be7e1fbd7719a85c487cb",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-23.11", "ref": "release-23.11",
"type": "indirect" "type": "indirect"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "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", "root": "root",

105
flake.nix
View file

@ -2,70 +2,83 @@
description = "Super Nintendo Interface"; description = "Super Nintendo Interface";
# Nixpkgs / NixOS version to use. # 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 = { outputs = {
self, self,
nixpkgs, nixpkgs,
flake-utils,
}: let }: let
# to work with older version of flakes # to work with older version of flakes
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
version = "0.0.95"; 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. sni = pkgs.buildGoModule {
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; pname = "sni";
inherit version;
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. src = pkgs.fetchFromGitHub {
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; owner = "alttpo";
repo = "sni";
rev = "v${version}";
hash = "sha256-lk4RIeObwdyTJzPcDYhSxkT9VG8Y6FWnsHQcjGJdfwI=";
};
# Nixpkgs instantiated for supported system types. buildInputs = with pkgs; [
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;}); gtk3.dev
in { libayatana-appindicator.dev
# Provide some binary packages for selected system types. ];
packages = forAllSystems (system: let nativeBuildInputs = [
pkgs = nixpkgsFor.${system}; pkgs.pkg-config
in rec { ];
default = sni;
sni = pkgs.buildGoModule { subPackages = "./cmd/sni";
pname = "sni";
inherit version;
src = pkgs.fetchFromGitHub { # This hash locks the dependencies of this package. It is
owner = "alttpo"; # necessary because of how Go requires network access to resolve
repo = "sni"; # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for
rev = "v${version}"; # details. Normally one can build with a fake sha256 and rely on native Go
hash = "sha256-lk4RIeObwdyTJzPcDYhSxkT9VG8Y6FWnsHQcjGJdfwI="; # 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; [ apps = rec {
gtk3.dev sni = {
libayatana-appindicator.dev type = "app";
]; program = "${self.packages.${system}.sni}/bin/sni";
nativeBuildInputs = [ };
pkgs.pkg-config default = sni;
]; };
subPackages = "./cmd/sni"; devShells = {
default = pkgs.mkShell {
# This hash locks the dependencies of this package. It is buildInputs = with pkgs; [
# necessary because of how Go requires network access to resolve go
# VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for gtk3.dev
# details. Normally one can build with a fake sha256 and rely on native Go libayatana-appindicator.dev
# mechanisms to tell you what the hash should be or determine what pkg-config
# 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];
}; };
}; };
}); });
};
} }