Skip to content

Commit

Permalink
Merge master into staging-next
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jun 9, 2024
2 parents e807ccc + 2a823de commit 4f7f106
Show file tree
Hide file tree
Showing 94 changed files with 2,207 additions and 926 deletions.
61 changes: 53 additions & 8 deletions doc/languages-frameworks/haskell.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,59 @@ for this to work.

`justStaticExecutables drv`
: Only build and install the executables produced by `drv`, removing everything
that may refer to other Haskell packages' store paths (like libraries and
documentation). This dramatically reduces the closure size of the resulting
derivation. Note that the executables are only statically linked against their
Haskell dependencies, but will still link dynamically against libc, GMP and
other system library dependencies. If dependencies use their Cabal-generated
`Paths_*` module, this may not work as well if GHC's dead code elimination
is unable to remove the references to the dependency's store path that module
contains.
that may refer to other Haskell packages' store paths (like libraries and
documentation). This dramatically reduces the closure size of the resulting
derivation. Note that the executables are only statically linked against their
Haskell dependencies, but will still link dynamically against libc, GMP and
other system library dependencies.

If the library being built or its dependencies use their Cabal-generated
`Paths_*` module, this may not work as well if GHC's dead code elimination is
unable to remove the references to the dependency's store path that module
contains. (See [nixpkgs#164630][164630] for more information.)

Importing the `Paths_*` module may cause builds to fail with this message:

```
error: output '/nix/store/64k8iw0ryz76qpijsnl9v87fb26v28z8-my-haskell-package-1.0.0.0' is not allowed to refer to the following paths:
/nix/store/5q5s4a07gaz50h04zpfbda8xjs8wrnhg-ghc-9.6.3
```

If that happens, first disable the check for GHC references and rebuild the
derivation:

```nix
pkgs.haskell.lib.overrideCabal
(pkgs.haskell.lib.justStaticExecutables my-haskell-package)
(drv: {
disallowGhcReference = false;
})
```

Then use `strings` to determine which libraries are responsible:

```
$ nix-build ...
$ strings result/bin/my-haskell-binary | grep /nix/store/
...
/nix/store/n7ciwdlg8yyxdhbrgd6yc2d8ypnwpmgq-hs-opentelemetry-sdk-0.0.3.6/bin
...
```

Finally, use `remove-references-to` to delete those store paths from the produced output:

```nix
pkgs.haskell.lib.overrideCabal
(pkgs.haskell.lib.justStaticExecutables my-haskell-package)
(drv: {
postInstall = ''
${drv.postInstall or ""}
remove-references-to -t ${pkgs.haskellPackages.hs-opentelemetry-sdk}
'';
})
```

[164630]: https://github.com/NixOS/nixpkgs/issues/164630

`enableSeparateBinOutput drv`
: Install executables produced by `drv` to a separate `bin` output. This
Expand Down
5 changes: 5 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22520,6 +22520,11 @@
githubId = 46590321;
name = "xrelkd";
};
xtrayambak = {
github = "xTrayambak";
githubId = 59499552;
name = "Trayambak Rai";
};
xurei = {
email = "[email protected]";
github = "xurei";
Expand Down
8 changes: 8 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
before changing the package to `pkgs.stalwart-mail` in
[`services.stalwart-mail.package`](#opt-services.stalwart-mail.package).

- `haskell.lib.compose.justStaticExecutables` now disallows references to GHC in the
output by default, to alert users to closure size issues caused by
[#164630](https://github.com/NixOS/nixpkgs/issues/164630). See ["Packaging
Helpers" in the Haskell section of the Nixpkgs
manual](https://nixos.org/manual/nixpkgs/unstable/#haskell-packaging-helpers)
for information on working around `output '...' is not allowed to refer to
the following paths` errors caused by this change.

- The `stalwart-mail` module now uses RocksDB as the default storage backend
for `stateVersion` ≥ 24.11. (It was previously using SQLite for structured
data and the filesystem for blobs).
Expand Down
3 changes: 2 additions & 1 deletion nixos/modules/services/audio/alsa.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ in
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
ExecStart = "${alsa-utils}/sbin/alsactl restore --ignore";
ExecStop = "${alsa-utils}/sbin/alsactl store --ignore";
};
};
Expand Down
28 changes: 19 additions & 9 deletions pkgs/applications/misc/darkman/default.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
{ lib, fetchFromGitLab, buildGoModule, scdoc, nix-update-script }:
{ lib
, fetchFromGitLab
, buildGoModule
, scdoc
, nix-update-script
}:

buildGoModule rec {
pname = "darkman";
version = "1.5.4";
version = "2.0.1";

src = fetchFromGitLab {
owner = "WhyNotHugo";
repo = "darkman";
rev = "v${version}";
sha256 = "sha256-6SNXVe6EfVwcXH9O6BxNw+v4/uhKhCtVS3XE2GTc2Sc=";
sha256 = "sha256-FaEpVy/0PqY5Bmw00hMyFZb9wcwYwEuCKMatYN8Xk3o=";
};

vendorHash = "sha256-xEPmNnaDwFU4l2G4cMvtNeQ9KneF5g9ViQSFrDkrafY=";

nativeBuildInputs = [ scdoc ];
patches = [
./go-mod.patch
./makefile.patch
];

postPatch = ''
substituteInPlace darkman.service \
--replace "/usr/bin/darkman" "$out/bin/darkman"
--replace-fail /usr/bin/darkman $out/bin/darkman
substituteInPlace contrib/dbus/nl.whynothugo.darkman.service \
--replace "/usr/bin/darkman" "$out/bin/darkman"
--replace-fail /usr/bin/darkman $out/bin/darkman
substituteInPlace contrib/dbus/org.freedesktop.impl.portal.desktop.darkman.service \
--replace "/usr/bin/darkman" "$out/bin/darkman"
--replace-fail /usr/bin/darkman $out/bin/darkman
'';

vendorHash = "sha256-3lILSVm7mtquCdR7+cDMuDpHihG+gDJTcQa1cM2o7ZU=";
nativeBuildInputs = [ scdoc ];

buildPhase = ''
runHook preBuild
make build
Expand All @@ -32,6 +41,7 @@ buildGoModule rec {

installPhase = ''
runHook preInstall
install -Dm755 darkman -t $out/bin
make PREFIX=$out install
runHook postInstall
'';
Expand Down
28 changes: 28 additions & 0 deletions pkgs/applications/misc/darkman/go-mod.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/go.mod b/go.mod
index 2d396a4..c4fea4b 100644
--- a/go.mod
+++ b/go.mod
@@ -1,14 +1,19 @@
module gitlab.com/WhyNotHugo/darkman

-go 1.16
+go 1.18

require (
github.com/adrg/xdg v0.3.3
github.com/godbus/dbus/v5 v5.0.4
- github.com/kr/pretty v0.2.0 // indirect
github.com/rxwycdh/rxhash v0.0.0-20230131062142-10b7a38b400d
github.com/sj14/astral v0.1.2
- github.com/spf13/cobra v1.7.0 // indirect
- gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
+ github.com/spf13/cobra v1.7.0
gopkg.in/yaml.v3 v3.0.1
)
+
+require (
+ github.com/inconshreveable/mousetrap v1.1.0 // indirect
+ github.com/kr/pretty v0.2.0 // indirect
+ github.com/spf13/pflag v1.0.5 // indirect
+ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
+)
12 changes: 12 additions & 0 deletions pkgs/applications/misc/darkman/makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/Makefile b/Makefile
index 9048e45..0fb1f5a 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,6 @@ site/index.html: darkman.1
mandoc -T html -O style=man-style.css < darkman.1 > site/index.html

install: build
- @install -Dm755 darkman ${DESTDIR}${PREFIX}/bin/darkman
@install -Dm644 darkman.service ${DESTDIR}${PREFIX}/lib/systemd/user/darkman.service
@install -Dm644 darkman.1 ${DESTDIR}${PREFIX}/share/man/man1/darkman.1
@install -Dm644 LICENCE ${DESTDIR}${PREFIX}/share/licenses/darkman/LICENCE
79 changes: 30 additions & 49 deletions pkgs/applications/misc/gitit/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, haskellPackages, haskell, removeReferencesTo
{ lib, stdenv, haskellPackages, haskell
# “Plugins” are a fancy way of saying gitit will invoke
# GHC at *runtime*, which in turn makes it pull GHC
# into its runtime closure. Only enable if you really need
Expand All @@ -7,55 +7,36 @@
, pluginSupport ? false
}:

# this is similar to what we do with the pandoc executable

let
plain = haskellPackages.gitit;
plugins =
if pluginSupport
then plain
else haskell.lib.compose.disableCabalFlag "plugins" plain;
static = haskell.lib.compose.justStaticExecutables plugins;
inherit (haskell.lib.compose)
enableCabalFlag
disableCabalFlag
justStaticExecutables
overrideCabal
;

in
(haskell.lib.compose.overrideCabal (drv: {
buildTools = (drv.buildTools or []) ++ [ removeReferencesTo ];
}) static).overrideAttrs (drv: {
base = (if pluginSupport then enableCabalFlag else disableCabalFlag)
"plugins"
haskellPackages.gitit;

# These libraries are still referenced, because they generate
# a `Paths_*` module for figuring out their version.
# The `Paths_*` module is generated by Cabal, and contains the
# version, but also paths to e.g. the data directories, which
# lead to a transitive runtime dependency on the whole GHC distribution.
# This should ideally be fixed in haskellPackages (or even Cabal),
# but a minimal gitit is important enough to patch it manually.
disallowedReferences = [
haskellPackages.pandoc-types
haskellPackages.HTTP
haskellPackages.pandoc
haskellPackages.happstack-server
haskellPackages.filestore
];
postInstall = ''
remove-references-to \
-t ${haskellPackages.pandoc-types} \
$out/bin/gitit
remove-references-to \
-t ${haskellPackages.HTTP} \
$out/bin/gitit
remove-references-to \
-t ${haskellPackages.pandoc} \
$out/bin/gitit
remove-references-to \
-t ${haskellPackages.happstack-server} \
$out/bin/gitit
remove-references-to \
-t ${haskellPackages.filestore} \
$out/bin/gitit
'';
# Removes erroneous references from dead code that GHC can't eliminate
aarch64DarwinFix = overrideCabal (drv:
lib.optionalAttrs (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) {
postInstall = ''
${drv.postInstall or ""}
remove-references-to -t ${haskellPackages.HTTP} "$out/bin/gitit"
remove-references-to -t ${haskellPackages.HTTP} "$out/bin/expireGititCache"
remove-references-to -t ${haskellPackages.happstack-server} "$out/bin/gitit"
remove-references-to -t ${haskellPackages.hoauth2} "$out/bin/gitit"
remove-references-to -t ${haskellPackages.pandoc} "$out/bin/gitit"
remove-references-to -t ${haskellPackages.pandoc-types} "$out/bin/gitit"
'';
});
in

meta = drv.meta // {
maintainers = drv.meta.maintainers or []
++ [ lib.maintainers.Profpatsch ];
};
})
if pluginSupport
then base
else lib.pipe (base.override { ghc-paths = null; }) [
justStaticExecutables
aarch64DarwinFix
]
Loading

0 comments on commit 4f7f106

Please sign in to comment.