Skip to content

Commit

Permalink
refactor(templates): use mkShell & pass inputs to shell.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Jan 9, 2025
1 parent 1391456 commit c478421
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 68 deletions.
2 changes: 1 addition & 1 deletion modules/base/nix/overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# this file exists to work around issues with nixpkgs that may arise
# hopefully that means its empty a lot
# (final: prev: import ./fixes.nix final prev)
(final: prev: import ./fixes.nix final prev)

# we minimize the amount of packages that are installed
(_: prev: import ./nix.nix { inherit config prev; })
Expand Down
19 changes: 18 additions & 1 deletion modules/base/nix/overlays/fixes.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
_: _: {
_: prev: {
# https://github.com/NixOS/nixpkgs/pull/371815
matrix-synapse-unwrapped = prev.matrix-synapse-unwrapped.overrideAttrs (oa: {
patches = [
(prev.fetchpatch2 {
url = "https://github.com/element-hq/synapse/commit/3eb92369ca14012a07da2fbf9250e66f66afb710.patch";
sha256 = "sha256-VDn3kQy23+QC2WKhWfe0FrUOnLuI1YwH5GxdTTVWt+A=";
})
];

postPatch =
oa.postPatch or ""
+ ''
substituteInPlace tests/storage/databases/main/test_events_worker.py \
--replace-fail "def test_recovery" "def no_test_recovery"
'';

nativeCheckInputs = builtins.filter (p: !p.meta.broken) oa.nativeCheckInputs;
});
}
4 changes: 2 additions & 2 deletions modules/flake/templates/c/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
};

outputs =
{ self, nixpkgs }:
{ self, nixpkgs }@inputs:
let
forAllSystems =
function:
Expand All @@ -21,7 +21,7 @@
});

devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
default = pkgs.callPackage ./shell.nix { inherit inputs; };
});

overlays.default = final: _: { example = final.callPackage ./default.nix { }; };
Expand Down
21 changes: 13 additions & 8 deletions modules/flake/templates/c/shell.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{
stdenv,
mkShellNoCC,

# extra tooling
libcxx,
gnumake,
cppcheck,
clang-tools,
callPackage,

inputs, # our inputs
self ? inputs.self,
}:
let
mainPkg = callPackage ./default.nix { };
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs = [
mkShellNoCC {
inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ];

packages = [
libcxx # stdlib for cpp
gnumake # builder
cppcheck # static analysis
clang-tools # fix headers not found
] ++ (oa.nativeBuildInputs or [ ]);
})
];
}
4 changes: 2 additions & 2 deletions modules/flake/templates/go/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
};

outputs =
{ self, nixpkgs }:
{ self, nixpkgs }@inputs:
let
forAllSystems =
function:
Expand All @@ -21,7 +21,7 @@
});

devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
default = pkgs.callPackage ./shell.nix { inherit inputs; };
});

overlays.default = final: _: { example = final.callPackage ./default.nix { }; };
Expand Down
21 changes: 13 additions & 8 deletions modules/flake/templates/go/shell.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
stdenv,
mkShellNoCC,

# extra tooling
go,
gopls,
goreleaser,
callPackage,

inputs, # our inputs
self ? inputs.self,
}:
let
mainPkg = callPackage ./default.nix { };
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs = [
mkShellNoCC {
inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ];

packages = [
go
gopls
goreleaser
] ++ (oa.nativeBuildInputs or [ ]);
})
];
}
4 changes: 2 additions & 2 deletions modules/flake/templates/latex/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
};

outputs =
{ self, nixpkgs }:
{ self, nixpkgs }@inputs:
let
forAllSystems =
function:
Expand All @@ -21,7 +21,7 @@
});

devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
default = pkgs.callPackage ./shell.nix { inherit inputs; };
});

overlays.default = final: _: { example = final.callPackage ./default.nix { }; };
Expand Down
26 changes: 17 additions & 9 deletions modules/flake/templates/latex/shell.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
stdenv,
mkShellNoCC,

# extra tooling
just,
texlive,
callPackage,
...

inputs, # our inputs
self ? inputs.self,
}:
let
mainPkg = callPackage ./default.nix { };
in
mainPkg.overrideAttrs (oa: {
buildInputs = [
mkShellNoCC {
inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ];

packages = [
just

(texlive.combine {
Expand All @@ -19,5 +23,9 @@ mainPkg.overrideAttrs (oa: {
pdfpages
;
})
] ++ (oa.nativeBuildInputs or [ ]);
})
];

shellHook = ''
echo "Hello, world!"
'';
}
4 changes: 2 additions & 2 deletions modules/flake/templates/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
};

outputs =
{ self, nixpkgs }:
{ self, nixpkgs }@inputs:
let
forAllSystems =
function:
Expand All @@ -21,7 +21,7 @@
});

devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
default = pkgs.callPackage ./shell.nix { inherit inputs; };
});

overlays.default = final: _: { example = final.callPackage ./default.nix { }; };
Expand Down
22 changes: 14 additions & 8 deletions modules/flake/templates/nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
eza,
callPackage,
stdenv,
mkShellNoCC,

inputs, # our inputs
self ? inputs.self,
}:
let
mainPkg = callPackage ./default.nix { };
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs = [ eza ] ++ (oa.nativeBuildInputs or [ ]);
})
mkShellNoCC {
inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ];

packages = [ ];

shellHook = ''
echo "Hello, world!"
'';
}
4 changes: 2 additions & 2 deletions modules/flake/templates/node/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
};

outputs =
{ self, nixpkgs }:
{ self, nixpkgs }@inputs:
let
forAllSystems =
function:
Expand All @@ -21,7 +21,7 @@
});

devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
default = pkgs.callPackage ./shell.nix { inherit inputs; };
});

overlays.default = final: _: { example = final.callPackage ./default.nix { }; };
Expand Down
27 changes: 15 additions & 12 deletions modules/flake/templates/node/shell.nix
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
stdenv,
mkShellNoCC,

# extra tooling
eslint_d,
prettierd,
callPackage,
writeShellScriptBin,
typescript,

inputs, # our inputs
self ? inputs.self,
}:
let
mainPkg = callPackage ./default.nix { };
mkNpxAlias = name: writeShellScriptBin name "npx ${name} \"$@\"";
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs = [
mkShellNoCC {
inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ];

packages = [
eslint_d
prettierd
(mkNpxAlias "tsc")
(mkNpxAlias "tsserver")
] ++ (oa.nativeBuildInputs or [ ]);
typescript
];

shellHook = ''
eslint_d start # start eslint daemon
eslint_d status # inform user about eslint daemon status
'';
})
}
4 changes: 2 additions & 2 deletions modules/flake/templates/rust/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
};

outputs =
{ self, nixpkgs }:
{ self, nixpkgs }@inputs:
let
forAllSystems =
function:
Expand All @@ -21,7 +21,7 @@
});

devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
default = pkgs.callPackage ./shell.nix { inherit inputs; };
});

overlays.default = final: _: { example = final.callPackage ./default.nix { }; };
Expand Down
22 changes: 13 additions & 9 deletions modules/flake/templates/rust/shell.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
stdenv,
mkShell,

# extra tooling
clippy,
rustfmt,
callPackage,
rust-analyzer,

inputs, # our inputs
self ? inputs.self,
}:
let
mainPkg = callPackage ./default.nix { };
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs = [
# Additional rust tooling
mkShell {
inputsFrom = [ self.packages.${stdenv.hostPlatform.system}.default ];

packages = [
clippy
rustfmt
rust-analyzer
] ++ (oa.nativeBuildInputs or [ ]);
})
];
}

0 comments on commit c478421

Please sign in to comment.