Skip to content

Commit cad397b

Browse files
authored
Merge pull request #4 from midirhee12/main
2 parents 053de7f + c68d65a commit cad397b

File tree

4 files changed

+93
-70
lines changed

4 files changed

+93
-70
lines changed

.envrc

Lines changed: 0 additions & 50 deletions
This file was deleted.

flake.lock

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,63 @@
11
{
22
description = "All Thing's Linux discord bot - Tux";
33

4-
inputs.nixpkgs = {
5-
type = "github";
6-
owner = "NixOS";
7-
repo = "nixpkgs";
8-
ref = "nixos-unstable";
4+
inputs = {
5+
nixpkgs = {
6+
type = "github";
7+
owner = "NixOS";
8+
repo = "nixpkgs";
9+
ref = "nixos-unstable";
10+
};
11+
12+
flake-parts = {
13+
type = "github";
14+
owner = "hercules-ci";
15+
repo = "flake-parts";
16+
ref = "main";
17+
};
918
};
1019

11-
outputs = {
20+
outputs = inputs@{
1221
self,
1322
nixpkgs,
23+
flake-parts,
1424
...
1525
}:
16-
let
17-
supportedSystems = [
26+
flake-parts.lib.mkFlake { inherit inputs; } {
27+
systems = [
1828
"x86_64-linux"
1929
"x86_64-darwin"
2030
"aarch64-linux"
2131
"aarch64-darwin"
2232
];
2333

24-
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
25-
in {
26-
devShells = forAllSystems (system: let
27-
pkgs = nixpkgs.legacyPackages.${system};
28-
in {
29-
tux = pkgs.callPackage ./shell.nix { inherit pkgs; };
30-
default = self.devShells.${system}.tux;
31-
});
34+
perSystem = { pkgs, self', system, ... }: {
35+
devShells = {
36+
default = self'.devShells.tux;
37+
tux = pkgs.callPackage ./shell.nix { inherit pkgs self; };
38+
};
39+
40+
apps.envrc = {
41+
type = "app";
42+
program = self'.packages.envrc;
43+
};
44+
45+
# Creates .envrc if does not exist
46+
packages.envrc = pkgs.writeShellScriptBin "envrc" ''
47+
echo
48+
49+
if [ ! -e ".envrc" ]; then
50+
echo "Creating .envrc"
51+
printf "use flake .\n\n\n" | cat - .env.example > .envrc
52+
echo
53+
54+
echo "The directory is now set up for direnv usage."
55+
echo
56+
else
57+
echo "Please delete .envrc if you wish to recreate it."
58+
echo
59+
fi
60+
'';
61+
};
3262
};
3363
}

shell.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
{ pkgs ? import <nixpkgs> {} }:
1+
{ pkgs ? import <nixpkgs> {}, self ? null }:
22

33
pkgs.mkShell {
4+
buildInputs = if self == null then [] else [
5+
self.packages.${pkgs.system}.envrc
6+
];
7+
48
packages = with pkgs; [
59
python313
610
poetry
@@ -9,10 +13,15 @@ pkgs.mkShell {
913
];
1014

1115
shellHook = ''
12-
# enters the user's preferred shell using a more robust method
16+
# See perSystem.packages.envrc
17+
if command -v envrc >/dev/null 2>&1; then
18+
envrc
19+
fi
20+
21+
# Enters the user's preferred shell using a more robust method
1322
$(getent passwd $(id -un) | cut -d: -f7 | tr -d '\n')
1423
15-
# exits after child shell exits
24+
# Exits after child shell exits
1625
exit
1726
'';
1827
}

0 commit comments

Comments
 (0)