Add flake.nix

This commit is contained in:
Florian RICHER 2023-02-01 23:36:03 +01:00
parent 339891709c
commit a5186ea3d6
6 changed files with 163 additions and 2 deletions

15
README.md Normal file
View file

@ -0,0 +1,15 @@
# Installation
`<hostname>` is default to `hostname` command but it can be overwritten
Build only
```bash
nixos-rebuild build --flake .#<hostname>
```
Build and switch
```bash
nixos-rebuild switch --flake .#<hostname>
```

View file

@ -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
}

View file

@ -1 +1,86 @@
# Fonctionnement de flake
# Fonctionnement de flake
### Général
- Permet de télécharger des dépendances de code comme \<home-manager>
> 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 = {
# <hostname> specified with
# `nixos-rebuild [build/switch] --flake .#<hostname>`
<hostname> = lib.nixosSystem {
inherit system;
modules = [ ./configuration.nix ];
};
};
};
```

View file

@ -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 '<home-manager>' -A install
```
## Configuration
$HOME/.config/nixpkgs/home.nix
```nix

27
flake.lock Normal file
View file

@ -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
}

24
flake.nix Normal file
View file

@ -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 ];
};
};
};
}