Merge pull request #135 from divnix/auto-srcs
pkgs: automatic source management
This commit is contained in:
commit
afedb536cc
@ -12,8 +12,10 @@
|
|||||||
# Introduction
|
# Introduction
|
||||||
DevOS grants a simple way to use, deploy and manage [NixOS][nixos] systems for
|
DevOS grants a simple way to use, deploy and manage [NixOS][nixos] systems for
|
||||||
personal and productive use. It does this by providing a convenient repository
|
personal and productive use. It does this by providing a convenient repository
|
||||||
structure; integrating several popular projects like
|
structure, integrating several popular projects like
|
||||||
[home-manager][home-manager], and [devshell][devshell].
|
[home-manager][home-manager], and [devshell][devshell], and offering useful
|
||||||
|
conveniences like
|
||||||
|
[automatic source updates](./pkgs#automatic-source-updates).
|
||||||
|
|
||||||
Skip the indeterminate nature of other systems, _and_ the perceived difficulty
|
Skip the indeterminate nature of other systems, _and_ the perceived difficulty
|
||||||
of Nix. It's easier than you think!
|
of Nix. It's easier than you think!
|
||||||
|
@ -4,3 +4,13 @@ The `update` subcommand is a simple alias for:
|
|||||||
nix flake update --recreate-lock-file --commit-lock-file
|
nix flake update --recreate-lock-file --commit-lock-file
|
||||||
```
|
```
|
||||||
As it sounds, this will update your lock file, and commit it.
|
As it sounds, this will update your lock file, and commit it.
|
||||||
|
|
||||||
|
## Updating Package Sources
|
||||||
|
If you pass an input name then it will only update that input.
|
||||||
|
|
||||||
|
For example, you can update any
|
||||||
|
[package sources](../../pkgs#automatic-source-updates) you may have declared
|
||||||
|
in _pkgs/flake.nix_:
|
||||||
|
```sh
|
||||||
|
flk update srcs
|
||||||
|
```
|
||||||
|
23
flake.lock
23
flake.lock
@ -74,15 +74,16 @@
|
|||||||
"flake-compat": {
|
"flake-compat": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1606424373,
|
"lastModified": 1611461076,
|
||||||
"narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=",
|
"narHash": "sha256-ad++dTtMNeitUIKi1c66aTrVJOSf+mdZTrGrXzjDr6Q=",
|
||||||
"owner": "edolstra",
|
"owner": "BBBSnowball",
|
||||||
"repo": "flake-compat",
|
"repo": "flake-compat",
|
||||||
"rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf",
|
"rev": "a565cb46bee9fa856a6c15bc9c3bb947fbb784ec",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "edolstra",
|
"owner": "BBBSnowball",
|
||||||
|
"ref": "pr-1",
|
||||||
"repo": "flake-compat",
|
"repo": "flake-compat",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
@ -214,9 +215,21 @@
|
|||||||
"nixos-hardware": "nixos-hardware",
|
"nixos-hardware": "nixos-hardware",
|
||||||
"nur": "nur",
|
"nur": "nur",
|
||||||
"override": "override",
|
"override": "override",
|
||||||
|
"srcs": "srcs",
|
||||||
"utils": "utils"
|
"utils": "utils"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"srcs": {
|
||||||
|
"locked": {
|
||||||
|
"narHash": "sha256-Ot96/oKT5+A5kdqkfYyT45cfEiqhI5UyPdEfEZjbXaA=",
|
||||||
|
"path": "./pkgs",
|
||||||
|
"type": "path"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"path": "./pkgs",
|
||||||
|
"type": "path"
|
||||||
|
}
|
||||||
|
},
|
||||||
"utils": {
|
"utils": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1608663846,
|
"lastModified": 1608663846,
|
||||||
|
@ -21,8 +21,9 @@
|
|||||||
deploy.inputs.flake-compat.follows = "flake-compat";
|
deploy.inputs.flake-compat.follows = "flake-compat";
|
||||||
naersk.url = "github:nmattia/naersk";
|
naersk.url = "github:nmattia/naersk";
|
||||||
naersk.inputs.nixpkgs.follows = "override";
|
naersk.inputs.nixpkgs.follows = "override";
|
||||||
flake-compat.url = "github:edolstra/flake-compat";
|
flake-compat.url = "github:BBBSnowball/flake-compat/pr-1";
|
||||||
flake-compat.flake = false;
|
flake-compat.flake = false;
|
||||||
|
srcs.url = "path:./pkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
|
@ -4,7 +4,7 @@ let
|
|||||||
pathExists filter;
|
pathExists filter;
|
||||||
|
|
||||||
inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
||||||
recursiveUpdate genAttrs nixosSystem mkForce optionalAttrs;
|
recursiveUpdate genAttrs nixosSystem mkForce substring optionalAttrs;
|
||||||
|
|
||||||
# mapFilterAttrs ::
|
# mapFilterAttrs ::
|
||||||
# (name -> value -> bool )
|
# (name -> value -> bool )
|
||||||
@ -93,6 +93,8 @@ in
|
|||||||
|
|
||||||
overlays = pathsToImportedAttrs overlayPaths;
|
overlays = pathsToImportedAttrs overlayPaths;
|
||||||
|
|
||||||
|
mkVersion = src: "${substring 0 8 src.lastModifiedDate}_${src.shortRev}";
|
||||||
|
|
||||||
genPkgs = { self }:
|
genPkgs = { self }:
|
||||||
let inherit (self) inputs;
|
let inherit (self) inputs;
|
||||||
in
|
in
|
||||||
@ -107,6 +109,7 @@ in
|
|||||||
(overridesOverlay overridePkgs)
|
(overridesOverlay overridePkgs)
|
||||||
self.overlay
|
self.overlay
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
|
srcs = self.inputs.srcs.inputs;
|
||||||
lib = (prev.lib or { }) // {
|
lib = (prev.lib or { }) // {
|
||||||
inherit (nixos.lib) nixosSystem;
|
inherit (nixos.lib) nixosSystem;
|
||||||
flk = self.lib;
|
flk = self.lib;
|
||||||
|
@ -14,22 +14,24 @@ the supported systems listed in the package's `meta.platforms` attribute.
|
|||||||
And, as usual, every package in the overlay is also available to any NixOS
|
And, as usual, every package in the overlay is also available to any NixOS
|
||||||
[host](../hosts).
|
[host](../hosts).
|
||||||
|
|
||||||
|
## Automatic Source Updates
|
||||||
|
There is the added, but optional, convenience of declaring your sources in
|
||||||
|
_pkgs/flake.nix_ as an input. This allows updates to be managed automatically
|
||||||
|
by simply [updating](../doc/flk/update.md#updating-package-sources) the lock
|
||||||
|
file. No more manually entering sha256 hashes!
|
||||||
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
pkgs/development/libraries/libinih/default.nix:
|
pkgs/development/libraries/libinih/default.nix:
|
||||||
```nix
|
```nix
|
||||||
{ stdenv, meson, ninja, fetchFromGitHub, ... }:
|
{ stdenv, meson, ninja, lib, srcs, ... }:
|
||||||
let version = "r50";
|
let version = "r53";
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "libinih";
|
pname = "libinih";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = srcs.libinih;
|
||||||
owner = "benhoyt";
|
|
||||||
repo = "inih";
|
|
||||||
rev = "${version}";
|
|
||||||
hash = "sha256-GF+TVEysaXJxSBBjMsTr2IQvRKlzdEu3rlPQ88PE3nI=";
|
|
||||||
};
|
|
||||||
|
|
||||||
buildInputs = [ meson ninja ];
|
buildInputs = [ meson ninja ];
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ stdenv.mkDerivation {
|
|||||||
-Ddistro_install=true
|
-Ddistro_install=true
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with lib; {
|
||||||
description = "Simple .INI file parser in C";
|
description = "Simple .INI file parser in C";
|
||||||
homepage = "https://github.com/benhoyt/inih";
|
homepage = "https://github.com/benhoyt/inih";
|
||||||
maintainers = [ maintainers.divnix ];
|
maintainers = [ maintainers.divnix ];
|
||||||
@ -56,4 +58,16 @@ final: prev: {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
pkgs/flake.nix:
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
description = "Package sources";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
libinih.url = "github:benhoyt/inih/r53";
|
||||||
|
libinih.flake = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
[pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs
|
[pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs
|
||||||
|
7
pkgs/flake.nix
Normal file
7
pkgs/flake.nix
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
description = "Package sources";
|
||||||
|
|
||||||
|
inputs = { };
|
||||||
|
|
||||||
|
outputs = { ... }: { };
|
||||||
|
}
|
14
shell/flk.sh
14
shell/flk.sh
@ -17,12 +17,12 @@ usage () {
|
|||||||
|
|
||||||
printf " %-30s %s\n\n" \
|
printf " %-30s %s\n\n" \
|
||||||
"up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \
|
"up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \
|
||||||
"update" "Update and commit the lock file" \
|
"update [INPUT]" "Update and commit the lock file" \
|
||||||
"get [core|community] DEST" "Copy the desired template to DEST" \
|
"get (core|community) [DEST]" "Copy the desired template to DEST" \
|
||||||
"iso HOST" "Generate an ISO image of HOST" \
|
"iso HOST" "Generate an ISO image of HOST" \
|
||||||
"install HOST [ARGS]" "Shortcut for nixos-install" \
|
"install HOST [ARGS]" "Shortcut for nixos-install" \
|
||||||
"home HOST USER [switch]" "Home-manager config of USER from HOST" \
|
"home HOST USER [switch]" "Home-manager config of USER from HOST" \
|
||||||
"HOST [switch|boot|test]" "Shortcut for nixos-rebuild"
|
"HOST (switch|boot|test)" "Shortcut for nixos-rebuild"
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -49,14 +49,18 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"update")
|
"update")
|
||||||
nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT"
|
if [[ -n "$2" ]]; then
|
||||||
|
nix flake update --update-input "$2" --commit-lock-file "$DEVSHELL_ROOT"
|
||||||
|
else
|
||||||
|
nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"get")
|
"get")
|
||||||
if [[ "$2" == "core" || "$2" == "community" ]]; then
|
if [[ "$2" == "core" || "$2" == "community" ]]; then
|
||||||
nix flake new -t "github:divnix/devos/$2" "${3:-flk}"
|
nix flake new -t "github:divnix/devos/$2" "${3:-flk}"
|
||||||
else
|
else
|
||||||
echo "flk get [core|community] {dest}"
|
echo "flk get (core|community) [DEST]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user