-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6f7b61a
Showing
25 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[*] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
watch_file flake.nix | ||
watch_file flake.lock | ||
# load the flake devShell | ||
eval "$([ -d $(direnv_layout_dir) ] || mkdir $(direnv_layout_dir); nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore nix links | ||
/result | ||
/result-* | ||
|
||
.direnv | ||
|
||
# For the moment, ignore /secrets content | ||
# will change it when implementing it | ||
/secrets/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Flake structure | ||
|
||
## Objective | ||
|
||
This is an example of how I structure my configurations, | ||
not necessarily the perfect match for every setup. | ||
|
||
## Features | ||
|
||
This flake example shows how to group several common tools: | ||
|
||
* Ability to have custom packages in the system | ||
* Ability to present this packages as an overlay | ||
* Ability to handle one or multiple `nixos` configurations | ||
* Ability to handle one or multiple `nix-darwin` configurations | ||
* Ability to handle one or multiple `home-manager` configurations | ||
|
||
## Usage | ||
|
||
1) Enter the devShell environment (using `direnv` or `nix develop`). | ||
2) Update the `inputs` using `flake-mgr update` | ||
3) Generate the system configuration using `flake-mgr switch` | ||
* This will define in the flake registy two local variations | ||
`nixpkgs` to pin it for the system and `nixcfg` to this current | ||
flake. | ||
* Will apply `nixos-rebuild switch` using current flake (a flag | ||
might be required to select the correct configuration). | ||
4) Generate the home configuration using `flake-mgr home-switch` | ||
|
||
## Limitations | ||
|
||
Currently, all the features were not used / tested (most notable | ||
`nix-darwin`). Flake-mgr doesn't include yet a darwin-switch action. | ||
|
||
Secrets handling is still a WIP, I target the integration of | ||
`sops-nix` but other solutions might also apply. | ||
|
||
Even though the current flake has an overlay, it is not propagated to | ||
the `nixpkgs` entry in the registry, you will have to combine | ||
explicitely the different overlays from other flakes/shells. | ||
|
||
## Directory layout | ||
|
||
* `darwin/configurations`: Configurations for `nix-darwin` | ||
* `darwin/modules`: Modules for `nix-darwin` | ||
* `home/configurations`: Configurations for the users | ||
using `home-manager` | ||
* `home/modules`: Modules for `home-manager` | ||
* `lib`: Nix libraries to help handling the flake | ||
* `nixos/configurations`: Configurations for `nixos` | ||
* `nixos/modules`: Modules for `nixos` | ||
* `pkgs`: Local packages | ||
* `secrets`: Not yey implemented, but should contain | ||
keys, credentials and tokens protected by `sops-nix` | ||
or `git-crypt` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
description = "My custom flake"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-20.09-small"; | ||
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
home-manager.url = "github:nix-community/home-manager/release-20.09"; | ||
home-manager.inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, home-manager, nixpkgs-unstable }: | ||
let | ||
lib = import ./lib { inherit nixpkgs self; }; | ||
in | ||
{ | ||
inherit lib; | ||
legacyPackages = lib.utils.forAllSystems (system: | ||
let | ||
rawPkgs = import ./pkgs { | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
config.allowUnfree = true; | ||
}; | ||
unstable = import nixpkgs-unstable { | ||
inherit system; | ||
config.allowUnfree = true; | ||
}; | ||
inherit home-manager; | ||
}; | ||
in | ||
# Not working atm | ||
#lib.utils.removeIncompatible system rawPkgs; | ||
rawPkgs | ||
); | ||
|
||
homeConfigurations = lib.utils.forAllSystems (system: (lib.homeManager.loadConfigurations { inherit system; }).homeConfigurations); | ||
homeModules = lib.utils.forAllSystems (system: (lib.homeManager.loadConfigurations { inherit system; }).homeModules); | ||
|
||
inherit (lib.utils) overlay; | ||
inherit (lib.nixos.loadConfigurations home-manager.nixosModules) | ||
nixosModules nixosConfigurations; | ||
inherit (lib.darwin.loadConfigurations) | ||
darwinModules darwinConfigurations; | ||
|
||
devShell = lib.utils.forAllSystems (system: | ||
nixpkgs.legacyPackages.${system}.mkShell { | ||
buildInputs = | ||
(with self.legacyPackages.${system}; [ | ||
flake-mgr | ||
]); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ pkgs, ... }: | ||
|
||
{ | ||
home.packages = with pkgs; [ | ||
ripgrep | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ self, nixpkgs, utils }: | ||
|
||
let | ||
darwinModules = import ../darwin/modules; | ||
|
||
in | ||
{ | ||
inherit darwinModules; | ||
|
||
loadConfigurations = { | ||
system ? builtins.currentSystem | ||
, pkgs ? nixpkgs.legacyPackages.${system} | ||
}: | ||
{ | ||
inherit darwinModules; | ||
|
||
darwinConfigurations = utils.loadConfigurations "${self}/darwin" | ||
({name, fullName }: { | ||
configuration = "${fullName}/configuration.nix"; | ||
username = name; | ||
inherit system pkgs; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ self, nixpkgs }: | ||
|
||
let | ||
utils = import ./utils.nix { inherit self nixpkgs; }; | ||
|
||
combinedPackages = nixpkgs // { | ||
legacyPackages = utils.forAllSystems (system: | ||
import nixpkgs { | ||
inherit system; | ||
config.allowUnfree = true; | ||
overlays = [ self.overlay ]; | ||
}); | ||
}; | ||
in | ||
{ | ||
inherit utils; | ||
|
||
nixos = import ./nixos.nix { | ||
inherit self utils; | ||
nixpkgs = combinedPackages; | ||
}; | ||
|
||
homeManager = import ./home-manager.nix { | ||
inherit self utils; | ||
nixpkgs = combinedPackages; | ||
}; | ||
|
||
darwin = import ./darwin.nix { | ||
inherit self utils; | ||
nixpkgs = combinedPackages; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ self, nixpkgs, utils }: | ||
|
||
let | ||
homeModules = import ../home/modules; | ||
|
||
configuration = { | ||
configuration | ||
, username | ||
, homeDirectory ? "/home/${username}" | ||
, pkgs ? nixpkgs.legacyPackages.${system} | ||
, system ? builtins.currentSystem | ||
, check ? true }: | ||
import "${self.legacyPackages.${system}.unstable.home-manager}/modules" { | ||
inherit check pkgs; | ||
configuration = { ... }: { | ||
imports = [ configuration homeModules ]; | ||
_module.args.pkgs = pkgs; | ||
home = { inherit homeDirectory username; }; | ||
}; | ||
}; | ||
in | ||
|
||
{ | ||
inherit homeModules; | ||
|
||
loadConfigurations = { | ||
system ? builtins.currentSystem | ||
, pkgs ? nixpkgs.legacyPackages.${system} | ||
}: | ||
{ | ||
inherit homeModules; | ||
|
||
homeConfigurations = utils.loadConfigurations "${self}/home" | ||
({name, fullName }: configuration { | ||
configuration = "${fullName}/home.nix"; | ||
username = name; | ||
inherit system pkgs; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ self, nixpkgs, utils }: | ||
|
||
let | ||
inherit (nixpkgs) lib; | ||
inherit (utils) filterDir mapDir; | ||
|
||
fromCommonConfiguration = nixosModules: extraModule: rec { | ||
system = "x86_64-linux"; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
modules = (lib.mapAttrsToList (n: v: v) nixosModules) | ||
++ [ { | ||
imports = [ | ||
nixpkgs.nixosModules.notDetected | ||
extraModule | ||
]; | ||
|
||
system.configurationRevision = lib.mkIf (self ? rev) self.rev; | ||
|
||
nix.registry = { | ||
nixpkgs.flake = nixpkgs; | ||
nixcfg.flake = self; | ||
}; | ||
} ]; | ||
}; | ||
|
||
nixosModules = | ||
let mods = "${self}/nixos/modules"; in mapDir mods | ||
(name: value: if value == "regular" then import "${mods}/${name}.nix" else import "${mods}/${name}") | ||
(n: v: n != "default.nix"); | ||
in { | ||
inherit nixosModules; | ||
|
||
loadConfigurations = extraModules: | ||
{ | ||
inherit nixosModules; | ||
nixosConfigurations = utils.loadConfigurations "${self}/nixos" | ||
({fullName, ... }: lib.nixosSystem | ||
(fromCommonConfiguration (nixosModules // extraModules) | ||
(import "${fullName}/configuration.nix"))); | ||
}; | ||
} |
Oops, something went wrong.