I have this simple module, that for some reason doesn’t work. If I remove the conditional (if isDarwin
) it works fine. But if I add the if statement back it doesn’t work. I have no idea why, the code seems correct for me & I have other modules with similar structures (without conditionals though) & they are working fine.
My setup is using flakes, nix-darwin & home-manager & I’m very much a beginner so I’m sure I’m doing lots of things wrong. My full setup is here it’s heavily WIP.
{ pkgs, lib, config, ... }:
with config.settings;
let
cfg = config.my.gui;
in {
options = with lib; {
my.gui = {
enable = mkEnableOption ''
Whether to enable gui module
'';
};
};
config = with lib;
mkIf cfg.enable {
users.users.${username} = {
packages = with pkgs;
[
slack
] ++ (if pkgs.stdenv.isDarwin then
[ ]
else [
brave
firefox
obsidian
zoom-us
]);
};
};
}
If I remove the conditional ( if isDarwin
) it works fine
do you mind pasting the error? Not sure if flakes is complaining about impure eval (which it shouldn’t, as your system should have been passed at this point), or something else.
(if pkgs.stdenv.isDarwin then
[ ]
else [
brave
firefox
obsidian
zoom-us
]
could be:
lib.optionals (!pkgs.stdenv.isDarwin) [
brave
firefox
obsidian
zoom-us
]
There is no error, that’s the issue & nix build
completes fine. But none of these packages gets installed, for example, Slack should be installed because it’s outside of the if/else. But it doesn’t get installed. If I remove the if/else it gets installed.
the Darwin list is empty for now, but I plan to add stuff there. So that’s why I need the if/else.
I’m not sure, seems like it should be right since you specified system here: https://github.com/ahmedelgabri/dotfiles/blob/7e1bd6644be7160842985b893908ea782d7e4fec/flake.nix#L112. I would just verify that stdenv.isDarwin
is giving you what want.
Ok, it looks like it installs Slack but doesn’t symlink it to ~/Applications
because I found Slack.app in the store… I also tested the isDarwin
by add [ hello ]
there & that was installed properly.
https://github.com/NixOS/nixpkgs/blob/d70b9c4c557b8964760044a5440a0416e86e40d5/pkgs/applications/networking/instant-messengers/slack/default.nix#L172-L174
So it seems that the condition is fine, but the symlinking is not working for some reason… I confirmed that by adding one of my own to this list & indeed the symlink was removed from ~/Application
https://github.com/ahmedelgabri/dotfiles/blob/7e1bd6644be7160842985b893908ea782d7e4fec/nix/pkgs/alfred.nix
I’m really puzzled by the behaviour of linking Apps. Here is another module, very simple & straight forward & has no conditionals even. Same problem. The mpv.app
, gets installed but doesn’t get linked…
https://github.com/ahmedelgabri/dotfiles/blob/5829b848bbee574f7bc85640ae9bae1cab9bfc6b/nix/modules/shared/mpv.nix
Ok, I narrowed it down to this.
Not sure exactly why this is happening still but that’s the minimal reproducible module with the issue:
This one doesn’t work
{ pkgs, lib, config, ... }:
let
cfg = config.my.gui;
in {
options = with lib; {
my.gui = {
enable = mkEnableOption ''
Whether to enable gui module
'';
};
};
config = with lib;
mkIf cfg.enable {
users.users.foo = { packages = with pkgs; [ slack ]; }; # Slack will be installed but not linked
};
}
This one works
{ pkgs, lib, config, ... }:
let
cfg = config.my.gui;
in {
options = with lib; {
my.gui = {
enable = mkEnableOption ''
Whether to enable gui module
'';
};
};
config = with lib;
mkIf cfg.enable {
environment.systemPackages = with pkgs; [ slack ]; # Slack will be installed & linked inside /Applications
};
}
I finally found my answer, in case it’s useful for anyone.
GUI apps only work with environment.systemPackages
only in nix-darwin
https://github.com/LnL7/nix-darwin/blob/828879f93084fdd5b12925acc016497d2410bdc4/modules/system/applications.nix#L17-L21
1 Like