Skip to content

Commit

Permalink
feat(darwinProfiles): add nix
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 11, 2023
1 parent b83be2d commit 0a17a8c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions nixos/darwinProfiles/presets/nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
lib,
pkgs,
loadSubmodule,
}:
let
l = lib // builtins;
inherit (pkgs.stdenv.hostPlatform) isAarch64;
in
{
imports = [ (loadSubmodule ./optimise.nix) ];
nix = {
package = pkgs.nixUnstable;
configureBuildUsers = true;
settings = {
# Administrative users on Darwin systems are part of the admin group.
trusted-users = [ "@admin" ];
extra-platforms = l.mkIf isAarch64 [
"x86_64-darwin"
"aarch64-darwin"
];
auto-optimise-store = false;
experimental-features = [
"nix-command"
"flakes"
"recursive-nix"
];
sandbox = false;
# https://github.com/NixOS/nix/issues/7273
};
extraOptions = ''
# https://plutus-community.readthedocs.io/en/latest/#Environment/Build/Mac_M1/
extra-sandbox-paths = /System/Library/Frameworks /System/Library/PrivateFrameworks /usr/lib /private/tmp /private/var/tmp /usr/bin/env
'';
};
services.nix-daemon.enable = true;
# Recreate /run/current-system symlink after boot
# services.activate-system.enable = true;
}
33 changes: 33 additions & 0 deletions nixos/darwinProfiles/presets/nix/optimise.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# credit: https://github.com/montchr/dotfield/blob/68f6c9c3f6cc67c5c775b8a2a3f93cae6a76b3a5/profiles/darwinProfiles/core/nix-optimizations-darwin.nix#L9
{ config }:
{
nix.settings.auto-optimise-store = false;
# While it’s possible to set `auto-optimise-store` in `nix.conf`, it sometimes causes problems
# on Darwin. Run a job periodically to optimise the store.
launchd.daemons."nix-store-optimise".serviceConfig = {
ProgramArguments = [
"/bin/sh"
"-c"
''
/bin/wait4path ${config.nix.package}/bin/nix && \
exec ${config.nix.package}/bin/nix store optimise
''
];
StartCalendarInterval = [ {
Hour = 2;
Minute = 0;
} ];
StandardErrorPath = "/var/log/nix-store.log";
StandardOutPath = "/var/log/nix-store.log";
};

nix.gc = {
automatic = true;
interval = {
Weekday = 0;
Hour = 2;
Minute = 0;
};
options = "--delete-older-than 30d";
};
}
4 changes: 4 additions & 0 deletions tests/_snapshots/darwin
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
name = "font-fontawesome";
}
];
darwinNixProfile = ''
# https://plutus-community.readthedocs.io/en/latest/#Environment/Build/Mac_M1/
extra-sandbox-paths = /System/Library/Frameworks /System/Library/PrivateFrameworks /usr/lib /private/tmp /private/var/tmp /usr/bin/env
'';
}
6 changes: 6 additions & 0 deletions tests/darwin/expr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ in
darwinFontProfile =
(exporter.layouts.darwinConfiguration [
omnibus.darwinProfiles.presets.homebrew
omnibus.darwinProfiles.presets.nix
{ homebrew.__profiles__.fonts = true; }
]).config.homebrew.casks;

darwinNixProfile =
(exporter.layouts.darwinConfiguration [ omnibus.darwinProfiles.presets.nix ])
.config.nix.extraOptions;
}

// lib.optionalAttrs trace { }

0 comments on commit 0a17a8c

Please sign in to comment.