Skip to content

Commit 8dc5f92

Browse files
committed
feat(devshell): Add Nix devshell and update direnv to use nix-direnv 2.0.0
1 parent a33505c commit 8dc5f92

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Diff for: .envrc

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use_flake() {
2-
watch_file flake.nix
3-
watch_file flake.lock
4-
eval "$(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")"
5-
}
1+
# shellcheck shell=bash
62

3+
if ! has nix_direnv_version || ! nix_direnv_version 2.0.0; then
4+
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.0.0/direnvrc" "sha256-gMHKKyEOq/T0XmHKgz+pN+fUQC/1EKPAuOtYM95lLnU="
5+
fi
6+
7+
dotenv_if_exists
8+
nix_direnv_watch_file shell.nix
79
use flake

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Nix build artifacts
22
result
3+
4+
# Direnv
5+
.direnv

Diff for: flake.nix

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
defaultUser = "zlx";
3737
users = [defaultUser];
3838

39+
pkgs = nixpkgs.legacyPackages.${system};
40+
3941
machines = builtins.attrNames (
4042
nixpkgs.lib.filterAttrs
4143
(n: v: v == "directory")
@@ -85,5 +87,6 @@
8587
nixosConfigurations = builtins.listToAttrs (builtins.map (makeMachineConfig defaultUser) machines);
8688
homeConfigurations = builtins.listToAttrs (builtins.map makeHomeConfig users);
8789
nixOnDroidConfigurations = {device = makeNixOnDroidConfig defaultUser;};
90+
devShells."${system}".default = import ./shell.nix { inherit pkgs; };
8891
};
8992
}

Diff for: shell.nix

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{ pkgs }: with pkgs;
2+
mkShell {
3+
buildInputs = [
4+
figlet
5+
];
6+
7+
shellHook = ''
8+
local remote_url="$(git config --get remote.origin.url)"
9+
project_path=$(echo "$remote_url" | sed -E 's"(git@|.+://)[^:/]+[:/](.+)/.+$"\2"')
10+
repo_name=$(echo "$remote_url" | sed -E -e 's|.+/(.+)$|\1|' -e 's|(.+)(.git)$|\1|')
11+
12+
figlet "Welcome to $project_path's $repo_name"
13+
'';
14+
}

0 commit comments

Comments
 (0)