Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$has_disclaimer is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_lock is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_meta_box_present is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_send_notification is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_modify_title_and_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_heading is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_category is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_blz_affiliation_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_content_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_speciali is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskw is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_linkdex is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_content_score is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskeywords is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_keywordsynonyms is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_estimated-reading-time-minutes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_wordproof_timestamp is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$response_body is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_indexnow_last_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$newsletter_subject is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_newsletter_subject is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$newsletter_summary is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_newsletter_summary is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Homebrew e nix-darwin: il package manager che mancava su macOS | IlSoftware.it

Homebrew e nix-darwin: il package manager che mancava su macOS

Cosa sono Homebrew e nix-darwin: due package manager intelligenti che ampliano significativamente il numero di programmi installabili su macOS. Oltre a un catalogo più ricco, gli utenti possono beneficiare di tante funzionalità avanzate. Ecco quali sono.

Di suo il sistema operativo macOS non integra un package manager, ovvero uno strumento utile per installare e disinstallare applicazioni, anche in maniera automatizzata e da riga di comando. Per gestire i programmi macOS, Apple mette a disposizione unicamente il suo celeberrimo App Store. Con il preciso intento di offrire agli utenti della Mela un gestore di pacchetti degno di tale nome, ci ha pensato nel 2009 Max Howell presentando l’idea di Homebrew.

Il software colma il divario tra i programmi disponibili di default su macOS e quelle che ciascun utente potrebbe voler installare sul suo sistema. Gli autori di Homebrew ben riassumono la “missione” dell’utilità: “se aveste mai desiderato installare uno strumento come wget o una nuova applicazione come Firefox, ma ritenete noioso cercare e scaricare i file di installazione autonomamente, Homebrew è la soluzione perfetta per voi“.

Homebrew: cos’è e come funziona

Homebrew è un package manager che semplifica l’installazione e la gestione di software aggiuntivo. Funziona attraverso il concetto di “formule”, script Ruby che descrivono come installare un determinato software e le sue dipendenze.

Quando si vuole installare un nuovo programma tramite Homebrew, è sufficiente utilizzare il suo comando da terminale brew seguito dal nome del pacchetto che si desidera installare. Homebrew si occupa di scaricare il software desiderato, insieme a tutte le sue dipendenze, e di installarlo correttamente nel sistema.

Distribuito come programma open source, Homebrew trae vantaggio da un’estesa comunità di sviluppatori che si occupa della manutenzione del progetto, del suo aggiornamento e sviluppo.

Come installare Homebrew

L’installazione di Homebrew è un processo molto semplice. Basta aprire una finestra del terminale su macOS quindi incollarvi il comando che segue:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Lo script di installazione descrive ogni passaggio. Al termine, ogni utente ha accesso a un vasto ecosistema software pronto per essere gestito con un solo comando. Ad esempio, se si desiderasse installare il leggendario wget, utilità per scaricare file da Internet, è possibile procedere con il comando che segue:

brew install wget

Homebrew installa il pacchetto nella sua directory e crea un collegamento simbolico nel percorso /opt/homebrew, mantenendo il sistema pulito e organizzato.

Homebrew Cask: per installare applicazioni macOS con facilità

Oltre alla gestione del software tramite formule, l’applicazione integra anche Homebrew Cask, che consente di installare applicazioni macOS, font e plugin in modo simile a come si installano i pacchetti tramite il comando brew.

Homebrew Cask è specificamente progettato per semplificare l’installazione di applicazioni GUI, come browser Web, editor di testo, app di produttività e così via. L’idea è quella di scaricare e installare file binari precompilati delle applicazioni di proprio interesse. È utile quando si desiderano installare rapidamente applicazioni senza dover navigare manualmente sui siti Web degli sviluppatori. Ad esempio, per installare Firefox basta un semplice comando:

brew install --cask firefox

Maggiori informazioni su Homebrew sono disponibili sul sito ufficiale del progetto.

nix-darwin: cos’è e quali sono le differenze rispetto a Homebrew

Sebbene anche su Windows si siano compiuti enormi passi in avanti (ricordiamo ad esempio il gestore di pacchetti Scoop e Microsoft Winget) è GNU/Linux che, storicamente, ha fatto scuola per quanto concerne i migliori package manager.

nix è uno dei migliori in assoluto per diversi motivi. Innanzitutto, offre una sorta di memoria condivisa a lungo termine. Non c’è più bisogno di ricordarsi la sintassi utilizzata mesi orsono per configurare una macchina o quali comandi si sono utilizzati alle due di notte per configurare alla perfezione un ambiente di lavoro. La sincronizzazione dei dati è un punto di forza indiscutibile.

Si tratta di uno strumento prezioso che assicura una visione completa sul proprio ambiente software. Tutti i file di configurazione, temi ed estensioni dell’editor e i programmi avviati dalla riga di comando, sono definiti in un unico repository.

Grazie a nix, inoltre, è possibile ridurre il lavoro manuale: gli utenti possono automatizzare il processo di aggiornamento e gestione delle configurazioni, riducendo così il carico di lavoro e il tempo necessario per mantenere “in salute” tutti i sistemi amministrati.

