Skip to content

Commit 9a5aded

Browse files
committed
build(nix): allow platform specific
1 parent f867de1 commit 9a5aded

File tree

9 files changed

+55
-17
lines changed

9 files changed

+55
-17
lines changed

core/default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
};
2222

2323
config = {
24+
nixpkgs.config = {
25+
allowUnfree = true;
26+
allowBroken = true;
27+
};
2428
nix.settings.experimental-features = "nix-command flakes";
2529

2630
environment.systemPackages = config.nixpkgs.add;
@@ -34,7 +38,7 @@
3438
homebrew = {
3539
enable = true;
3640
global.autoUpdate = true;
37-
taps = config.brew.add.taps;
41+
# taps = config.brew.add.taps;
3842
brews = config.brew.add.formula;
3943
casks = config.brew.add.cask;
4044

core/package.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
{ lib, profile, config }: {
1+
{ lib, profile, config, isDarwin }: {
22
mkPackage = name: {
33
optional ? false,
44
only ? [],
55
except ? [],
6+
platform ? [],
67
config ? {},
78
}:
89
let
910
inherit (lib) types;
11+
systemPlatform = if isDarwin then "darwin" else "linux";
1012
isEmpty = list: builtins.length list == 0;
11-
cfg = config.packages.${name} or { inherit optional only except; };
13+
cfg = config.packages.${name} or { inherit optional only except platform; };
1214
shouldInstall = (
1315
!cfg.optional &&
16+
(isEmpty cfg.platform || lib.elem systemPlatform cfg.platform) &&
1417
(isEmpty cfg.only || lib.elem profile cfg.only) &&
1518
!(lib.elem profile cfg.except)
1619
);
@@ -31,6 +34,11 @@
3134
default = except;
3235
description = "Excluded profiles.";
3336
};
37+
platform = lib.mkOption {
38+
type = types.listOf types.str;
39+
default = platform;
40+
description = "Allowed platforms (empty = all).";
41+
};
3442
};
3543

3644
config = lib.mkMerge [

core/profile.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ rec {
1616
}:
1717
let
1818
isDarwin = lib.hasSuffix "-darwin" system;
19-
homePath = if isDarwin then "/Users/${username}" else "/home/${username}";
2019
profile = name;
2120

2221
modules = [
@@ -27,7 +26,7 @@ rec {
2726
{
2827
darwinConfigurations.${name} = darwin.lib.darwinSystem {
2928
inherit system;
30-
specialArgs = { inherit profile username; };
29+
specialArgs = { inherit profile username isDarwin; };
3130
modules = modules ++ [
3231
homebrew.darwinModules.nix-homebrew {
3332
inherit lib;

migrate.sh

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
write_nix() {
44
cat <<'EOF'
5-
{ config, lib, pkgs, profile, ...}:
5+
{ config, lib, pkgs, profile, isDarwin, ...}:
66
let
77
package = import ../core/package.nix {
88
inherit lib;
99
inherit profile;
1010
inherit config;
11+
inherit isDarwin;
1112
};
1213
inherit (package) mkPackage;
1314
EOF
@@ -21,8 +22,11 @@ EOF
2122
if test -n "$4"; then
2223
printf ' except = [ %s ];\n' "$4"
2324
fi
25+
if test -n "$5"; then
26+
printf ' platform = [ %s ];\n' "$5"
27+
fi
2428
printf ' config = {\n'
25-
printf ' %s = [ %s ];\n' "$5" "$6"
29+
printf ' %s = [ %s ];\n' "$6" "$7"
2630
printf ' };\n}\n'
2731
}
2832

@@ -79,19 +83,40 @@ parse_profiles() {
7983
printf '%s' "$output"
8084
}
8185

86+
parse_platforms() {
87+
if test "$1" = "#"; then
88+
shift
89+
fi
90+
if test "$1" = "platform"; then
91+
shift
92+
else
93+
return
94+
fi
95+
output=""
96+
while test -n "$1"; do
97+
if test -n "$output"; then
98+
output="$output "
99+
fi
100+
output="\"$1\""
101+
shift
102+
done
103+
printf '%s' "$output"
104+
}
105+
82106
migrate_to_nix() {
83107
source="$1"
84108
destination="$(printf '%s' "$source" | sed 's/\.sh/.nix/')"
85109
package="$2"
86110
manager="$3"
87-
write_nix "$(basename "$1" | sed 's/\.sh$//' | normalize)" "$4" "$5" "$6" "$manager" "$package" >"$destination"
111+
write_nix "$(basename "$1" | sed 's/\.sh$//' | normalize)" "$4" "$5" "$6" "$7" "$manager" "$package" >"$destination"
88112
}
89113

90114
validate_package() {
91115
content="$(cat "$1")"
92116
optional=""
93117
only=""
94118
except=""
119+
platforms=""
95120
if contains "$content" optional; then
96121
optional="1"
97122
fi
@@ -100,17 +125,20 @@ validate_package() {
100125
only="$(parse_profiles only $profiles)"
101126
except="$(parse_profiles except $profiles)"
102127
fi
128+
if contains "$content" platform; then
129+
platforms="$(parse_platforms $(read_match "$content" platform))"
130+
fi
103131

104132
if contains "$content" "use_nix"; then
105-
migrate_to_nix "$1" "pkgs.$(read_match "$content" "use_nix" | item_at 3 | strip)" nixpkgs.add "$optional" "$only" "$except"
133+
migrate_to_nix "$1" "pkgs.$(read_match "$content" "use_nix" | item_at 3 | strip)" nixpkgs.add "$optional" "$only" "$except" "$platforms"
106134
elif contains "$content" "use_brew formula"; then
107-
migrate_to_nix "$1" "$(read_match "$content" "use_brew formula" | item_at 3 | normalize)" brew.add.formula "$optional" "$only" "$except"
135+
migrate_to_nix "$1" "$(read_match "$content" "use_brew formula" | item_at 3 | normalize)" brew.add.formula "$optional" "$only" "$except" "$platforms"
108136
elif contains "$content" "use_brew cask"; then
109-
migrate_to_nix "$1" "$(read_match "$content" "use_brew cask" | item_at 3 | normalize | xargs sh -c 'out="";for i in $*; do case "$1" in -*) continue;; *);; esac;if test -n "$out"; then out="$out ";fi;out="$out\"$i\""; done; printf "%s" "$out"' sh)" brew.add.cask "$optional" "$only" "$except"
137+
migrate_to_nix "$1" "$(read_match "$content" "use_brew cask" | item_at 3 | normalize | xargs sh -c 'out="";for i in $*; do case "$1" in -*) continue;; *);; esac;if test -n "$out"; then out="$out ";fi;out="$out\"$i\""; done; printf "%s" "$out"' sh)" brew.add.cask "$optional" "$only" "$except" "$platforms"
110138
elif contains "$content" "use_brew_tap"; then
111-
migrate_to_nix "$1" "$(read_match "$content" "use_brew_tap" | item_at 2 | normalize | xargs sh -c 'out="";for i in $*; do case "$1" in -*) continue;; *);; esac;if test -n "$out"; then out="$out ";fi;out="$out\"$i\""; done; printf "%s" "$out"' sh)" brew.add.tap "$optional" "$only" "$except"
139+
migrate_to_nix "$1" "$(read_match "$content" "use_brew_tap" | item_at 2 | normalize | xargs sh -c 'out="";for i in $*; do case "$1" in -*) continue;; *);; esac;if test -n "$out"; then out="$out ";fi;out="$out\"$i\""; done; printf "%s" "$out"' sh)" brew.add.tap "$optional" "$only" "$except" "$platforms"
112140
# elif contains "$content" "has_executable"; then
113-
# migrate_to_nix "$1" "pkgs.$(read_match "$content" "has_executable" | item_at 2 | strip)" nixpkgs.add "$optional" "$only" "$except"
141+
# migrate_to_nix "$1" "pkgs.$(read_match "$content" "has_executable" | item_at 2 | strip)" nixpkgs.add "$optional" "$only" "$except" "$platforms"
114142
else
115143
printf ' skipped\n'
116144
return 1

packages/cryptomator.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ profile -work
1616
has_app 'Cryptomator'
1717
require fuse-t
1818

19-
# use_nix 'cryptomator'
2019
use_brew cask 'cryptomator'

packages/ghostty.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ fi
1313

1414
has_app 'Ghostty'
1515

16-
# use_nix 'ghostty'
16+
# platform darwin
17+
# use_nix 'ghostty-bin'
1718
use_brew cask 'ghostty'

packages/proton-mail.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ fi
1414
has_app 'Proton Mail'
1515

1616
profile -work
17-
# use_nix 'protonmail-desktop'
1817
use_brew cask 'proton-mail'

packages/proton-pass.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ fi
1414
has_app 'Proton Pass'
1515

1616
profile -work
17-
# use_nix 'proton-pass'
1817
use_brew cask 'proton-pass'

packages/sysstat.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ fi
1313

1414
has_executable 'sysstat'
1515

16+
# platform linux
1617
# use_nix 'sysstat'
1718
use_apt 'sysstat'

0 commit comments

Comments
 (0)