Skip to content

Commit

Permalink
Merge pull request #6 from gytis-ivaskevicius/staging
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
gytis-ivaskevicius authored Apr 25, 2021
2 parents 51cb739 + d37a46e commit e7ae270
Show file tree
Hide file tree
Showing 27 changed files with 938 additions and 442 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
51 changes: 51 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI
on:
push:
workflow_dispatch:
pull_request:
types: [opened]

jobs:
quality-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: cachix/install-nix-action@v13
with:
nix_path: nixpkgs=channel:nixos-unstable
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-3.0pre20201007_5257a25/install
extra_nix_config: experimental-features = nix-command flakes

- name: Check Nix parsing
run: find . -name "*.nix" -exec nix-instantiate --parse --quiet {} >/dev/null +

- name: Run `nix flake check`
run: cd examples/fully-featured && nix flake check --show-trace

- name: Run `nix flake show`
run: cd examples/fully-featured && nix flake show --show-trace

- name: Build Morty configuration
run: cd examples/fully-featured && nix build .#nixosConfigurations.Morty.config.system.build.toplevel --dry-run

- name: Build Rick configuration
run: cd examples/fully-featured && nix build .#someConfigurations.Rick.config.system.build.toplevel --dry-run

- name: Build Summer checks
run: cd examples/fully-featured && nix build .#checks.x86_64-linux.summerHasUnfreeConfigured && nix build .#checks.x86_64-linux.summerHasPackageOverridesConfigured && nix build .#checks.x86_64-linux.summerHasCustomModuleConfigured

- name: Run `nix flake check`
run: cd examples/somewhat-realistic && nix flake check --show-trace

- name: Run `nix flake show`
run: cd examples/somewhat-realistic && nix flake show --show-trace

- name: Build HostnameOne configuration
run: cd examples/somewhat-realistic && nix build .#nixosConfigurations.HostnameOne.config.system.build.toplevel --dry-run

- name: Check Nix formatting
run: nix shell nixpkgs\#nixpkgs-fmt -c nixpkgs-fmt --check .

