compat: fixes
* 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
This commit is contained in:
parent
7002009c86
commit
1b80806516
13
compat/default.nix
Normal file
13
compat/default.nix
Normal file
|
@ -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
|
|
@ -1,17 +0,0 @@
|
|||
let
|
||||
inherit (builtins)
|
||||
fetchTarball
|
||||
fromJSON
|
||||
readFile
|
||||
;
|
||||
lockfile = fromJSON (readFile ../flake.lock);
|
||||
in
|
||||
input:
|
||||
let
|
||||
locked = lockfile.nodes."${input}".locked;
|
||||
inherit (locked) rev narHash owner repo;
|
||||
in
|
||||
fetchTarball {
|
||||
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
||||
sha256 = narHash;
|
||||
}
|
10
compat/nixos/default.nix
Normal file
10
compat/nixos/default.nix
Normal file
|
@ -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
|
|
@ -1,5 +0,0 @@
|
|||
let
|
||||
fetch = import ./fetch.nix;
|
||||
nixpkgs = fetch "nixos";
|
||||
in
|
||||
nixpkgs
|
|
@ -1,41 +0,0 @@
|
|||
# this file is an impure recreation of the flake profile currently deployed
|
||||
# based on the systems hostname. The purpose is so tools which do not yet have
|
||||
# flake support (e.g `nixos-option`), can work as expected.
|
||||
{ lib, ... }:
|
||||
let
|
||||
inherit (builtins) attrNames readDir;
|
||||
|
||||
nixpkgs = toString (import ./nixpkgs-compat.nix);
|
||||
|
||||
hostname = lib.fileContents /etc/hostname;
|
||||
host = "/etc/nixos/hosts/${hostname}.nix";
|
||||
config =
|
||||
if (builtins.pathExists host) then
|
||||
[ host ]
|
||||
else
|
||||
[ /etc/nixos/hosts/NixOS.nix ];
|
||||
in
|
||||
{
|
||||
imports = (import ./modules/list.nix) ++ [
|
||||
"${
|
||||
builtins.fetchTarball
|
||||
"https://github.com/nix-community/home-manager/archive/master.tar.gz"
|
||||
}/nixos"
|
||||
/etc/nixos/profiles/core
|
||||
] ++ config;
|
||||
|
||||
networking.hostName = hostname;
|
||||
nix.nixPath = [
|
||||
"nixpkgs=${nixpkgs}"
|
||||
"nixos-config=/etc/nixos/configuration.nix"
|
||||
"nixpkgs-overlays=/etc/nixos/overlays"
|
||||
];
|
||||
|
||||
nixpkgs.overlays =
|
||||
let
|
||||
overlays = map
|
||||
(name: import (./overlays + "/${name}"))
|
||||
(attrNames (readDir ./overlays));
|
||||
in
|
||||
overlays;
|
||||
}
|
17
default.nix
17
default.nix
|
@ -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
flake.nix
74
flake.nix
|
@ -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 = ./.;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -80,9 +84,11 @@
|
|||
{
|
||||
inherit packages;
|
||||
|
||||
devShell = import ./shell.nix {
|
||||
inherit pkgs;
|
||||
devShell = import ./shell {
|
||||
inherit pkgs nixos;
|
||||
};
|
||||
|
||||
legacyPackages = pkgs;
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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 = [ ];
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -23,16 +24,13 @@ 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;
|
||||
|
@ -40,6 +38,12 @@ in
|
|||
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)
|
||||
|
@ -51,7 +55,7 @@ in
|
|||
nameValuePair ("") (null))
|
||||
(readDir dir);
|
||||
|
||||
modules =
|
||||
nixosModules =
|
||||
let
|
||||
# binary cache
|
||||
cachix = import ../cachix.nix;
|
|
@ -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";
|
||||
|
|
93
shell.nix
93
shell.nix
|
@ -1,92 +1 @@
|
|||
let
|
||||
nixpkgs = import ./compat/nixpkgs.nix;
|
||||
fetch = import ./compat/fetch.nix;
|
||||
|
||||
devshell' = fetch "devshell";
|
||||
pkgs' = import devshell' { inherit nixpkgs; };
|
||||
in
|
||||
{ pkgs ? pkgs', ... }:
|
||||
let
|
||||
build = "config.system.build";
|
||||
|
||||
installPkgs = (import "${nixpkgs}/nixos" {
|
||||
configuration = { };
|
||||
system = pkgs.system;
|
||||
}).config.system.build;
|
||||
|
||||
flk = pkgs.writeShellScriptBin "flk" ''
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] ]"
|
||||
elif [[ "$1" == "up" ]]; then
|
||||
mkdir -p up
|
||||
hostname=$(hostname)
|
||||
nixos-generate-config --dir up/$hostname
|
||||
echo \
|
||||
"{
|
||||
imports = [ ../up/$hostname/configuration.nix ];
|
||||
}" > hosts/up-$hostname.nix
|
||||
git add -f up/$hostname
|
||||
git add -f hosts/up-$hostname.nix
|
||||
elif [[ "$1" == "iso" ]]; then
|
||||
nix build $DEVSHELL_ROOT#nixosConfigurations.niximg.${build}.isoImage "${"\${@:2}"}"
|
||||
elif [[ "$1" == "install" ]]; then
|
||||
sudo nixos-install --flake ".#$2" "${"\${@:3}"}"
|
||||
else
|
||||
sudo nixos-rebuild --flake ".#$1" "${"\${@:2}"}"
|
||||
fi
|
||||
'';
|
||||
|
||||
name = "flk";
|
||||
in
|
||||
pkgs.mkDevShell {
|
||||
inherit name;
|
||||
|
||||
packages = with pkgs; with installPkgs; [
|
||||
git-crypt
|
||||
nixos-install
|
||||
nixos-generate-config
|
||||
nixos-enter
|
||||
pre-commit
|
||||
];
|
||||
|
||||
env = { inherit name; };
|
||||
|
||||
commands = with pkgs; [
|
||||
{
|
||||
name = nixpkgs-fmt.pname;
|
||||
package = nixpkgs-fmt;
|
||||
help = nixpkgs-fmt.meta.description;
|
||||
category = "linters";
|
||||
}
|
||||
{
|
||||
name = flk.name;
|
||||
help = "Build, deploy, and install nixflk";
|
||||
category = "main";
|
||||
package = flk;
|
||||
}
|
||||
{
|
||||
name = "hooks";
|
||||
help = "install git hooks";
|
||||
command = "pre-commit install";
|
||||
}
|
||||
{
|
||||
name = "grip";
|
||||
help = python38Packages.grip.meta.description;
|
||||
category = "servers";
|
||||
package = python38Packages.grip;
|
||||
}
|
||||
{
|
||||
name = git.pname;
|
||||
help = git.meta.description;
|
||||
category = "vcs";
|
||||
package = git;
|
||||
}
|
||||
{
|
||||
name = "nix";
|
||||
help = nixFlakes.meta.description;
|
||||
category = "main";
|
||||
command = ''${nixFlakes}/bin/nix --option experimental-features "nix-command flakes ca-references" "$@"'';
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
(import ./compat).shellNix
|
||||
|
|
89
shell/default.nix
Normal file
89
shell/default.nix
Normal file
|
@ -0,0 +1,89 @@
|
|||
{ pkgs ? (import ./compat).defaultNix.legacyPackages."${builtins.currentSystem}"
|
||||
, nixos ? (import ./compat).defaultNix.inputs.nixos
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
build = "config.system.build";
|
||||
|
||||
installPkgs = (import "${nixos}/nixos" {
|
||||
configuration = { };
|
||||
system = pkgs.system;
|
||||
}).config.system.build;
|
||||
|
||||
flk = pkgs.writeShellScriptBin "flk" ''
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] ]"
|
||||
elif [[ "$1" == "up" ]]; then
|
||||
mkdir -p up
|
||||
hostname=$(hostname)
|
||||
nixos-generate-config --dir up/$hostname
|
||||
echo \
|
||||
"{
|
||||
imports = [ ../up/$hostname/configuration.nix ];
|
||||
}" > hosts/up-$hostname.nix
|
||||
git add -f up/$hostname
|
||||
git add -f hosts/up-$hostname.nix
|
||||
elif [[ "$1" == "iso" ]]; then
|
||||
nix build $DEVSHELL_ROOT#nixosConfigurations.niximg.${build}.isoImage "${"\${@:2}"}"
|
||||
elif [[ "$1" == "install" ]]; then
|
||||
sudo nixos-install --flake ".#$2" "${"\${@:3}"}"
|
||||
else
|
||||
sudo nixos-rebuild --flake ".#$1" "${"\${@:2}"}"
|
||||
fi
|
||||
'';
|
||||
|
||||
name = "flk";
|
||||
in
|
||||
pkgs.mkDevShell {
|
||||
inherit name;
|
||||
|
||||
packages = with pkgs; with installPkgs; [
|
||||
git-crypt
|
||||
nixos-install
|
||||
nixos-generate-config
|
||||
nixos-enter
|
||||
nixos-option
|
||||
pre-commit
|
||||
];
|
||||
|
||||
env = { inherit name; };
|
||||
|
||||
commands = with pkgs; [
|
||||
{
|
||||
name = nixpkgs-fmt.pname;
|
||||
package = nixpkgs-fmt;
|
||||
help = nixpkgs-fmt.meta.description;
|
||||
category = "linters";
|
||||
}
|
||||
{
|
||||
name = flk.name;
|
||||
help = "Build, deploy, and install nixflk";
|
||||
category = "main";
|
||||
package = flk;
|
||||
}
|
||||
{
|
||||
name = "hooks";
|
||||
help = "install git hooks";
|
||||
command = "pre-commit install";
|
||||
}
|
||||
{
|
||||
name = "grip";
|
||||
help = python38Packages.grip.meta.description;
|
||||
category = "servers";
|
||||
package = python38Packages.grip;
|
||||
}
|
||||
{
|
||||
name = git.pname;
|
||||
help = git.meta.description;
|
||||
category = "vcs";
|
||||
package = git;
|
||||
}
|
||||
{
|
||||
name = "nix";
|
||||
help = nixFlakes.meta.description;
|
||||
category = "main";
|
||||
command = ''${nixFlakes}/bin/nix --option experimental-features "nix-command flakes ca-references" "$@"'';
|
||||
}
|
||||
];
|
||||
|
||||
}
|
Loading…
Reference in a new issue