diff --git a/apps.nix b/apps.nix new file mode 100644 index 0000000..18fb18d --- /dev/null +++ b/apps.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: +let + appEnv = pkgs.buildEnv { + name = "home-manager-applications"; + paths = config.home.packages; + pathsToLink = "/Applications"; + }; +in { + home.activation.addApplications = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + # Install MacOS applications to the user environment. + HM_APPS="$HOME/Applications/Home Manager Apps" + # Reset current state + [ -e "$HM_APPS" ] && $DRY_RUN_CMD rm -r "$HM_APPS" + $DRY_RUN_CMD mkdir -p "$HM_APPS" + # .app dirs need to be actual directories for Finder to detect them as Apps. + # In the env of Apps we build, the .apps are symlinks. We pass all of them as + # arguments to cp and make it dereference those using -H + $DRY_RUN_CMD cp --archive -H --dereference ${appEnv}/Applications/* "$HM_APPS" + $DRY_RUN_CMD chmod +w -R "$HM_APPS" + ''; +} diff --git a/flake.lock b/flake.lock index c79c9cd..2b94f07 100644 --- a/flake.lock +++ b/flake.lock @@ -53,6 +53,22 @@ "type": "github" } }, + "nixpkgs-willem": { + "locked": { + "lastModified": 1672791794, + "narHash": "sha256-mqGPpGmwap0Wfsf3o2b6qHJW1w2kk/I6cGCGIU+3t6o=", + "ref": "master", + "rev": "9813adc7f7c0edd738c6bdd8431439688bb0cb3d", + "revCount": 439706, + "type": "git", + "url": "file:///Users/willem/dev/nixpkgs" + }, + "original": { + "ref": "master", + "type": "git", + "url": "file:///Users/willem/dev/nixpkgs" + } + }, "nur": { "locked": { "lastModified": 1672325070, @@ -73,6 +89,7 @@ "home-manager": "home-manager", "nixpkgs-22_11": "nixpkgs-22_11", "nixpkgs-unstable": "nixpkgs-unstable", + "nixpkgs-willem": "nixpkgs-willem", "nur": "nur" } }, diff --git a/flake.nix b/flake.nix index 8fb97c0..cf8802d 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,7 @@ description = "Willem's Home Manager configuration"; inputs = { + nixpkgs-willem.url = "git+file:///Users/willem/dev/nixpkgs?ref=master"; nixpkgs-22_11.url = "github:NixOS/nixpkgs/nixos-22.11"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; home-manager = { diff --git a/home.nix b/home.nix index 276a671..4c08fd9 100644 --- a/home.nix +++ b/home.nix @@ -4,7 +4,8 @@ let homeDirectory = config.home.homeDirectory; emacsCommand = [ "emacsclient" "-c" "-nw" ]; in { - imports = [ ./emacs.nix ./launchd.nix ./packages.nix ./programs.nix ]; + imports = + [ ./emacs.nix ./launchd.nix ./packages.nix ./programs.nix ./apps.nix ]; nixpkgs.config = { allowUnfree = true; @@ -37,4 +38,9 @@ in { home.file.".gnupg/gpg-agent.conf".text = '' pinentry-program "${pkgs.pinentry_mac}/Applications/pinentry-mac.app/Contents/MacOS/pinentry-mac" ''; + + home.file.".config/nix/nix.conf".text = '' + allow-dirty = true + experimental-features = flakes nix-command + ''; } diff --git a/packages.nix b/packages.nix index 0b62300..1f74875 100644 --- a/packages.nix +++ b/packages.nix @@ -2,8 +2,15 @@ { home.packages = with pkgs; - [ coreutils gnused spoof-mac colima pinentry_mac iterm2 ] ++ [ discord ] - ++ [ docker docker-compose ] ++ [ + [ + coreutils + gnused + spoof-mac + colima + pinentry_mac + iterm2 + (pkgs.callPackage ./spotify-mac.nix { }) + ] ++ [ discord ] ++ [ docker docker-compose ] ++ [ zsh-powerlevel10k comma automake diff --git a/programs.nix b/programs.nix index dc89868..ecd9e34 100644 --- a/programs.nix +++ b/programs.nix @@ -31,8 +31,11 @@ key = "C3DE5DF6198DACBD"; signByDefault = true; }; - extraConfig.init.defaultBranch = "master"; - extraConfig.core.autocrlf = false; + extraConfig = { + init.defaultBranch = "master"; + core.autocrlf = false; + push.autoSetupRemote = true; + }; package = pkgs.gitAndTools.gitFull; userName = "willemml"; userEmail = "willem@leit.so"; diff --git a/spotify-mac.nix b/spotify-mac.nix new file mode 100644 index 0000000..a538612 --- /dev/null +++ b/spotify-mac.nix @@ -0,0 +1,42 @@ +{ stdenv, lib, config, pkgs, ... }: + +stdenv.mkDerivation { + name = "spotify-mac-app"; + + sourceRoot = "."; + + nativeBuildInputs = [ pkgs.undmg pkgs.makeWrapper pkgs.perl pkgs.unzip pkgs.zip ]; + + src = pkgs.fetchurl { + url = "https://download.scdn.co/Spotify.dmg"; + hash = "sha256-9Ts6064YaZdjbRN28qkZcrwTH+63drC/jUfTGLvpBNc="; + }; + + spotxsrc = pkgs.fetchFromGitHub { + name = "spotx-mac-src"; + owner = "willemml"; + repo = "SpotX-Mac"; + rev = "03ea3aa59e135b9e2f68b6c8f4d4debe2b207830"; + hash = "sha256-H3QxmM0ALtz58MKaQ6pFcK6wP8oMWufvQ2q2ZjpO5Gs="; + }; + + installPhase = '' + runHook preInstall + + mkdir -p $out/Applications + cp -r "Spotify.app" $out/Applications + + # wrap executable to $out/bin + mkdir -p $out/bin + makeWrapper "$out/Applications/Spotify.app/Contents/MacOS/Spotify" "$out/bin/Spotify" + + cp "$spotxsrc/install.sh" install.sh + + chmod +x install.sh + + ./install.sh -a "$out/Applications/Spotify.app" + + runHook postInstall + ''; +} +