From 0055f4c9b36f185b217c632340a1fc45dd3e1098 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Mon, 14 Feb 2022 00:56:43 +0000 Subject: [PATCH] Add link and unlink apps --- flake.nix | 17 ++++++++++++++++- home-modules/common.nix | 4 ++++ util.nix | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index fa49fa5..40febd0 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ let inherit (builtins) mapAttrs attrValues; inherit (lib.flake) eachDefaultSystem; - inherit (lib.my) mkApp mkShellApp inlineModules mkDefaultSystemsPkgs flakePackageOverlay; + inherit (lib.my) mkApp mkShellApp mkShellApp' inlineModules mkDefaultSystemsPkgs flakePackageOverlay; extendLib = lib: lib.extend (final: prev: { my = import ./util.nix { lib = final; }; @@ -108,6 +108,8 @@ } // (eachDefaultSystem (system: let + homeFlake = "$HOME/.config/nixpkgs/flake.nix"; + pkgs = pkgs'.unstable.${system}; lib = pkgs.lib; in @@ -115,6 +117,19 @@ { apps = { fmt = mkShellApp pkgs "fmt" ''exec "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" "$@" .''; + link = mkShellApp' pkgs { + name = "install-home-link"; + runtimeInputs = [ pkgs.coreutils ]; + text = + '' + [ -e "${homeFlake}" ] && echo "${homeFlake} already exists" && exit 1 + + mkdir -p "$(dirname "${homeFlake}")" + ln -s "$(pwd)/flake.nix" "${homeFlake}" + echo "Installed link to $(pwd)/flake.nix at ${homeFlake}" + ''; + }; + unlink = mkShellApp pkgs "remove-home-link" ''rm -f ${homeFlake}''; }; devShell = pkgs.mkShell { diff --git a/home-modules/common.nix b/home-modules/common.nix index 7fafa23..3c1c213 100644 --- a/home-modules/common.nix +++ b/home-modules/common.nix @@ -14,6 +14,10 @@ mkMerge [ enable = true; settings = {}; }; + + lsd = { + enable = mkDefault true; + }; }; home = { diff --git a/util.nix b/util.nix index d4b6087..f4b156c 100644 --- a/util.nix +++ b/util.nix @@ -24,6 +24,10 @@ rec { mkDefaultSystemsPkgs = path: args': genAttrs defaultSystems (system: import path ((args' system) // { inherit system; })); mkApp = program: { type = "app"; inherit program; }; mkShellApp = pkgs: name: text: mkApp (pkgs.writeShellScript name text).outPath; + mkShellApp' = pkgs: args: + let + app = pkgs.writeShellApplication args; + in mkApp "${app}/bin/${app.meta.mainProgram}"; inlineModules = modules: mapAttrs (_: path: {