- name: Build HostnameThree configuration
run: cd examples/somewhat-realistic && nix build .#darwinConfigurations.HostnameThree.config.system.build.toplevel --dry-run

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/*/flake.lock
184 changes: 123 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

[![Discord](https://img.shields.io/discord/591914197219016707.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.com/invite/RbvHtGa)

Need help? Createn an issue or ping @Gytis#0001 in discord server above.

# What is this flake #

This flake exposes a library abstraction to *painlessly* generate nixos flake configurations.
Expand All @@ -11,101 +15,159 @@ 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; }`.
- `lib.exporter.modulesFromListExporter [ ./a.nix ./b.nix ]` - Generates modules attributes which looks like this `{ a = import ./a.nix; b = import ./b.nix; }`.
- `lib.exporter.overlaysFromChannelsExporter channels` - Collects all overlays from channels and exports them as an appropriately namespaced attribute set. Users can instantiate with their nixpkgs version.
- `lib.builder.packagesFromOverlayBuilderConstructor channels pkgs` - Similar to the overlay generator, but outputs them as packages, instead. Users can use your cache.


# Examples #

- [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)
- [Fufexan Dotfiles](https://github.com/fufexan/dotfiles/blob/main/flake.nix)
- [Bobbbay Dotfiles](https://github.com/Bobbbay/dotfiles/blob/master/flake.nix)
- [Charlotte Dotfiles](https://github.com/chvp/nixos-config/blob/master/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).
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). (WARNING: Quite overwhelming)

And more realistic flake example can be found [Here](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/master/examples/somewhat-realistic-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).

I strongly recommend referring to actual people examples above when setting up your system.

Looking to add a kick-ass repl to your config? Create and import something along the lines of this:
```nix
{ inputs, ... }:
{
outputs = inputs@{ self, nixpkgs, unstable, nur, utils, home-manager, neovim }:
utils.lib.systemFlake {
environment.shellAliases = {
very-cool-nix-repl = "nix repl ${inputs.utils.lib.repl}";
};
}
```

## Documentation as code. Options with their example usage and description.

```nix
let
inherit (builtins) removeAttrs;
mkApp = utils.lib.mkApp;
# If there is a need to get direct reference to nixpkgs - do this:
pkgs = self.pkgs.x86_64-linux.nixpkgs;
in flake-utils-plus.lib.systemFlake {
# `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 = [ "x86_64-linux" ];
# `self` and `inputs` arguments are REQUIRED!!!!!!!!!
inherit self inputs;
################
### channels ###
################
# Supported systems, used for packages, apps, devShell and multiple other definitions. Defaults to `flake-utils.lib.defaultSystems`
supportedSystems = [ "aarch64-linux" "x86_64-linux" ];
# Configuration that is shared between all channels.
channelsConfig = { allowBroken = true; };
# Default architecture to be used for `nixosProfiles` defaults to "x86_64-linux"
defaultSystem = "aarch64-linux";
# Overlays which are applied to all channels.
sharedOverlays = [ nur.overlay ];
# Channel definitions. `channels.<name>.{input,overlaysBuilder,config,patches}`
channels.nixpkgs = {
# Channel input to import
input = nixpkgs;
# Nixpkgs flake reference to be used in the configuration.
channels.<name>.input = nixpkgs;
# Channel specific overlays
overlaysBuilder = channels: [ ];
# Channel specific config options.
channels.<name>.config = { allowUnfree = true; };
# Channel specific configuration. Overwrites `channelsConfig` argument
config = { allowUnfree = false; };
};
# Patches to apply on selected channel.
channels.<name>.patches = [ ./someAwesomePatch.patch ];
# Additional channel input
channels.unstable.input = unstable;
# Yep, you see it first folks - you can patch nixpkgs!
channels.unstable.patches = [ ./myNixpkgsPatch.patch ];
# Overlays to apply on a selected channel.
channels.<name>.overlaysBuilder = channels: [
(final: prev: { inherit (channels.unstable) neovim; })
];
# Default configuration values for `channels.<name>.config = {...}`
channelsConfig.allowUnfree = true;
####################
### hostDefaults ###
####################
# 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 = [ ];
};
# Default architecture to be used for `hosts` defaults to "x86_64-linux".
hostDefaults.system = "x86_64-linux";
OtherHost = { ... };
};
# Default modules to be passed to all hosts.
hostDefaults.modules = [ utils.nixosModules.saneFlakeDefaults ];
# Extra arguments to be passed to modules. Defaults to `{ inherit inputs; }`
sharedExtraArgs = { };
# Reference to `channels.<name>.*`, defines default channel to be used by hosts. Defaults to "nixpkgs".
hostDefaults.channelName = "unstable";
# Shared overlays between channels, gets applied to all `channels.<name>.input`
sharedOverlays = [ ];
# Extra arguments to be passed to all modules. Merged with host's extraArgs.
hostDefaults.extraArgs = { inherit utils inputs; foo = "foo"; };
# Shared modules/configurations between `nixosProfiles`
sharedModules = [ utils.nixosModules.saneFlakeDefaults ];
#############
### hosts ###
#############
# Evaluates to `packages.<system>.attributeKey = "attributeValue"`
packagesBuilder = channels: { attributeKey = "attributeValue"; };
# System architecture. Defaults to `defaultSystem` argument.
hosts.<hostname>.system = "aarch64-linux";
# Evaluates to `defaultPackage.<system>.attributeKey = "attributeValue"`
defaultPackageBuilder = channels: { attributeKey = "attributeValue"; };
# <name> of the channel to be used. Defaults to `nixpkgs`;
hosts.<hostname>.channelName = "unstable";
# Evaluates to `apps.<system>.attributeKey = "attributeValue"`
appsBuilder = channels: { attributeKey = "attributeValue"; };
# Extra arguments to be passed to the modules.
hosts.<hostname>.extraArgs = { abc = 123; };
# Evaluates to `defaultApp.<system>.attributeKey = "attributeValue"`
defaultAppBuilder = channels: { attributeKey = "attributeValue"; };
# These are not part of the module system, so they can be used in `imports` lines without infinite recursion.
hosts.<hostname>.specialArgs = { thing = "abc"; };
# Evaluates to `devShell.<system>.attributeKey = "attributeValue"`
devShellBuilder = channels: { attributeKey = "attributeValue"; };
# Host specific configuration.
hosts.<hostname>.modules = [ ./configuration.nix ];
# Evaluates to `checks.<system>.attributeKey = "attributeValue"`
checksBuilder = channels: { attributeKey = "attributeValue"; };
# Flake output for configuration to be passed to. Defaults to `nixosConfigurations`.
hosts.<hostname>.output = "darwinConfigurations";
# System builder. Defaults to `channels.<name>.input.lib.nixosSystem`.
# `removeAttrs` workaround due to this issue https://github.com/LnL7/nix-darwin/issues/319
hosts.<hostname>.builder = args: nix-darwin.lib.darwinSystem (removeAttrs args [ "system" ]);
#############################
### flake output builders ###
#############################
# Evaluates to `packages.<system>.coreutils = <unstable-channel-reference>.coreutils`.
packagesBuilder = channels: { inherit (channels.unstable) coreutils; };
# Evaluates to `defaultPackage.<system>.neovim = <nixpkgs-channel-reference>.neovim`.
defaultPackageBuilder = channels: channels.nixpkgs.neovim;
# Evaluates to `apps.<system>.custom-neovim = utils.lib.mkApp { drv = ...; exePath = ...; };`.
appsBuilder = channels: with channels.nixpkgs; {
custom-neovim = mkApp {
drv = fancy-neovim;
exePath = "/bin/nvim";
};
};
# Evaluates to `apps.<system>.firefox = utils.lib.mkApp { drv = ...; };`.
defaultAppBuilder = channels: mkApp { drv = channels.nixpkgs.firefox; };
# Evaluates to `devShell.<system> = <nixpkgs-channel-reference>.mkShell { name = "devShell"; };`.
devShellBuilder = channels: channels.nixpkgs.mkShell { name = "devShell"; };
#########################################################
### All other properties are passed down to the flake ###
#########################################################
checks.x86_64-linux.someCheck = pkgs.hello;
packages.x86_64-linux.somePackage = pkss.hello;
overlay = import ./overlays;
abc = 132;
}
```


Loading

0 comments on commit e7ae270

Please sign in to comment.