Skip to content

Commit

Permalink
Merge pull request #1 from gytis-ivaskevicius/staging (Release v1.0.0)
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
gytis-ivaskevicius authored Mar 21, 2021
2 parents be73f1e + 9c50408 commit 51cb739
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 154 deletions.
201 changes: 86 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,140 +1,111 @@

# What is this flake #

This flake exposes a library abstraction to *painlessly* generate nixos flake configurations.

The biggest design goal is to keep down the fluff. The library is
meant to be easy to understand and use. It aims to be far simpler
than frameworks such as devos (previously called nixflk).
The biggest design goal is to keep down the fluff. The library is meant to be easy to understand and use. It aims to be far simpler than frameworks such as devos (previously called nixflk).

# Features of flake #

This flake provides two main features (visible from `flake.nix`):

- `nixosModules.saneFlakeDefaults` - Configures `nix.*` attributes. Generates `nix.nixPath`/`nix.registry` from flake `inputs`, sets `pkgs.nixUnstable` as the default also enables `ca-references` and `flakes`.
- `lib.systemFlake { ... }` - Generates a system flake that may then be built.
- `lib.modulesFromList [ ./a.nix ./b.nix ]` - Generates modules attributes which looks like this `{ a = import ./a.nix; b = import ./b.nix; }`.


# Examples #

- `nixPathFromInputs` generates list for nixpath to include flake inputs.
- `nixRegistryFromInputs` generates attribute set for registry to include flake inputs.
- `nixDefaultsFromInputs` generates `nix` configuration attribute set. Invokes `nixPathFromInputs` and `nixRegistreyFromInputs` as well as enables flakes.
- `systemFlake` generates a system flake that may then be built.
- [Gytis Dotfiles (Author of this project)](https://github.com/gytis-ivaskevicius/nixfiles/blob/master/flake.nix)
- [fufexan Dotfiles](https://github.com/fufexan/dotfiles/blob/main/flake.nix)

# How to use this flake #

Example flake with all available attributes can be found [Here](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/master/examples/fully-featured-flake.nix).

And more realistic flake example can be found [Here](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/master/examples/somewhat-realistic-flake.nix).

```nix
outputs = inputs@{ self, nixpkgs, unstable, nur, utils, home-manager, neovim }:
utils.lib.systemFlake {
{
outputs = inputs@{ self, nixpkgs, unstable, nur, utils, home-manager, neovim }:
utils.lib.systemFlake {
# Required arguments
inherit self inputs;
# `self` and `inputs` arguments are REQUIRED!!!!!!!!!
inherit self inputs;
# Supported systems, used for packages, apps, devShell and multiple other definitions. Defaults to `flake-utils.lib.defaultSystems`
supportedSystems = [ "aarch64-linux" "x86_64-linux" ];
# Supported systems, used for packages, apps, devShell and multiple other definitions. Defaults to `flake-utils.lib.defaultSystems`
supportedSystems = [ "aarch64-linux" "x86_64-linux" ];
# Default architecture to be used for `nixosProfiles` defaults to "x86_64-linux". Might get renamed in near future
defaultSystem = "aarch64-linux";
# Default architecture to be used for `nixosProfiles` defaults to "x86_64-linux"
defaultSystem = "aarch64-linux";
# Channel definitions. `channels.<name>.{input,overlaysFunc,config}`
channels.nixpkgs = {
# Channel input to import
input = nixpkgs;
# Channel definitions. `channels.<name>.{input,overlaysBuilder,config,patches}`
channels.nixpkgs = {
# Channel input to import
input = nixpkgs;
# Channel specific overlays
overlaysFunc = channels: [
(final: prev: { inherit (channels.unstable) zsh; })
];
# Channel specific overlays
overlaysBuilder = channels: [ ];
# Channel specific configuration. Overwrites `channelsConfig` argument
config = {
allowUnfree = false;
};
};
# Additional channel input
channels.unstable.input = unstable;
channels.unstable.overlaysFunc = channels: [
(final: prev: {
neovim-nightly = neovim.defaultPackage.${prev.system};
})
];
# Default configuration values for `channels.<name>.config = {...}`
channelsConfig = {
allowBroken = true;
allowUnfree = true;
};
# Profiles, gets parsed into `nixosConfigurations`
nixosProfiles = {
# Profile name / System hostname
Morty = {
# System architecture. Defaults to `defaultSystem` argument
system = "x96_64-linux";
# <name> of the channel to be used
channelName = "unstable";
# Extra arguments to be passed to the modules. Overwrites `sharedExtraArgs` argument
extraArgs = {
abc = 123;
# Channel specific configuration. Overwrites `channelsConfig` argument
config = { allowUnfree = false; };
};
# Additional channel input
channels.unstable.input = unstable;
# Yep, you see it first folks - you can patch nixpkgs!
channels.unstable.patches = [ ./myNixpkgsPatch.patch ];
# Default configuration values for `channels.<name>.config = {...}`
channelsConfig.allowUnfree = true;
# Profiles, gets parsed into `nixosConfigurations`
nixosProfiles = {
# Profile name / System hostname
FirstHost = {
# System architecture. Defaults to `defaultSystem` argument
system = "x86_64-linux";
# <name> of the channel to be used. Defaults to `nixpkgs`
channelName = "unstable";
# Extra arguments to be passed to the modules. Overwrites `sharedExtraArgs` argument
extraArgs = { };
# Host specific configuration
modules = [ ];
};
OtherHost = { ... };
};
# Host specific configuration. Same as `sharedModules`
modules = [
(import ./configurations/Morty.host.nix)
];
};
};
# Extra arguments to be passed to modules
sharedExtraArgs = { inherit utils; };
# Overlays, gets applied to all `channels.<name>.input`
sharedOverlays = [
# Overlay imported from `./overlays`. (Defined below)
self.overlays
# Nix User Repository overlay
nur.overlay
];
# Shared modules/configurations between `nixProfiles`
sharedModules = [
home-manager.nixosModules.home-manager
(import ./modules)
{
# Sets sane `nix.*` defaults. Please refer to implementation/readme for more details.
nix = utils.lib.nixDefaultsFromInputs inputs;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
### Postfix of keys below might change in soon future.
# Evaluates to `packages.<system>.attributeKey = "attributeValue"`
packagesFunc = channels: { attributeKey = "attributeValue"; };
# Evaluates to `defaultPackage.<system>.attributeKey = "attributeValue"`
defaultPackageFunc = channels: { attributeKey = "attributeValue"; };
# Evaluates to `apps.<system>.attributeKey = "attributeValue"`
appsFunc = channels: { attributeKey = "attributeValue"; };
# Evaluates to `defaultApp.<system>.attributeKey = "attributeValue"`
defaultAppFunc = channels: { attributeKey = "attributeValue"; };
# Evaluates to `devShell.<system>.attributeKey = "attributeValue"`
devShellFunc = channels: { attributeKey = "attributeValue"; };
# Evaluates to `checks.<system>.attributeKey = "attributeValue"`
checksFunc = channels: { attributeKey = "attributeValue"; };
# All other values gets passed down to the flake
overlay = import ./overlays;
abc = 132;
# etc
};
```
# Extra arguments to be passed to modules. Defaults to `{ inherit inputs; }`
sharedExtraArgs = { };
# Other Examples #
# Shared overlays between channels, gets applied to all `channels.<name>.input`
sharedOverlays = [ ];
# Shared modules/configurations between `nixosProfiles`
sharedModules = [ utils.nixosModules.saneFlakeDefaults ];
# Evaluates to `packages.<system>.attributeKey = "attributeValue"`
packagesBuilder = channels: { attributeKey = "attributeValue"; };
# Evaluates to `defaultPackage.<system>.attributeKey = "attributeValue"`
defaultPackageBuilder = channels: { attributeKey = "attributeValue"; };
# Evaluates to `apps.<system>.attributeKey = "attributeValue"`
appsBuilder = channels: { attributeKey = "attributeValue"; };
# Evaluates to `defaultApp.<system>.attributeKey = "attributeValue"`
defaultAppBuilder = channels: { attributeKey = "attributeValue"; };
# Evaluates to `devShell.<system>.attributeKey = "attributeValue"`
devShellBuilder = channels: { attributeKey = "attributeValue"; };
# Evaluates to `checks.<system>.attributeKey = "attributeValue"`
checksBuilder = channels: { attributeKey = "attributeValue"; };
};
}
```

- [Gytis Dotfiles](https://github.com/gytis-ivaskevicius/nixfiles/blob/master/flake.nix)
- [Justin Dotfiles](https://github.com/DieracDelta/flakes/blob/flakes/flake.nix)
- [fufexan Dotfiles](https://github.com/fufexan/nixos-config/blob/master/flake.nix)
- [Bobbbay Dotfiles](https://github.com/Bobbbay/dotfiles/blob/master/flake.nix)

49 changes: 26 additions & 23 deletions examples/fully-featured-flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
outputs = inputs@{ self, nixpkgs, unstable, nur, utils, home-manager, neovim }:
utils.lib.systemFlake {

# Required arguments
# `self` and `inputs` arguments are REQUIRED!!!!!!!!!!!!!!
inherit self inputs;

# Supported systems, used for packages, apps, devShell and multiple other definitions. Defaults to `flake-utils.lib.defaultSystems`
supportedSystems = [ "aarch64-linux" "x86_64-linux" ];

# Default architecture to be used for `nixosProfiles` defaults to "x86_64-linux". Might get renamed in near future
# Default architecture to be used for `nixosProfiles` defaults to "x86_64-linux"
defaultSystem = "aarch64-linux";

# Channel definitions. `channels.<name>.{input,overlaysFunc,config}`
# Channel definitions. `channels.<name>.{input,overlaysBuilder,config,patches}`
channels.nixpkgs = {
# Channel input to import
input = nixpkgs;

# Channel specific overlays
overlaysFunc = channels: [
overlaysBuilder = channels: [
(final: prev: { inherit (channels.unstable) zsh; })
];

Expand All @@ -50,7 +50,9 @@

# Additional channel input
channels.unstable.input = unstable;
channels.unstable.overlaysFunc = channels: [
# Yep, you see it first folks - you can patch nixpkgs!
channels.unstable.patches = [ ./myNixpkgsPatch.patch ];
channels.unstable.overlaysBuilder = channels: [
(final: prev: {
neovim-nightly = neovim.defaultPackage.${prev.system};
})
Expand All @@ -68,8 +70,8 @@
# Profile name / System hostname
Morty = {
# System architecture. Defaults to `defaultSystem` argument
system = "x96_64-linux";
# <name> of the channel to be used
system = "x86_64-linux";
# <name> of the channel to be used. Defaults to `nixpkgs`
channelName = "unstable";
# Extra arguments to be passed to the modules. Overwrites `sharedExtraArgs` argument
extraArgs = {
Expand All @@ -82,46 +84,47 @@
};
};

# Extra arguments to be passed to modules
sharedExtraArgs = { inherit utils; };
# Extra arguments to be passed to modules. Defaults to `{ inherit inputs; }`
sharedExtraArgs = { inherit utils inputs; };

# Overlays, gets applied to all `channels.<name>.input`
# Shared overlays between channels, gets applied to all `channels.<name>.input`
sharedOverlays = [
# Overlay imported from `./overlays`. (Defined below)
self.overlays
# Nix User Repository overlay
nur.overlay
];

# Shared modules/configurations between `nixProfiles`
# Shared modules/configurations between `nixosProfiles`
sharedModules = [
home-manager.nixosModules.home-manager
# Sets sane `nix.*` defaults. Please refer to implementation/readme for more details.
utils.nixosModules.saneFlakeDefaults
(import ./modules)
{
# Sets sane `nix.*` defaults. Please refer to implementation/readme for more details.
nix = utils.lib.nixDefaultsFromInputs inputs;

home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];



### Postfix of keys below might change in soon future.

# Evaluates to `packages.<system>.attributeKey = "attributeValue"`
packagesFunc = channels: { attributeKey = "attributeValue"; };
packagesBuilder = channels: { attributeKey = "attributeValue"; };

# Evaluates to `defaultPackage.<system>.attributeKey = "attributeValue"`
defaultPackageFunc = channels: { attributeKey = "attributeValue"; };
defaultPackageBuilder = channels: { attributeKey = "attributeValue"; };

# Evaluates to `apps.<system>.attributeKey = "attributeValue"`
appsFunc = channels: { attributeKey = "attributeValue"; };
appsBuilder = channels: { attributeKey = "attributeValue"; };

# Evaluates to `defaultApp.<system>.attributeKey = "attributeValue"`
defaultAppFunc = channels: { attributeKey = "attributeValue"; };
defaultAppBuilder = channels: { attributeKey = "attributeValue"; };

# Evaluates to `devShell.<system>.attributeKey = "attributeValue"`
devShellFunc = channels: { attributeKey = "attributeValue"; };
devShellBuilder = channels: { attributeKey = "attributeValue"; };

# Evaluates to `checks.<system>.attributeKey = "attributeValue"`
checksFunc = channels: { attributeKey = "attributeValue"; };
checksBuilder = channels: { attributeKey = "attributeValue"; };

# All other values gets passed down to the flake
overlay = import ./overlays;
Expand Down
Loading

0 comments on commit 51cb739

Please sign in to comment.