Misterio77 / nix-config

Personal nixos and home-manager configurations.
https://m7.rs/git/nix-config/
MIT License
803 stars 47 forks source link

this config with darwin #7

Closed luxus closed 2 years ago

luxus commented 2 years ago

is anyone using this config with darwin as example?

luxus commented 2 years ago

i tried to do it myself but i still struggle with the syntax and the understanding for nix :(

https://github.com/luxus/nix-config/blob/mychanges/lib/default.nix

Misterio77 commented 2 years ago

Hey,

The issue with your file is that you have one function input and one output. It should be:

{
  mkNixos = {
    hostname,
    system,
    persistence ? false,
  }:
    nixosSystem {
      inherit system;
      pkgs = outputs.legacyPackages.${system};
      specialArgs = {
        inherit inputs outputs hostname persistence;
      };
      modules =
        attrValues (import ../modules/nixos)
        ++ [
          ../hosts/nixos/${hostname}
        ];
    };

  mkDarwin = {
    hostname,
    system,
    persistence ? false,
  }:
    darwinSystem {
      inherit system;
      pkgs = outputs.legacyPackages.${system};
      specialArgs = {
        inherit inputs outputs hostname persistence;
      };
      modules =
        attrValues (import ../modules/darwin)
        ++ [
          ../hosts/darwin/${hostname}
        ];
    };
}
Misterio77 commented 2 years ago

Oh and by the way, you might be better served trying out my nix-starter-configs. They are really complete, yet easy to understand for people starting out with nix (package manager and/or language).

My config is a tad complex (you probably don't need to make a function for defining systems, for example) and overall "here be dragons".

luxus commented 2 years ago

okay.. i think it was too late yesterday :D

i still struggle to get it working. i will take a further look tomorrow. maybe i will figure it out

i'm pretty far with your config i got it working on 2 computers and from now on it looks a lot easier. impersistence is a pain in the ass but i got it mostly. https://mt-caret.github.io/blog/posts/2020-06-29-optin-state.html i will try to use the diff script there to see what i'm still missing (my volume resets)

luxus commented 2 years ago

@Misterio77 if you have the time to take a look on my fork of your config https://github.com/luxus/nix-config/blob/mychanges/lib/default.nix i would really appreciate it :D

Misterio77 commented 2 years ago

Looks good :)

But I'd advise you to instead start with a smaller config and work your way up. Nix code can be cryptic, so it's best if you start with code that you fully understand (of course, that isn't possible at the very beggining, so start with the simplest code possible), and build your own complexity as you progress. Dealing with complex abstractions you don't need will make it a LOT harder to learn.

Misterio77 commented 2 years ago

If you're interested in the abstractions, go right ahead. But if the thing you need is impermanence, I can help you write a minimum viable flake.

luxus commented 2 years ago

thanks for the advice, your config is not the first i tried :D and you are right it's easier with a smaller config. but i want to use the config on at least 5 machines, so your abstactions are really helpful.

as i posted in a other issue. your config is so far the most easiest to understand "complex config". i got nearly everything working and understand most of it so far. but the abstraction is a little bit much. :D i moved the nixOS configs to /hosts/nixOS/ but couldn't access common ../../common didn't work? is it not possible to go 2 folders up? when i try to use the config on a mac i got following error:

❯ darwin-rebuild switch --flake .
warning: Git tree '/Users/luxus/Source/nix-config' is dirty
building the system configuration...
warning: Git tree '/Users/luxus/Source/nix-config' is dirty
error: attribute 'darwinSystem' missing

       at /nix/store/vmfbw1rwrfq3sm4dmlisx76lwjd65210-source/lib/default.nix:1:19:

            1| {inputs, ...}: let
             |                   ^
            2|   inherit (inputs) self home-manager nixpkgs deploy-rs ;

do i have to separate the mkHome between darwin and nixOS aswell?

Misterio77 commented 2 years ago

your config is so far the most easiest to understand "complex config". i got nearly everything working and understand most of it so far. but the abstraction is a little bit much. :D

that makes sense.

but couldn't access common ../../common

Hm, it should work. In which file is this error happening?

error: attribute 'darwinSystem' missing

In lib/default.nix line 6, you're trying to import darwinSystem from nixpkgs.lib. You should import it from darwin.lib instead. Like so:

{inputs, ...}: let
  inherit (inputs) self home-manager nixpkgs deploy-rs darwin;
  inherit (self) outputs;

  inherit (builtins) elemAt match any mapAttrs attrValues attrNames listToAttrs;
  inherit (nixpkgs.lib) nixosSystem filterAttrs genAttrs mapAttrs';
  inherit (darwin.lib) darwinSystem;
  inherit (home-manager.lib) homeManagerConfiguration;

  activate = type: config: deploy-rs.lib.${config.pkgs.system}.activate.${type} config;
in rec {
# ...
}
luxus commented 2 years ago

thanks that worked.. i could be more clever and just add a if statement with stdenv.hostplatform.isDarwin