Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does nix-darwin install nix 2.11.1 and twice #655

Closed
andrewcrook opened this issue May 10, 2023 · 8 comments
Closed

Why does nix-darwin install nix 2.11.1 and twice #655

andrewcrook opened this issue May 10, 2023 · 8 comments

Comments

@andrewcrook
Copy link

Installed nix 2.13.3

> bash <(curl -L https://releases.nixos.org/nix/nix-2.13.3/install)

every time I install nix-darwin as a flake nix 2.11.1 appears installed and linked under /run

/run/current-system/sw/bin/nix --version     
nix (Nix) 2.11.1

This is happens despite installing beforehand and using nix 2.13 to run nix build and darwin-rebuild

> nix doctor 
[FAIL] Multiple versions of nix found in PATH:
  /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin
  /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/bin
> ls -all  /run/
...
current-system -> /nix/store/b0q0g0ych5c38fqxc7bc582s4r6vi3rn-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
...


> \ls -all /run/current-system/
...
 sw -> /nix/store/wzhb1sjqg5p661zf4pg5hirdf9mbg6bb-system-path
...

\ls -all /run/current-system/sw/bin/
...
nix -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix
nix-build -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-build
nix-channel -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-channel
nix-collect-garbage -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-collect-garbage
nix-copy-closure -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-copy-closure
 nix-daemon -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-daemon
nix-env -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-env
nix-hash -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-hash
nix-info -> /nix/store/k7dmpmps8zh5bchs6iaad5srjprqdib8-nix-info/bin/nix-info
nix-instantiate -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-instantiate
nix-prefetch-url -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-prefetch-url
nix-shell -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-shell
nix-store -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1/bin/nix-store
...
> ls /nix/store/  | grep ".*nix-2\.13\.3*" 
8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/

Is there anyway I can stop this from happening?

@lockejan
Copy link
Contributor

lockejan commented May 10, 2023

Hard to say without seeing the source, but I guess your flake references nix as a package or service, which makes it install it again.

@andrewcrook
Copy link
Author

Hi @lockejan

Just a installed nix 2.13.3 then build this same flake.
I have simplified the flake and disabled home-manager to simplify even further.

flake.nix

{
  description = "Andrews MBP";
  inputs = {
    nixpkgs.url =
      "github:nixos/nixpkgs/7629f9b0680d87c7775f3261bee746da5dac76d1";
    darwin.url =
      "github:lnl7/nix-darwin/379d42fad6bc5c28f79d5f7ff2fa5f1c90cb7bf8";
    darwin.inputs.nixpkgs.follows = "nixpkgs";
    # home-manager.url = "github:nix-community/home-manager/0e4c33d76006c9080d2f228ba1c2308e3e4d7be6";
    # home-manager.inputs.nixpkgs.follows = "nixpkgs";
  };

  #  outputs = inputs:
  outputs = { self, darwin, nixpkgs }@inputs:
    let
      flakeContext = {
        # inherit inputs;
        inherit darwin;
        inherit nixpkgs;
      };
    in {
      darwinConfigurations = {
        Andrews-MBP =
          import ./darwinConfigurations/Andrews-MBP.nix flakeContext;
      };
      #  homeConfigurations = {
      #  andrew = import ./homeConfigurations/andrew.nix flakeContext;
      # };
    };
}

./darwinConfigurations/Andrews-MBP.nix

# { inputs, ... }@flakeContext:
{ darwin, nixpkgs }@flakeContext:
let
  darwinModule = { config, lib, pkgs, ... }: {
    config = {
      documentation = { enable = false; };
      programs = {
        bash = { enable = true; };
        zsh = { enable = true; };
        tmux.enable = true;
      };
      services = { nix-daemon = { enable = true; }; };
      users.users.andrew = { home = "/Users/andrew"; };
      #      system = {
      #        stateVersion = 4;
      #      };
    };
  };
  # inputs.nix-
in darwin.lib.darwinSystem {
  modules = [ darwinModule ];
  system = "aarch64-darwin";
}

copied to location
~/.config/nixpkgs/darwin/darwin-configuration.nix

{ config, pkgs, ... }:

{
  # List packages installed in system profile. To search by name, run:
  # $ nix-env -qaP | grep wget
  #  environment.systemPackages =
  #    with pkgs;
  #    [
  #      # gimp
  #      # emacsMacport
  #      ((emacsPackagesFor emacsMacport).emacsWithPackages(ps: [ ps.vterm ]))
  #      # (texlive.combine { inherit (texlive) scheme-medium grffile; })
  #      alacritty
  #      kitty
  #      wezterm
  #      handbrake
  #      vim
  #      # zathura
  #    ];

  # Use a custom configuration.nix location.
  # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix
  # environment.darwinConfig = "$HOME/.config/nixpkgs/darwin/configuration.nix";

  environment.darwinConfig =
    "/Users/andrew/.config/nixpkgs/darwin-configuration.nix";

  # Auto upgrade nix package and the daemon service.
  services.nix-daemon.enable = true;
  nix = {
    # package = pkgs.nixVersions.stable;
    package = pkgs.nixFlakes;
    # trustedUsers = [ "@admin" ];
    # gc.automatic = true;
    trustedUsers = [ "@admin" ];
    extraOptions = ''
      gc-keep-derivations = true
      gc-keep-outputs = true
      experimental-features = nix-command flakes
    '';
  };

  users.nix.configureBuildUsers = true;

  # Create /etc/bashrc that loads the nix-darwin environment.
  # programs.zsh.enable = true; # default shell on catalina
  # programs.zsh.enableCompletion = false;
  # programs.zsh.enableBashCompletion = false;
  # programs.zsh.promptInit = "";
  # programs.bash.enable = true; # default shell on catalina

  # Used for backwards compatibility, please read the changelog before changing.
  # $ darwin-rebuild changelog
  system.stateVersion = 4;

@andrewcrook
Copy link
Author

andrewcrook commented May 11, 2023

Update

From flake.nix I removed
darwin.inputs.nixpkgs.follows = "nixpkgs”;

and did a fresh reinstall I didn’t get nix 2.11.1 installed this time
instead I got two copies of nix 2.13.3

nix doctor 
[FAIL] Multiple versions of nix found in PATH:
  /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3/bin
  /nix/store/j7ib8pdagj6vadsq0506wf6sswhrb5yc-nix-2.13.3/bin
> nix-store --query --roots   /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3  
/nix/var/nix/profiles/default-2-link -> /nix/store/yca76hbqmdgfcdrbrd2859968pi8cyi9-user-environment
{censored} -> /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3
/nix/var/nix/profiles/default-1-link -> /nix/store/mh5zb54smn7c2nf9jwr0d2kqxawpdd1p-user-environment

>nix-store --query --roots  /nix/store/j7ib8pdagj6vadsq0506wf6sswhrb5yc-nix-2.13.3 
/nix/var/nix/profiles/system-1-link -> /nix/store/6aady9w29vsccmfnsb4dh34iipa85ns0-darwin-system-23.05.20230511.635a306+darwin4.379d42f
/Users/andrew/Developer/nix-setup/result -> /nix/store/6aady9w29vsccmfnsb4dh34iipa85ns0-darwin-system-23.05.20230511.635a306+darwin4.379d42f
/run/current-system -> /nix/store/6aady9w29vsccmfnsb4dh34iipa85ns0-darwin-system-23.05.20230511.635a306+darwin4.379d42f
{censored} -> /nix/store/j7ib8pdagj6vadsq0506wf6sswhrb5yc-nix-2.13.3

@andrewcrook andrewcrook changed the title Why does nix-darwin install nix 2.11.1 Why does nix-darwin install nix 2.11.1 and twice May 11, 2023
@andrewcrook
Copy link
Author

I noticed one ownership is root and the other user andrew. So I think the root is from install nix and Andrew owned one is from the flask build. I thought nix-daemon changed permissions and did every thing as root?

> ls -all /nix/store/ | grep '.*-nix-2.13.3.*'  
dr-xr-xr-x     8 andrew  staff        256  1 Jan  1970 8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3
dr-xr-xr-x     3 root    nixbld        96  1 Jan  1970 bga1xq2j0cksbiwa8v5qhswiwavzz5yk-nix-2.13.3-man
-r--r--r--     1 root    nixbld      6242  1 Jan  1970 g68h6qsab2kd0bh539mc92v7jgcxk1yk-nix-2.13.3.drv
dr-xr-xr-x     8 root    nixbld       256  1 Jan  1970 j7ib8pdagj6vadsq0506wf6sswhrb5yc-nix-2.13.3

@lockejan
Copy link
Contributor

lockejan commented May 16, 2023

Auto upgrade nix package and the daemon service.
services.nix-daemon.enable = true;
nix = {
# package = pkgs.nixVersions.stable;
package = pkgs.nixFlakes;
# trustedUsers = [ "@admin" ];
# gc.automatic = true;
trustedUsers = [ "@admin" ];
extraOptions = ''
gc-keep-derivations = true
gc-keep-outputs = true
experimental-features = nix-command flakes
'';
};

How do you build your system? What's the command?
My guess is that you have multiple nix-services enabled. [Maybe even in different scopes (machine and user)].
Not 100% sure, but it looks like it from first sight.
Try disabling one services.nix-daemon.enable = true;
You can check with launchctl list | grep nix. Might need sudo to give you some results.

Sidenote: You don't need pkgs.nixFlakes, bust just pkgs.nix. Flakes are also enabled by default in recent versions of nix.

@andrewcrook
Copy link
Author

andrewcrook commented May 17, 2023

How do you build your system? What's the command?

Since I have moved the configuration into the flake

Also added the following as a shortcut into the flake for building
Andrews-MBP = self.darwinConfigurations.Andrews-MBP.system;
So now I currently use the following

> nix build --extra-experimental-features 'nix-command flakes' .#Andrews-MBP
> nix-setup % ./result/sw/bin/darwin-rebuild switch --flake .#Andrews-MBP --verbose

My guess is that you have multiple nix-services enabled.

not seeing multiple nix-services running

[Maybe even in different scopes (machine and user)].

That was my thinking but how do you define system and user versions?
2.13.2 was originally installed and used to build the system
this seems to remain under /nix/var/nix/profiles/default/
The Darwin build has installed 2.11.1 and is under current-system and system profile
its seems that nix-darwin installed 2.11.1 and has 2.11.1 as a dependence under nix-tree

image
nix-store --query --roots /nix/store/8w0v2mffa10chrf1h66cbvbpw86qmh85-nix-2.13.3 
/nix/var/nix/profiles/default-2-link -> /nix/store/yca76hbqmdgfcdrbrd2859968pi8cyi9-user-environment
nix-store --query --roots /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1
/nix/var/nix/profiles/system-6-link -> /nix/store/17scs2w6gzdmqs0wmzqkklia6h4nqh97-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/Users/andrew/Developer/nix-setup/result -> /nix/store/17scs2w6gzdmqs0wmzqkklia6h4nqh97-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/nix/var/nix/profiles/system-9-link -> /nix/store/f8pmw3jbczwppq97sl3zf3nv7f0xz7i4-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/run/current-system -> /nix/store/f8pmw3jbczwppq97sl3zf3nv7f0xz7i4-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/nix/var/nix/profiles/system-4-link -> /nix/store/62md4xg7dc04zz31jjyvdy09qmagc4iw-darwin-system-22.11.20230511.635a306+darwin4.379d42f
{censored} -> /nix/store/1qdb3bqy80xa51h1s30n67w9a9iwp40q-nix-2.11.1
/nix/var/nix/profiles/system-2-link -> /nix/store/7hij15lgams2bbfxs58br225d3zpv0wh-darwin-system-22.11.20230511.635a306+darwin4.379d42f
/nix/var/nix/profiles/system-3-link -> /nix/store/sxzji1zmfxlxwngavzzs2xiakicp1zqj-darwin-system-22.11.20230511.635a306+darwin4.379d42f
/Users/andrew/.local/state/home-manager/gcroots/current-home -> /nix/store/ipr72kch3rh2lnlh1a7c66kb663dn49p-home-manager-generation
/Users/andrew/.local/state/nix/profiles/home-manager-1-link -> /nix/store/ipr72kch3rh2lnlh1a7c66kb663dn49p-home-manager-generation
/nix/var/nix/profiles/system-7-link -> /nix/store/vfkpdnki3yj99kn795ymzmv42742xhkw-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/nix/var/nix/profiles/system-5-link -> /nix/store/261v20in66frdx230gzhlbmapcn81600-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/nix/var/nix/profiles/system-8-link -> /nix/store/41nhgsxgcsbzw4nbh8y8f5dyggc4b91v-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
/nix/var/nix/profiles/default/bin/nix --version  
nix (Nix) 2.13.3

lrwxr-xr-x   1 root  nixbld   14 11 May 15:10 default -> default-2-link
lrwxr-xr-x   1 root  nixbld   60 11 May 15:10 default-2-link -> /nix/store/yca76hbqmdgfcdrbrd2859968pi8cyi9-user-environment

> /nix/var/nix/profiles/system/sw/bin/nix --version   
nix (Nix) 2.11.1


lrwxr-xr-x  1 root  nixbld  13 16 May 20:41 /nix/var/nix/profiles/system -> system-9-link
 system-9-link -> /nix/store/f8pmw3jbczwppq97sl3zf3nv7f0xz7i4-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f
current-system -> /nix/store/f8pmw3jbczwppq97sl3zf3nv7f0xz7i4-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f

current build
result -> /nix/store/17scs2w6gzdmqs0wmzqkklia6h4nqh97-darwin-system-22.11.20230508.7629f9b+darwin4.379d42f

user Andrew

>which nix
/run/current-system/sw/bin/nix
> nix --version                   
nix (Nix) 2.11.1


.nix-profile -> /nix/var/nix/profiles/per-user/Andrew/profile

> nix-env -q        
nix-tree-0.2.1
nixfmt-0.5.0
rnix-lsp-0.2.5
> ls /nix/var/nix/profiles/per-user/andrew/profile/bin/              
 nix-tree@   nixfmt@   rnix-lsp@

user root /var/root


> sudo  nix --version
nix (Nix) 2.11.1
> sudo  which nix 
/run/current-system/sw/bin/nix


.nix-profile -> /nix/var/nix/profiles/default

ls /nix/var/nix/profiles/default/bin/
 nix*         nix-channel@        nix-copy-closure@   nix-env@    nix-instantiate@    nix-shell@
 nix-build@  nix-collect-garbage@   nix-daemon@        nix-hash@   nix-prefetch-url@   nix-store@
> ./nix --version 
nix (Nix) 2.13.3

> ls /nix/var/nix/profiles/per-user/root/   
 channels@   channels-2-link@   channels-3-link@   channels-4-link@  channels-5-link@

lrwxr-xr-x  1 root  wheel    15 16 May 19:37 channels -> channels-5-link
channels-5-link -> /nix/store/57904rflsfh46y7fxi62rzc7sidc9vmq-user-environment

> sudo nix-env -q   
nix-2.13.3
nss-cacert-3.83

Try disabling one services.nix-daemon.enable = true;

tried that and useDaemon, one or other with no change and without darwin-rebuild fails saying it defaults to multiuser and requires the daemon to be enabled.

You can check with launchctl list | grep nix. Might need sudo to give you some results.

> sudo launchctl list | grep nix                  
-	0	org.nixos.darwin-store
564	0	org.nixos.nix-daemon
-	0	org.nixos.activate-system
-	0	org.nixos.nix-gc

@andrewcrook
Copy link
Author

I have moved to a newer version of nix-darwin

url = "github:lnl7/nix-darwin/master”;

now if I use the following for nix-darwin and home-manager

inputs.nixpkgs.follows = "nixpkgs”;

I get

error: attribute 'extend' missing

       at /nix/store/wlknzxqmndyk1md3c14ga0d50yygisyx-source/modules/lib/stdlib-extended.nix:7:4:

            6| let mkHmLib = import ./.;
            7| in nixpkgsLib.extend (self: super: {
             |    ^
            8|   hm = mkHmLib { lib = self; };
       Did you mean extends?
(use '--show-trace' to show detailed location information)

I can only get rid of this error and get nix-darwin to use nix 2.13.3 by using nixpkgs-unstable and inputs. darwin.inputs.nixpkgs.follows = "nixpkgs”;

now when building

• Updated input 'darwin/nixpkgs':
    'github:NixOS/nixpkgs/7e0743a5aea1dc755d4b761daf75b20aa486fdad' (2023-05-16)
  → follows 'nixpkgs'
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/55af203d468a6f5032a519cba4f41acf5a74b638' (2023-05-15)
  → 'github:nixos/nixpkgs/963006aab35e3e8ebbf6052b6bf4ea712fdd3c28' (2023-05-16)

after building

# Hooray the correct version
> nix --version 
nix (Nix) 2.13.3
# can now remove the original 
> sudo nix-env -e nix-2.13.3
> sudo nix-env -e  nss-cacert-3.83
# everything look fine.
> nix doctor                                    
[PASS] PATH contains only one nix version.
[PASS] All profiles are gcroots.
[PASS] Client protocol matches store protocol.

Summary

  • needs to have away to use the installed version of nix with nix-darwin
  • and needs more control over nix versions
  • nix-darwin can install its own version of nix even if its the unintended version
  • seem to be forced to use nixos-unstable rather than a more stable sources of nixpkgs
  • version following and nix-darwin has some issues
  • makes pinning versions of nixpkgs and nix-darwin more difficult than it needs to be.

@LnL7
Copy link
Owner

LnL7 commented May 17, 2023

When going through the nix-darwin installer the originally installed nix is not removed from the default profile, but while nix-darwin is used the version of nix specified declaratively will always have priority so this warning from nix doctor is not a problem at all. Keeping the version around in the expected location makes it easier for people to roll back to a still working nix installation if they want to stop using a declarative system configuration.

If you want to disable usage of profiles you can do so, which will result in these locations to not be exposed in environment variables like PATH. Alternatively you can delete the package from the default profile as you did.

{
  environment.profiles = mkForce [];
}

The traceback you posed seems more related to home manager, I've used follows in my flake without problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants