Skip to content

Commit

Permalink
compat: fixes
Browse files Browse the repository at this point in the history
* fix nixos-option
* use flake-compat for all backward compat concerns
* rebuild devshell after any nix file changes
* reexport system pkgs as legacyPackages
* provide lib flake output
* provide flake lib to nixos configs via `lib.flk`
* clean up flake.nix
  • Loading branch information
nrdxp committed Jan 23, 2021
1 parent 7002009 commit 1b80806
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
watch_file shell.nix
watch_file **/*.nix
use flake || use nix
13 changes: 13 additions & 0 deletions compat/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let
flake = (import
(
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "sha256:0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
}
)
{
src = ../.;
});
in
flake
17 changes: 0 additions & 17 deletions compat/fetch.nix

This file was deleted.

10 changes: 10 additions & 0 deletions compat/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ ... }:
let
inherit (default.inputs.nixos) lib;

host = configs.${hostname} or configs.NixOS;
configs = default.nixosConfigurations;
default = (import ../.).defaultNix;
hostname = lib.fileContents /etc/hostname;
in
host
5 changes: 0 additions & 5 deletions compat/nixpkgs.nix

This file was deleted.

41 changes: 0 additions & 41 deletions configuration.nix

This file was deleted.

17 changes: 4 additions & 13 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
let
inherit (flake.inputs.nixos.lib) recurseIntoAttrs mapAttrs;
flake = (import
(
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "sha256:0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
}
)
{
src = ./.;
}).defaultNix;
recurse = mapAttrs (_: v: recurseIntoAttrs v) flake.packages;
inherit (default.inputs.nixos.lib) recurseIntoAttrs;

default = (import ./compat).defaultNix;
in
recurse
builtins.mapAttrs (_: v: recurseIntoAttrs v) default.packages
74 changes: 40 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,34 @@

outputs = inputs@{ self, home, nixos, master, flake-utils, nur, devshell, nixos-hardware }:
let
inherit (builtins) attrNames attrValues elem pathExists;
inherit (flake-utils.lib) eachDefaultSystem mkApp flattenTreeSystem;
inherit (nixos) lib;
inherit (lib) recursiveUpdate filterAttrs mapAttrs;
inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules
genPackages pkgImport;

utils = import ./lib/utils.nix { inherit lib; };
inherit (builtins) attrValues;
inherit (flake-utils.lib) eachDefaultSystem flattenTreeSystem;
inherit (nixos.lib) recursiveUpdate;
inherit (self.lib) overlays nixosModules genPackages pkgImport;

externOverlays = [ nur.overlay devshell.overlay ];
externModules = [ home.nixosModules.home-manager ];

pkgs' = unstable:
let
override = import ./pkgs/override.nix;
overlays = (attrValues self.overlays)
++ externOverlays
++ [ self.overlay (override unstable) ];
in
pkgImport nixos overlays;

unstable' = pkgImport master [ ];

osSystem = "x86_64-linux";

outputs =
let
system = osSystem;
unstablePkgs = unstable' system;
osPkgs = pkgs' unstablePkgs system;
system = "x86_64-linux";
pkgs = self.legacyPackages.${system};
in
{
inherit nixosModules overlays;

nixosConfigurations =
import ./hosts (recursiveUpdate inputs {
inherit lib osPkgs unstablePkgs utils externModules system;
});
import ./hosts
(recursiveUpdate inputs {
inherit pkgs externModules system;
inherit (pkgs) lib;
});

overlay = import ./pkgs;

overlays = pathsToImportedAttrs overlayPaths;

nixosModules = modules;
lib = import ./lib {
inherit (nixos) lib;
};

templates.flk.path = ./.;

Expand All @@ -69,8 +55,26 @@
(eachDefaultSystem
(system:
let
unstablePkgs = unstable' system;
pkgs = pkgs' unstablePkgs system;
unstable = pkgImport master [ ] system;

pkgs =
let
override = import ./pkgs/override.nix;
overlays = (attrValues self.overlays)
++ externOverlays
++ [
self.overlay
(override unstable)
(final: prev: {
lib = (prev.lib or { }) // {
inherit (nixos.lib) nixosSystem;
flk = self.lib;
utils = flake-utils.lib;
};
})
];
in
pkgImport nixos overlays system;

packages = flattenTreeSystem system
(genPackages {
Expand All @@ -80,9 +84,11 @@
{
inherit packages;

devShell = import ./shell.nix {
inherit pkgs;
devShell = import ./shell {
inherit pkgs nixos;
};

legacyPackages = pkgs;
}
)
)
Expand Down
9 changes: 3 additions & 6 deletions hosts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
, nixos
, master
, nixos-hardware
, osPkgs
, pkgs
, self
, system
, unstablePkgs
, utils
, externModules
, ...
}:
let
inherit (utils) recImport;
inherit (lib.flk) recImport;
inherit (builtins) attrValues removeAttrs;

unstableModules = [ ];
Expand Down Expand Up @@ -50,12 +48,11 @@ let
[
"nixos-unstable=${master}"
"nixpkgs=${nixos}"
"nixos-config=${path}/configuration.nix"
"nixpkgs-overlays=${path}/overlays"
"home-manager=${home}"
];

nixpkgs.pkgs = osPkgs;
nixpkgs = { inherit pkgs; };

nix.registry = {
master.flake = master;
Expand Down
14 changes: 9 additions & 5 deletions lib/utils.nix → lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let
# Generate an attribute set by mapping a function over a list of values.
genAttrs' = values: f: listToAttrs (map f values);

# pkgImport :: Nixpkgs -> Overlays -> System -> Pkgs
pkgImport = nixpkgs: overlays: system:
import nixpkgs {
inherit system overlays;
Expand All @@ -23,23 +24,26 @@ let
# Convert a list to file paths to attribute set
# that has the filenames stripped of nix extension as keys
# and imported content of the file as value.
#
pathsToImportedAttrs = paths:
genAttrs' paths (path: {
name = removeSuffix ".nix" (baseNameOf path);
value = import path;
});

in
{
inherit mapFilterAttrs genAttrs' pkgImport pathsToImportedAttrs;

overlayPaths =
let
overlayDir = ../overlays;
fullPath = name: overlayDir + "/${name}";
in
map fullPath (attrNames (readDir overlayDir));

in
{
inherit mapFilterAttrs genAttrs' pkgImport pathsToImportedAttrs;

overlays = pathsToImportedAttrs overlayPaths;

recImport = { dir, _import ? base: import "${dir}/${base}.nix" }:
mapFilterAttrs
(_: v: v != null)
Expand All @@ -51,7 +55,7 @@ in
nameValuePair ("") (null))
(readDir dir);

modules =
nixosModules =
let
# binary cache
cachix = import ../cachix.nix;
Expand Down
3 changes: 3 additions & 0 deletions profiles/core/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ in
manix "" | grep '^# ' | sed 's/^# \(.*\) (.*/\1/;s/ (.*//;s/^# //' | sk --preview="manix '{}'" | xargs manix
'';

# fix nixos-option
nixos-option = "nixos-option -I nixpkgs=${toString ../../compat}";

# sudo
s = ifSudo "sudo -E ";
si = ifSudo "sudo -i";
Expand Down
Loading

0 comments on commit 1b80806

Please sign in to comment.