-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
242 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
inputs = { | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
nixpkgs.url = "nixpkgs/nixos-unstable"; | ||
drv-parts.url = "nixpkgs"; | ||
}; | ||
|
||
outputs = { | ||
self, | ||
flake-parts, | ||
drv-parts, | ||
... | ||
}: | ||
flake-parts.lib.mkFlake {inherit self;} { | ||
systems = ["x86_64-linux"]; | ||
|
||
# enable the drv-parts plugin for flake-parts | ||
imports = [drv-parts.modules.drv-parts]; | ||
|
||
perSystem = {config, pkgs, system, ...}: { | ||
checks = config.packages; | ||
pkgs.hello = { | ||
|
||
# select mkDerivation as a backend for this package | ||
imports = [drv-parts.modules.derivation]; | ||
|
||
# # set options | ||
name = "test"; | ||
builder = "/bin/sh"; | ||
args = ["-c" "echo $name > $out"]; | ||
system = system; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
inputs = { | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
nixpkgs.url = "nixpkgs/nixos-unstable"; | ||
drv-parts.url = "nixpkgs"; | ||
}; | ||
|
||
outputs = { | ||
self, | ||
flake-parts, | ||
drv-parts, | ||
... | ||
}: | ||
flake-parts.lib.mkFlake {inherit self;} { | ||
systems = ["x86_64-linux"]; | ||
|
||
# enable the drv-parts plugin for flake-parts | ||
imports = [drv-parts.flakeModule]; | ||
|
||
perSystem = {config, lib, pkgs, ...}: { | ||
checks = config.packages; | ||
pkgs.htop = import ./htop.nix; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{config, inputs', lib, pkgs, ...}: let | ||
stdenv = pkgs.stdenv; | ||
in { | ||
|
||
# select mkDerivation as a backend for this package | ||
imports = builtins.trace inputs'.drv-parts [inputs'.drv-parts.modules.mkDerivation]; | ||
|
||
options = { | ||
sensorsSupport = lib.mkOption { | ||
type = lib.types.bool; | ||
default = stdenv.isLinux; | ||
}; | ||
systemdSupport = lib.mkOption { | ||
type = lib.types.bool; | ||
default = stdenv.isLinux; | ||
}; | ||
}; | ||
|
||
config = { | ||
# set options | ||
pname = "htop"; | ||
version = "3.2.1"; | ||
|
||
src = pkgs.fetchFromGitHub { | ||
owner = "htop-dev"; | ||
repo = config.pname; | ||
rev = config.version; | ||
sha256 = "sha256-MwtsvdPHcUdegsYj9NGyded5XJQxXri1IM1j4gef1Xk="; | ||
}; | ||
|
||
nativeBuildInputs = [ pkgs.autoreconfHook ]; | ||
|
||
buildInputs = [ pkgs.ncurses ] | ||
++ lib.optional stdenv.isDarwin pkgs.IOKit | ||
++ lib.optional config.sensorsSupport pkgs.lm_sensors | ||
++ lib.optional config.systemdSupport pkgs.systemd | ||
; | ||
|
||
configureFlags = [ "--enable-unicode" "--sysconfdir=/etc" ] | ||
++ lib.optional config.sensorsSupport "--with-sensors" | ||
; | ||
|
||
postFixup = | ||
let | ||
optionalPatch = pred: so: lib.optionalString pred "patchelf --add-needed ${so} $out/bin/htop"; | ||
in | ||
'' | ||
${optionalPatch config.sensorsSupport "${pkgs.lm_sensors}/lib/libsensors.so"} | ||
${optionalPatch config.systemdSupport "${pkgs.systemd}/lib/libsystemd.so"} | ||
''; | ||
|
||
meta = with lib; { | ||
description = "An interactive process viewer"; | ||
homepage = "https://htop.dev"; | ||
license = licenses.gpl2Only; | ||
platforms = platforms.all; | ||
maintainers = with maintainers; [ rob relrod SuperSandro2000 ]; | ||
changelog = "https://github.com/htop-dev/htop/blob/${version}/ChangeLog"; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
inputs = { | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
nixpkgs.url = "nixpkgs/nixos-unstable"; | ||
drv-parts.url = "nixpkgs"; | ||
}; | ||
|
||
outputs = { | ||
self, | ||
flake-parts, | ||
drv-parts, | ||
... | ||
}: | ||
flake-parts.lib.mkFlake {inherit self;} { | ||
systems = ["x86_64-linux"]; | ||
|
||
# enable the drv-parts plugin for flake-parts | ||
imports = [drv-parts.modules.drv-parts]; | ||
|
||
perSystem = {config, pkgs, ...}: { | ||
checks = config.packages; | ||
pkgs.hello = { | ||
|
||
# select mkDerivation as a backend for this package | ||
imports = [drv-parts.modules.mkDerivation]; | ||
|
||
# set options | ||
name = "hello"; | ||
src = pkgs.fetchurl { | ||
url = "mirror://gnu/hello/hello-2.12.1.tar.gz"; | ||
sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA="; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
description = '' | ||
construct derivations using the nixos-module system | ||
''; | ||
|
||
inputs = { | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
nixpkgs.url = "nixpkgs/nixos-unstable"; | ||
|
@@ -7,21 +11,40 @@ | |
outputs = { | ||
self, | ||
flake-parts, | ||
nixpkgs, | ||
... | ||
}: | ||
flake-parts.lib.mkFlake {inherit self;} { | ||
systems = ["x86_64-linux"]; | ||
imports = [./modules/drv-parts.nix]; | ||
|
||
perSystem = {config, pkgs, ...}: { | ||
pkgs.hello = { | ||
name = "hello"; | ||
src = pkgs.fetchurl { | ||
url = "mirror://gnu/hello/hello-2.12.1.tar.gz"; | ||
sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA="; | ||
}; | ||
passthru.yolo = "lol"; | ||
flake = { | ||
flakeModule = self.nixosModules.drv-parts; | ||
modules = self.nixosModules; | ||
nixosModules = { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
DavHau
Author
Owner
|
||
# import one of these to pick the backend for your derivation | ||
# TODO: add more backends like for ex.: buildPythonPackage, etc. | ||
derivation = ./modules/derivation; | ||
mkDerivation = ./modules/mkDerivation; | ||
|
||
# the main module creatig the `.pkgs.[...]` option for flake-parts | ||
drv-parts = ./modules/drv-parts.nix; | ||
|
||
# the base derivation type used by the drv-parts module | ||
derivation-common = ./modules/derivation-common; | ||
}; | ||
}; | ||
|
||
perSystem = {system, pkgs, ...}: { | ||
packages.tests-examples = pkgs.writeShellScriptBin "tests-examples" '' | ||
set -eu -o pipefail | ||
for example in $(find ./examples); do | ||
echo "testing example $example" | ||
nix flake check "$example" -L \ | ||
--show-trace \ | ||
--no-write-lock-file \ | ||
--override-input drv-parts ${self} | ||
done | ||
''; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,64 @@ | ||
{config, lib, pkgs, ...}: let | ||
l = lib // builtins; | ||
t = l.types; | ||
argsFiltered = l.removeAttrs config [ | ||
|
||
# args that should not be passed to derivatio | ||
argsIgnore = [ | ||
# attrs introduced by module system | ||
"_module" | ||
# this module's custom options | ||
# this module's options which should not end up in the drv | ||
"derivation" | ||
"env" | ||
# attributes that should not be passed if null | ||
"args" | ||
"outputHash" | ||
"drvPath" | ||
"type" | ||
]; | ||
|
||
# attributes that should not be passed if null | ||
argsIgnoreIfNull = [ | ||
"outputHash" | ||
]; | ||
|
||
/* | ||
Filters out args which potentially must be removed because they are null. | ||
Later, the ones which are not null will be added back via `argsMaybeIgnored` | ||
*/ | ||
argsFiltered = l.removeAttrs config (argsIgnore ++ argsIgnoreIfNull); | ||
|
||
# esure that none of the env variables collides with the top-level options | ||
envCollisionError = key: '' | ||
The environment variable declared via env.${key} collides with option ${key}. | ||
Specify the option instead, or rename the environment variable. | ||
''; | ||
envChecked = | ||
l.mapAttrs | ||
(key: val: | ||
if config ? ${key} | ||
then throw (envCollisionError key) | ||
else val) | ||
config.env; | ||
|
||
# generates error message for env variable collision | ||
envCollisionError = key: '' | ||
The environment variable declared via env.${key} collides with option ${key}. | ||
Specify the option instead, or rename the environment variable. | ||
''; | ||
|
||
# returns empty attrset if value == null | ||
omitIfNull = argName: | ||
if config.${argName} == null | ||
then {} | ||
else {${argName} = config.${argName};}; | ||
|
||
# only contains args for which value != null | ||
argsMaybeIgnored = | ||
l.foldl | ||
(all: argName: all // (omitIfNull argName)) | ||
{} | ||
argsIgnoreIfNull; | ||
|
||
# all args that are massed directly to mkDerivation | ||
args = | ||
envChecked | ||
// argsFiltered | ||
// ( | ||
if config.args == null | ||
then {} | ||
else {inherit (config) args;} | ||
) | ||
// ( | ||
if config.outputHash == null | ||
then {} | ||
else {inherit (config) outputHash;} | ||
); | ||
// argsMaybeIgnored | ||
; | ||
|
||
in { | ||
config.derivation = derivation args; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think
nixosModules
items are supposed to be importable into the top level NixOS configuration.These are definitely modules, but
nixos*
, I don't think that's right for them.I like
modules.{package,nixos,flake-parts,nix-darwin}
, but that's unconventional and maybe over-engineering it. It does define convention that's more accomodating for all module system application, that's evenflake check
-able if Nix adopts this as the standard.