Skip to content

Commit

Permalink
Merge pull request #46 from gytis-ivaskevicius/staging
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
gytis-ivaskevicius authored Sep 5, 2021
2 parents e7ae270 + ccc1137 commit 231acaa
Show file tree
Hide file tree
Showing 45 changed files with 1,514 additions and 761 deletions.
50 changes: 17 additions & 33 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,30 @@ on:
types: [opened]

jobs:
quality-gate:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- 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
install_url: https://github.com/numtide/nix-unstable-installer/releases/download/nix-2.4pre20210604_8e6ee1b/install
extra_nix_config: experimental-features = nix-command flakes

- name: Check Nix parsing
run: find . -name "*.nix" -exec nix-instantiate --parse --quiet {} >/dev/null +
# Quick eval
- run: nix develop --command evalnix

- name: Run `nix flake check`
run: cd examples/fully-featured && nix flake check --show-trace
# Execute /tests/*
- run: nix develop --command check-derivation-outputs
- run: nix develop --command check-derivation-outputs-old
- run: nix develop --command check-channel-patching
- run: nix develop --command check-overlays-flow
- run: nix develop --command check-hosts-config

- 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
# Build /examples/*
- run: nix develop --command build-home-manager+nur+neovim-Rick
- run: nix develop --command build-minimal-multichannel-Hostname1
- run: nix develop --command build-minimal-multichannel-Hostname2
- run: nix develop --command build-exporters-Morty

# Check formatting
- run: nix develop --command fmt --check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
examples/*/flake.lock
examples/*/result
113 changes: 63 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,74 @@