Ricorrendo a uno strumento come nix-darwin è possibile gestire praticamente qualunque impostazione di sistema sulla piattaforma macOS. L’ambiente in uso diventa così più facilmente gestibile e trasparente.

Cosa sono Darwin e nix-darwin

Darwin è il sistema operativo open source POSIX-compliant rilasciato da Apple nel 2000. È composto da codice sviluppato da Apple, derivato da NeXTSTEP, BSD e altri progetti software free. Il “nocciolo” di macOS e iOS vede Darwin come uno dei pilastri fondamentali: ne abbiamo parlato nell’articolo sulle differenze tra macOS e Linux.

nix-darwin è un insieme di moduli per la gestione della configurazione di macOS. Gli utenti hanno a disposizione una piattaforma nix centralizzata che permette di accedere a ogni “piega” della configurazione del sistema in uso.

nix adotta un approccio dichiarativo per la gestione dei pacchetti, il che significa che l’utente deve indicare semplicemente quali pacchetti desidera e Nix si occupa di risolvere le dipendenze e procedere con l’installazione in modo coerente. Inoltre, nix-darwin crea un ambiente isolato per ogni pacchetto installato, consentendo di evitare interferenze o conflitti tra pacchetti.

Gli utenti possono inoltre apprezzare la creazione di ambienti riproducibili, l’eventuale rollback (ripristino) dei pacchetti e il repository centralizzato.

nix-darwin: l’approccio più potente per gestire i pacchetti software con macOS

Sebbene Homebrew resti un vero e proprio punto di riferimento, nix-darwin offre oggi il modo migliore per gestire pacchetti e configurazioni di sistema su macOS.

Come sottolinea Davis Haupt, interfacciarsi con le varie parti dell’ecosistema nix non è propriamente semplice per i principianti. Per iniziare a usare nix su macOS, Haupt suggerisce di ricorrere all’installer di Determinate Systems. Integra infatti un’utilità da riga di comando e a novembre 2023 è stata aggiunta una efficace procedura d’installazione in formato grafico.

Per configurare nix-darwin sulla macchina macOS, Haupt propone un flake ovvero un elemento che rende più facile e trasparente la definizione, la condivisione e l’utilizzo di pacchetti, configurazioni e ambienti con nix.

Nel flake proposto in corrispondenza del paragrafo Setting up nix-darwin, le occorrenze di $USER e $HOSTNAME vanno sostituite, rispettivamente, con il nome utente in uso e con il nome del sistema macOS. Riproponiamo di seguito il contenuto del file flake realizzato da Haupt (il file va salvato come ~/.config/nix/flake.nix):

# ~/.config/nix/flake.nix

{
  description = "Mia configurazione di sistema";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin = {
        url = "github:LnL7/nix-darwin";
        inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs }:
  let
    configuration = {pkgs, ... }: {

        services.nix-daemon.enable = true;
        # Riga necessaria per usare i flake sul sistema
        nix.settings.experimental-features = "nix-command flakes";

        system.configurationRevision = self.rev or self.dirtyRev or null;

        # Utilizzato per garantire retrocompatibilita'
        # Vedere `darwin-rebuild changelog`
        system.stateVersion = 4;

        # La piattaforma sulla quale e' usata la configurazione.
        # Su un sistema Intel system, inserire la stringa "x86_64-darwin"
        nixpkgs.hostPlatform = "aarch64-darwin";

        # Specificare l'utente che esegue `nix-darwin`.
        users.users.$USER = {
            name = "$USER";
            home = "/Users/$USER";
        };

        # Crea il percorso /etc/zshrc per l'ambiente nix-darwin
        programs.zsh.enable = true;

        environment.systemPackages = [ ];
    };
  in
  {
    darwinConfigurations."$HOSTNAME" = nix-darwin.lib.darwinSystem {
      modules = [
         configuration
      ];
    };
  };
}

Attivazione della configurazione nix-darwin su macOS

Una delle particolarità quando si usano i flake di nix è che tutti i file richiamati devono necessariamente risultare controllati mediante un repository contenente codice sorgente. Ciò significa che è necessario avere git installato prima di configurare l’ambiente nix.

I seguenti comandi consentono di predisporre tutto il necessario:

cd ~/.config/nix
git init
git add flake.nix
nix run nix-darwin --extra-experimental-features nix-command --extra-experimental-features flakes -- switch --flake ~/.config/nix

Installazione di pacchetti software con nix-darwin

Come primo passo, è necessario aggiornare l’elenco dei repository e, di conseguenza, dei pacchetti installabili ricorrendo a nix-darwin:

environment.systemPackages = [ pkgs.neofetch pkgs.vim ];

A questo punto basta eseguire il comando seguente per aggiornare la configurazione di nix-darwin:

darwin-rebuild switch --flake ~/.config/nix

Il “catalogo” dei pacchetti installabili sui sistemi macOS tramite nix è davvero nutrito. Alcuni programmi, tuttavia, potrebbero essere disponibile soltanto mediante Homebrew. Come spiega Haupt al paragrafo Installing packages from Homebrew, si può modificare la configurazione del file flake.nix per aggiungere un riferimento esplicito a Homebrew, all’interno della sezione environment.systemPackages. Questo è il file flake completo che integra anche il supporto diretto di Homebrew.

Ti consigliamo anche

Link copiato negli appunti