From dee1af556ce932c148c365e33b7ff72c64528621 Mon Sep 17 00:00:00 2001 From: pinage404 Date: Tue, 24 Dec 2024 00:48:20 +0100 Subject: [PATCH] feat: add ability to run apps from the launchpad apps installed without nix-darwin nor home-manager --- README.org | 60 ++++++++++++++++++++++++++++++++++++++++++++++ example/.gitignore | 1 + example/flake.nix | 52 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 22 +++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 example/.gitignore create mode 100644 example/flake.nix diff --git a/README.org b/README.org index b20e634..1f2f978 100644 --- a/README.org +++ b/README.org @@ -160,6 +160,66 @@ in } #+end_src +*** Others Flakes without nix-darwin nor home-manager + +This will install apps local for a project available in the launchpad + +Example: + +#+begin_src nix +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + inputs.nixcasks.url = "github:jacekszymanski/nixcasks"; + inputs.nixcasks.inputs.nixpkgs.follows = "nixpkgs"; + + inputs.mac-app-util.url = "github:hraban/mac-app-util"; + + outputs = + { self + , nixpkgs + , flake-utils + , mac-app-util + , nixcasks + , ... + }: + flake-utils.lib.eachDefaultSystem (system: { + devShells.default = + let + osVersion = "sonoma"; + + nixcasksOverlay = final: prev: { + nixcasks = (nixcasks.output { + inherit osVersion; + }).packages."${prev.system}"; + }; + + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + nixcasksOverlay + ]; + }; + + brewPackages = [ + pkgs.nixcasks.android-studio + pkgs.nixcasks.firefox + ]; + in + pkgs.mkShellNoCC { + shellHook = '' + # make apps available in the launcher and up to date in the dock + ${pkgs.lib.getExe mac-app-util.packages."${system}".shellHook} \ + ${mac-app-util.lib.assembleBrewAppsInOneFolder { inherit pkgs brewPackages; }} \ + "Nix_Flake_Example" + ''; + }; + }); +} +#+end_src + ** Commands At the core of this project is a (Nix-agnostic) program that can: diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..301d47e --- /dev/null +++ b/example/.gitignore @@ -0,0 +1 @@ +flake.lock diff --git a/example/flake.nix b/example/flake.nix new file mode 100644 index 0000000..4a6708a --- /dev/null +++ b/example/flake.nix @@ -0,0 +1,52 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + inputs.nixcasks.url = "github:jacekszymanski/nixcasks"; + inputs.nixcasks.inputs.nixpkgs.follows = "nixpkgs"; + + # inputs.mac-app-util.url = "github:hraban/mac-app-util"; + inputs.mac-app-util.url = "../."; + + outputs = + { self + , nixpkgs + , flake-utils + , mac-app-util + , nixcasks + , ... + }: + flake-utils.lib.eachDefaultSystem (system: { + devShells.default = + let + osVersion = "sonoma"; + + nixcasksOverlay = final: prev: { + nixcasks = (nixcasks.output { + inherit osVersion; + }).packages."${prev.system}"; + }; + + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + nixcasksOverlay + ]; + }; + + brewPackages = [ + pkgs.nixcasks.android-studio + pkgs.nixcasks.firefox + ]; + in + pkgs.mkShellNoCC { + shellHook = '' + # make apps available in the launcher and up to date in the dock + ${pkgs.lib.getExe mac-app-util.packages."${system}".shellHook} \ + ${mac-app-util.lib.assembleBrewAppsInOneFolder { inherit pkgs brewPackages; }} \ + "Nix_Flake_Example" + ''; + }; + }); +} diff --git a/flake.nix b/flake.nix index 3f7da81..14c023e 100644 --- a/flake.nix +++ b/flake.nix @@ -60,6 +60,15 @@ ${mac-app-util}/bin/mac-app-util sync-trampolines "/Applications/Nix Apps" "/Applications/Nix Trampolines" ''; }; + lib.assembleBrewAppsInOneFolder = { pkgs, brewPackages }: + pkgs.runCommand "assembleBrewAppsInOneFolder" { } '' + mkdir --parents $out + for PACKAGE in ${builtins.concatStringsSep " " brewPackages}; do + for APP in "$PACKAGE"/*/*.app; do + ln --symbolic "$APP" "$out" + done + done + ''; } // (with flake-utils.lib; eachDefaultSystem (system: @@ -100,6 +109,19 @@ doInstallCheck = true; meta.license = pkgs.lib.licenses.agpl3Only; }) {}; + + shellHook = + let + is-on-mac = builtins.hasAttr system self.packages; + mac-app-util = self.packages.${system}.default; + in + pkgs.writeShellScriptBin "mac-app-util-shell-hook" ( + if is-on-mac then '' + fromDir="$1" + toDir="~/Applications/$2" + ${mac-app-util}/bin/mac-app-util sync-trampolines "$fromDir" "$toDir" + '' else "" + ); }; })); }