[![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.
Need help? Create an issue or ping @Gytis#0001 in the above Discord Server.

# What is this flake #
# Changing branching policy #
From now on `master` serves as a development branch (previously `staging` was used for such purposes). Please use tags for stable releases of flake-utils-plus.
In general, with the improvements in test harness, releases might happen more frequently. Sticking with a tagged release might offer better trade-offs going forward.

This flake exposes a library abstraction to *painlessly* generate nixos flake configurations.
Please note, while 1.2.0 retains backwards compatibility, 1.2.1 is the same version with all backwards compatibility removed.

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 #
# What is this flake? #

This flake provides two main features (visible from `flake.nix`):
Flake-utils-plus exposes a library abstraction to *painlessly* generate NixOS flake configurations.

- `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.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.
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 the flake #

# Examples #
Main flake-utils-plus features (Attributes visible from `flake.nix`):
- Extends [flake-utils](https://github.com/numtide/flake-utils). Everything exported by fu can be used from this flake.
- `lib.mkFlake { ... }` - Clean and pleasant to use flakes abstraction.
- Option [`nix.generateRegistryFromInputs`](./lib/options.nix) - Generates `nix.registry` from flake inputs.
- Option [`nix.generateNixPathFromInputs`](./lib/options.nix) - Generate `nix.nixPath` from available inputs.
- Option [`nix.linkInputs`](./lib/options.nix) - Symlink inputs to /etc/nix/inputs.
- Simple and clean support for multiple `nixpkgs` references.
- `nixpkgs` references patching.
- `channelsConfig` - Config applied to all `nixpkgs` references.
- `hostDefaults` - Default configuration shared between host definitions.
- `outputsBuilder` - Clean way to export packages/apps/etc.
- `sharedOverlays` - Overlays applied on all imported channels.
- [`lib.exportModules [ ./a.nix ./b.nix ]`](./lib/exportModules.nix) - Generates module attribute which look like this `{ a = import ./a.nix; b = import ./b.nix; }`.
- [`lib.exportOverlays channels`](./lib/exportOverlays.nix) - Exports all overlays from channels as an appropriately namespaced attribute set. Users can instantiate with their nixpkgs version.
- [`lib.exportPackages self.overlays channels`](./lib/exportPackages.nix) - Similar to the overlay generator, but outputs them as packages for the platforms defined in `meta.platforms`. Unlike overlays, these packages are consistent across flakes allowing them to be cached.
- [`pkgs.fup-repl`](./lib/overlay.nix) - A package that adds a kick-ass repl. Usage:
- `$ repl` - Loads your system repl into scope as well as `pkgs` and `lib` from `nixpkgs` input.
- `$ repl /path/to/flake.nix` - Same as above but loads the specified flake.

- [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)
- [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 #

# How to use this flake #
* [Example of using multiple channels](./examples/minimal-multichannel)

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)
* [Exporters usage example](./examples/exporters)

And more realistic flake example can be found [Here](https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/master/examples/somewhat-realistic/flake.nix).
* [Using FUP to configure hosts with Home Manager, NUR and neovim](./examples/home-manager+nur+neovim)

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

Looking to add a kick-ass repl to your config? Create and import something along the lines of this:
```nix
{ inputs, ... }:
We recommend referring to people's examples below when setting up your system.

{
environment.shellAliases = {
very-cool-nix-repl = "nix repl ${inputs.utils.lib.repl}";
};
}
- [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)
- [Bobbbay Dotfiles](https://github.com/Bobbbay/dotfiles/blob/master/flake.nix)
- [Charlotte Dotfiles](https://github.com/chvp/nixos-config/blob/master/flake.nix)

```

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

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 {
in flake-utils-plus.lib.mkFlake {
# `self` and `inputs` arguments are REQUIRED!!!!!!!!!!!!!!
# `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`.
Expand All @@ -76,6 +86,7 @@ in flake-utils-plus.lib.systemFlake {
sharedOverlays = [ nur.overlay ];
# Nixpkgs flake reference to be used in the configuration.
# Autogenerated from `inputs` by default.
channels.<name>.input = nixpkgs;
# Channel specific config options.
Expand All @@ -98,7 +109,7 @@ in flake-utils-plus.lib.systemFlake {
hostDefaults.system = "x86_64-linux";
# Default modules to be passed to all hosts.
hostDefaults.modules = [ utils.nixosModules.saneFlakeDefaults ];
hostDefaults.modules = [ ./module.nix ./module2 ];
# Reference to `channels.<name>.*`, defines default channel to be used by hosts. Defaults to "nixpkgs".
hostDefaults.channelName = "unstable";
Expand Down Expand Up @@ -135,28 +146,31 @@ in flake-utils-plus.lib.systemFlake {
#############################
### flake output builders ###
### flake outputs builder ###
#############################
# 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";
outputsBuilder = channels: {
# Evaluates to `apps.<system>.custom-neovim = utils.lib.mkApp { drv = ...; exePath = ...; };`.
apps = {
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 `packages.<system>.coreutils = <unstable-nixpkgs-reference>.package-from-overlays`.
packages = { inherit (channels.unstable) package-from-overlays; };
# Evaluates to `devShell.<system> = <nixpkgs-channel-reference>.mkShell { name = "devShell"; };`.
devShellBuilder = channels: channels.nixpkgs.mkShell { name = "devShell"; };
# Evaluates to `apps.<system>.firefox = utils.lib.mkApp { drv = ...; };`.
defaultApp = mkApp { drv = channels.nixpkgs.firefox };
# Evaluates to `defaultPackage.<system>.neovim = <nixpkgs-channel-reference>.neovim`.
defaultPackage = channels.nixpkgs.neovim;
# Evaluates to `devShell.<system> = <nixpkgs-channel-reference>.mkShell { name = "devShell"; };`.
devShell = channels.nixpkgs.mkShell { name = "devShell"; };
};
#########################################################
Expand All @@ -170,4 +184,3 @@ in flake-utils-plus.lib.systemFlake {
}
```

86 changes: 86 additions & 0 deletions devShell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{ system ? builtins.currentSystem }:
let
# nixpkgs / devshell is only used for development. Don't add it to the flake.lock.
nixpkgsGitRev = "82d05e980543e1703cbfd3b5ccd1fdcd4b0f1f00";
devshellGitRev = "26f25a12265f030917358a9632cd600b51af1d97";

nixpkgsSrc = fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${nixpkgsGitRev}.tar.gz";
sha256 = "02yqgivv8kxksv7n6vmh22qxprlfjh4rfkgf98w46nssq5ahdb1q";
};

devshellSrc = fetchTarball {
url = "https://github.com/numtide/devshell/archive/${devshellGitRev}.tar.gz";
sha256 = "sha256:0f6fph5gahm2bmzd399mba6b0h6wp6i1v3gryfmgwp0as7mwqpj7";
};

pkgs = import nixpkgsSrc { inherit system; };
devshell = import devshellSrc { inherit system pkgs; };

withCategory = category: attrset: attrset // { inherit category; };
util = withCategory "utils";

test = name: withCategory "tests" {
name = "check-${name}";
help = "Checks ${name} testcases";
command = ''
set -e
echo -e "\n\n##### Building ${name}\n"
cd $DEVSHELL_ROOT/tests/${name}
nix flake show --no-write-lock-file "$@"
nix flake check --no-write-lock-file "$@"
'';
};

dry-nixos-build = example: host: withCategory "dry-build" {
name = "build-${example}-${host}";
command = ''
set -e
echo -e "\n\n##### Building ${example}-${host}\n"
cd $DEVSHELL_ROOT/examples/${example}
nix flake show --no-write-lock-file "$@"
nix build .#nixosConfigurations.${host}.config.system.build.toplevel --no-write-lock-file --no-link "$@"
'';
};

in
devshell.mkShell {
name = "flake-utils-plus";
packages = with pkgs; [
fd
nixpkgs-fmt
];

commands = [
{
command = "git rm --ignore-unmatch -f $DEVSHELL_ROOT/{tests,examples}/*/flake.lock";
help = "Remove all lock files";
name = "rm-locks";
}
{
name = "fmt";
help = "Check Nix formatting";
command = "nixpkgs-fmt \${@} $DEVSHELL_ROOT";
}
{
name = "evalnix";
help = "Check Nix parsing";
command = "fd --extension nix --exec nix-instantiate --parse --quiet {} >/dev/null";
}

(test "channel-patching")
(test "derivation-outputs")
(test "derivation-outputs-old")
(test "hosts-config")
(test "overlays-flow")
(test "all" // { command = "check-channel-patching && check-derivation-outputs && check-derivation-outputs-old && check-hosts-config && check-overlays-flow"; })

(dry-nixos-build "minimal-multichannel" "Hostname1")
(dry-nixos-build "minimal-multichannel" "Hostname2")
(dry-nixos-build "home-manager+nur+neovim" "Rick")
(dry-nixos-build "exporters" "Morty")
(withCategory "dry-build" { name = "build-all"; command = "build-exporters-Morty && build-home-manager+nur+neovim-Rick && build-minimal-multichannel-Hostname1 && build-minimal-multichannel-Hostname2"; })

];

}
49 changes: 49 additions & 0 deletions examples/exporters/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
description = "FUP exporters demo";

inputs = {
nixpkgs.url = github:nixos/nixpkgs/release-21.05;
unstable.url = github:nixos/nixpkgs/nixos-unstable-small;
utils.url = path:../../;
};


outputs = inputs@{ self, nixpkgs, utils, ... }:
let
inherit (utils.lib) exportOverlays exportPackages exportModules;
in
utils.lib.systemFlake {
inherit self inputs;

# Channel specific overlays. Overlays `coreutils` from `unstable` channel.
channels.nixpkgs.overlaysBuilder = channels: [
(final: prev: { inherit (channels.unstable) ranger; })
];

# Propagates to channels.<name>.overlaysBuilder
sharedOverlays = [
self.overlay
];

hosts.Morty.modules = with self.nixosModules; [
Morty
];

nixosModules = exportModules [
./hosts/Morty.nix
];

# export overlays automatically for all packages defined in overlaysBuilder of each channel
overlays = exportOverlays {
inherit (self) pkgs inputs;
};

outputsBuilder = channels: {
# construct packagesBuilder to export all packages defined in overlays
packages = exportPackages self.overlays channels;
};

overlay = import ./overlays;

};
}
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/exporters/overlays/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
final: prev: {
inherit (prev) coreutils;
}
1 change: 0 additions & 1 deletion examples/fully-featured/configurations/Rick.host.nix

This file was deleted.

6 changes: 0 additions & 6 deletions examples/fully-featured/configurations/Summer.host.nix

This file was deleted.

Loading

0 comments on commit 231acaa

Please sign in to comment.