diff --git a/.gitignore b/.gitignore index 6d4529d..d680eed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ bin releases extra/man/chrome-shell.1.gz extra/man/chrome-shell.1.html +# symbolic link created by nix +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..62d57c9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1718530797, + "narHash": "sha256-pup6cYwtgvzDpvpSCFh1TEUjw2zkNpk8iolbKnyFmmU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b60ebf54c15553b393d144357375ea956f89e9a9", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f8b385e --- /dev/null +++ b/flake.nix @@ -0,0 +1,64 @@ +{ + description = "A native messaging host for executing shell commands."; + + # Nixpkgs / NixOS version to use. + inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: + let + # Generate a user-friendly version number. + version = "nightly-4"; + + # System types to support. + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + + in + { + + # enable nix fmt + formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt; + + # Provide some binary packages for selected system types. + packages = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + in + { + chrome-shell = pkgs.crystal.buildCrystalPackage { + pname = "chrome-shell"; + inherit version; + src = ./.; + format = "shards"; + + # nix cannot run git commands to generate the version string, + # patch the sources to set the version string + patchPhase = '' + sed -i "s/{{.*}}/\"${version}\"/" src/main.cr + ''; + }; + }); + + # Add dependencies that are only needed for development + devShells = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShell { + buildInputs = (with pkgs; [ nixd ]) + ++ (with self.packages.${system}.chrome-shell; nativeBuildInputs ++ buildInputs); + }; + }); + + # The default package for 'nix build'. This makes sense if the + # flake provides only one package or there is a clear "main" + # package. + defaultPackage = forAllSystems (system: self.packages.${system}.chrome-shell); + }; +}