From c4784217c01b73b8f9fb56aed0255c448b2081c4 Mon Sep 17 00:00:00 2001 From: isabel Date: Thu, 9 Jan 2025 16:07:57 +0000 Subject: [PATCH] refactor(templates): use mkShell & pass inputs to shell.nix --- modules/base/nix/overlays/default.nix | 2 +- modules/base/nix/overlays/fixes.nix | 19 ++++++++++++++++- modules/flake/templates/c/flake.nix | 4 ++-- modules/flake/templates/c/shell.nix | 21 +++++++++++-------- modules/flake/templates/go/flake.nix | 4 ++-- modules/flake/templates/go/shell.nix | 21 +++++++++++-------- modules/flake/templates/latex/flake.nix | 4 ++-- modules/flake/templates/latex/shell.nix | 26 +++++++++++++++--------- modules/flake/templates/nix/flake.nix | 4 ++-- modules/flake/templates/nix/shell.nix | 22 ++++++++++++-------- modules/flake/templates/node/flake.nix | 4 ++-- modules/flake/templates/node/shell.nix | 27 ++++++++++++++----------- modules/flake/templates/rust/flake.nix | 4 ++-- modules/flake/templates/rust/shell.nix | 22 +++++++++++--------- 14 files changed, 116 insertions(+), 68 deletions(-) diff --git a/modules/base/nix/overlays/default.nix b/modules/base/nix/overlays/default.nix index 22f2c82e2..27398ebc1 100644 --- a/modules/base/nix/overlays/default.nix +++ b/modules/base/nix/overlays/default.nix @@ -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; }) diff --git a/modules/base/nix/overlays/fixes.nix b/modules/base/nix/overlays/fixes.nix index e5e291621..6197bdd2e 100644 --- a/modules/base/nix/overlays/fixes.nix +++ b/modules/base/nix/overlays/fixes.nix @@ -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; + }); } diff --git a/modules/flake/templates/c/flake.nix b/modules/flake/templates/c/flake.nix index 34581583c..a15281ffb 100644 --- a/modules/flake/templates/c/flake.nix +++ b/modules/flake/templates/c/flake.nix @@ -6,7 +6,7 @@ }; outputs = - { self, nixpkgs }: + { self, nixpkgs }@inputs: let forAllSystems = function: @@ -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 { }; }; diff --git a/modules/flake/templates/c/shell.nix b/modules/flake/templates/c/shell.nix index e7f2c2642..b3f333fe0 100644 --- a/modules/flake/templates/c/shell.nix +++ b/modules/flake/templates/c/shell.nix @@ -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 [ ]); -}) + ]; +} diff --git a/modules/flake/templates/go/flake.nix b/modules/flake/templates/go/flake.nix index 92fbc6eac..57044a822 100644 --- a/modules/flake/templates/go/flake.nix +++ b/modules/flake/templates/go/flake.nix @@ -6,7 +6,7 @@ }; outputs = - { self, nixpkgs }: + { self, nixpkgs }@inputs: let forAllSystems = function: @@ -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 { }; }; diff --git a/modules/flake/templates/go/shell.nix b/modules/flake/templates/go/shell.nix index f0af32f48..405970f0b 100644 --- a/modules/flake/templates/go/shell.nix +++ b/modules/flake/templates/go/shell.nix @@ -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 [ ]); -}) + ]; +} diff --git a/modules/flake/templates/latex/flake.nix b/modules/flake/templates/latex/flake.nix index 3fd106ff8..13e927d82 100644 --- a/modules/flake/templates/latex/flake.nix +++ b/modules/flake/templates/latex/flake.nix @@ -6,7 +6,7 @@ }; outputs = - { self, nixpkgs }: + { self, nixpkgs }@inputs: let forAllSystems = function: @@ -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 { }; }; diff --git a/modules/flake/templates/latex/shell.nix b/modules/flake/templates/latex/shell.nix index 340fd0a6d..e398f00df 100644 --- a/modules/flake/templates/latex/shell.nix +++ b/modules/flake/templates/latex/shell.nix @@ -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 { @@ -19,5 +23,9 @@ mainPkg.overrideAttrs (oa: { pdfpages ; }) - ] ++ (oa.nativeBuildInputs or [ ]); -}) + ]; + + shellHook = '' + echo "Hello, world!" + ''; +} diff --git a/modules/flake/templates/nix/flake.nix b/modules/flake/templates/nix/flake.nix index 9e60e39fb..870f570f8 100644 --- a/modules/flake/templates/nix/flake.nix +++ b/modules/flake/templates/nix/flake.nix @@ -6,7 +6,7 @@ }; outputs = - { self, nixpkgs }: + { self, nixpkgs }@inputs: let forAllSystems = function: @@ -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 { }; }; diff --git a/modules/flake/templates/nix/shell.nix b/modules/flake/templates/nix/shell.nix index 92b046508..d87b70ad8 100644 --- a/modules/flake/templates/nix/shell.nix +++ b/modules/flake/templates/nix/shell.nix @@ -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!" + ''; +} diff --git a/modules/flake/templates/node/flake.nix b/modules/flake/templates/node/flake.nix index 9122ec842..47630236a 100644 --- a/modules/flake/templates/node/flake.nix +++ b/modules/flake/templates/node/flake.nix @@ -6,7 +6,7 @@ }; outputs = - { self, nixpkgs }: + { self, nixpkgs }@inputs: let forAllSystems = function: @@ -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 { }; }; diff --git a/modules/flake/templates/node/shell.nix b/modules/flake/templates/node/shell.nix index 944e0dc8c..c16b041d1 100644 --- a/modules/flake/templates/node/shell.nix +++ b/modules/flake/templates/node/shell.nix @@ -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 ''; -}) +} diff --git a/modules/flake/templates/rust/flake.nix b/modules/flake/templates/rust/flake.nix index c1719c6bc..71f48c39e 100644 --- a/modules/flake/templates/rust/flake.nix +++ b/modules/flake/templates/rust/flake.nix @@ -6,7 +6,7 @@ }; outputs = - { self, nixpkgs }: + { self, nixpkgs }@inputs: let forAllSystems = function: @@ -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 { }; }; diff --git a/modules/flake/templates/rust/shell.nix b/modules/flake/templates/rust/shell.nix index 5f95e7110..9326642df 100644 --- a/modules/flake/templates/rust/shell.nix +++ b/modules/flake/templates/rust/shell.nix @@ -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 [ ]); -}) + ]; +}