From fafb7d465633e950c21e07336dd963901c27f2e0 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Sat, 19 Feb 2022 23:34:41 +0000 Subject: [PATCH] Move devshell to subdirectory --- .envrc | 11 +++++ devshell/commands.nix | 52 ++++++++++++++++++++ devshell/default.nix | 25 ++++++++++ install.nix => devshell/install.nix | 0 flake.nix | 74 +---------------------------- 5 files changed, 90 insertions(+), 72 deletions(-) create mode 100644 devshell/commands.nix create mode 100644 devshell/default.nix rename install.nix => devshell/install.nix (100%) diff --git a/.envrc b/.envrc index f688e49..d8202b9 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,14 @@ +use_flake_extra_watch() { + watch_file devshell/* + for f in devshell/*; do + if [ "$f" -nt flake.nix ]; then + # nix-direnv doesn't check the dates on other files, so give it a kick via flake.nix + touch flake.nix + fi + done +} + +use flake_extra_watch use flake # devshell needs the shellHook to run even when cached diff --git a/devshell/commands.nix b/devshell/commands.nix new file mode 100644 index 0000000..0e18261 --- /dev/null +++ b/devshell/commands.nix @@ -0,0 +1,52 @@ +{ pkgs, ... }: +let + homeFlake = "$HOME/.config/nixpkgs/flake.nix"; +in +{ + commands = [ + { + name = "repl"; + category = "utilities"; + help = "Open a `nix repl` with this flake"; + command = + '' + tmp="$(mktemp --tmpdir repl.nix.XXXXX)" + echo "builtins.getFlake \"$PRJ_ROOT\"" > "$tmp" + nix repl "$tmp" || true + rm "$tmp" + ''; + } + { + name = "home-link"; + category = "utilities"; + help = "Install link to flake.nix for home-manager to use"; + command = + '' + [ -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}" + ''; + } + { + name = "home-unlink"; + category = "utilities"; + help = "Remove home-manager flake.nix link"; + command = "rm -f ${homeFlake}"; + } + + { + name = "fmt"; + category = "tasks"; + help = pkgs.nixpkgs-fmt.meta.description; + command = ''exec "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" "$@"''; + } + { + name = "home-switch"; + category = "tasks"; + help = "Run `home-manager switch`"; + command = ''home-manager switch --flake . "$@"''; + } + ]; +} diff --git a/devshell/default.nix b/devshell/default.nix new file mode 100644 index 0000000..23d94e1 --- /dev/null +++ b/devshell/default.nix @@ -0,0 +1,25 @@ +{ lib, pkgs, ... }: +let + inherit (lib.my) attrsToNVList; +in +{ + imports = [ ./commands.nix ./install.nix ]; + + env = attrsToNVList { + # starship will show this + name = "devshell"; + + NIX_USER_CONF_FILES = toString (pkgs.writeText "nix.conf" + '' + experimental-features = nix-command flakes ca-derivations + ''); + }; + + packages = with pkgs; [ + coreutils + nixVersions.stable + agenix + deploy-rs.deploy-rs + home-manager + ]; +} diff --git a/install.nix b/devshell/install.nix similarity index 100% rename from install.nix rename to devshell/install.nix diff --git a/flake.nix b/flake.nix index b0cafe4..3da2c81 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ inherit (builtins) mapAttrs attrValues; inherit (lib) recurseIntoAttrs filterAttrs; inherit (lib.flake) flattenTree eachDefaultSystem; - inherit (lib.my) attrsToNVList inlineModules mkDefaultSystemsPkgs flakePackageOverlay; + inherit (lib.my) inlineModules mkDefaultSystemsPkgs flakePackageOverlay; # Extend a lib with extras that _must not_ internally reference private nixpkgs. flake-utils doesn't, but many # other flakes (e.g. home-manager) probably do internally. @@ -141,8 +141,6 @@ } // (eachDefaultSystem (system: let - homeFlake = "$HOME/.config/nixpkgs/flake.nix"; - pkgs = pkgs'.unstable.${system}; lib = pkgs.lib; in @@ -153,74 +151,6 @@ deploy = recurseIntoAttrs (pkgs.deploy-rs.lib.deployChecks self.deploy); }; - # TODO: Move shell to a separate file? - devShell = pkgs.devshell.mkShell { - imports = [ ./install.nix ]; - - env = attrsToNVList { - # starship will show this - name = "devshell"; - - NIX_USER_CONF_FILES = toString (pkgs.writeText "nix.conf" - '' - experimental-features = nix-command flakes ca-derivations - ''); - }; - - packages = with pkgs; [ - coreutils - nixVersions.stable - agenix - deploy-rs.deploy-rs - home-manager - ]; - - commands = [ - { - name = "repl"; - category = "utilities"; - help = "Open a `nix repl` with this flake"; - command = - '' - tmp="$(mktemp --tmpdir repl.nix.XXXXX)" - echo "builtins.getFlake \"$PRJ_ROOT\"" > "$tmp" - nix repl "$tmp" || true - rm "$tmp" - ''; - } - { - name = "home-link"; - category = "utilities"; - help = "Install link to flake.nix for home-manager to use"; - command = - '' - [ -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}" - ''; - } - { - name = "home-unlink"; - category = "utilities"; - help = "Remove home-manager flake.nix link"; - command = "rm -f ${homeFlake}"; - } - - { - name = "fmt"; - category = "tasks"; - help = pkgs.nixpkgs-fmt.meta.description; - command = ''exec "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" "$@"''; - } - { - name = "home-switch"; - category = "tasks"; - help = "Run `home-manager switch`"; - command = ''home-manager switch --flake . "$@"''; - } - ]; - }; + devShell = pkgs.devshell.mkShell ./devshell; })); }