diff --git a/README.md b/README.md new file mode 100644 index 0000000..f968ede --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Installation + +`` is default to `hostname` command but it can be overwritten + +Build only + +```bash +nixos-rebuild build --flake .# +``` + +Build and switch + +```bash +nixos-rebuild switch --flake .# +``` \ No newline at end of file diff --git a/configuration.nix b/configuration.nix index 48af7f8..1793409 100644 --- a/configuration.nix +++ b/configuration.nix @@ -104,7 +104,7 @@ in vim git vscode - # wget + wget ]; # Some programs need SUID wrappers, can be configured further or are @@ -134,4 +134,10 @@ in # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). system.stateVersion = "23.05"; # Did you read the comment? + # BEGIN: Add flake feature TODO: Remove when not experimental + nix = { + package = pkgs.nixFlakes; + extraOptions = "experimental-features = nix-command flakes"; + }; + # END: Add flake feature } diff --git a/docs/flake/HOME.md b/docs/flake/HOME.md index 913e243..fe2772f 100644 --- a/docs/flake/HOME.md +++ b/docs/flake/HOME.md @@ -1 +1,86 @@ -# Fonctionnement de flake \ No newline at end of file +# Fonctionnement de flake + +### Général + +- Permet de télécharger des dépendances de code comme \ +> Stocke les dépendances dans le fichier `flake.lock`. +> Si l'on souhaite figer la version des dépendances pour éviter tout risque de mauvaise configuration. On peut utiliser le fichier `flake.log` + +- Permet de configurer facilement notre propre configuration comme depuis les dotfiles + +### Installation + +Pour le moment, flake est encore expérimental donc il faut l'activer manuellement. + +/etc/nixos/configuration.nix +```nix +[...] + # BEGIN: Add flake feature TODO: Remove when not experimental + nix = { + package = pkgs.nixFlakes; + extraOptions = "experimental-features = nix-command flakes"; + }; + # END: Add flake feature +} +``` + +### Configuration initial + +Génére le fichier `flake.nix` +```bash +nix flake init +``` + +`flake.nix` +```nix +{ + description = "A very basic flake"; + + outputs = { self, nixpkgs }: { + + packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; + + packages.x86_64-linux.default = self.packages.x86_64-linux.hello; + + }; +} +``` + +### Structure + +#### Inputs + +Défini l'ensemble des dépendances utilisées dans le `flake` + +```nix +inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; +}; +``` + +#### Outputs + +Récupère les inputs dans la fonction en paramètre +- Permet de configurer ce que l'on a importé. +- Peut configurer les packages, configurations, modules, ... + +```nix +outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + lib = nixpkgs.lib; + in { + nixosConfigurations = { + # specified with + # `nixos-rebuild [build/switch] --flake .#` + = lib.nixosSystem { + inherit system; + modules = [ ./configuration.nix ]; + }; + }; + }; +``` \ No newline at end of file diff --git a/docs/home_manager/HOME.md b/docs/home_manager/HOME.md index bf777ce..d429cc9 100644 --- a/docs/home_manager/HOME.md +++ b/docs/home_manager/HOME.md @@ -2,6 +2,8 @@ ## Installation +**!!! Inutile si on utilise Flakes et que l'on install home-manager avec** + *sudo si l'on souhaite utiliser le module NixOS depuis /etc/nixos/configuration.nix* ```bash nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager @@ -23,6 +25,8 @@ Relancer la session pour reload les channels pour le user courant. nix-shell '' -A install ``` +## Configuration + $HOME/.config/nixpkgs/home.nix ```nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e7a226e --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1675183161, + "narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a2f43bc --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + lib = nixpkgs.lib; + in { + nixosConfigurations = { + nixos-desktop = lib.nixosSystem { + inherit system; + modules = [ ./configuration.nix ]; + }; + }; + }; +}